#include <Mvn.hh>
Public Methods | |
Mvn_ (size_t D=2) | |
Inits to store a D-dimensional MVN centered on the origin, unit covariance matrix (standard MVN). | |
Mvn_ (const Vecdbl_ &Avg, const Smatdbl_ &Cov) | |
Inits to store a MVN distribution with average A and covariance matrix C. More... | |
size_t | dim () const |
dim(): returns the actual dimension. | |
size_t | dim (size_t D) |
dim(D): adjusts the calling object to represent a D-dimensional MVN distribution. More... | |
size_t | covrank () const |
covrank(): returns the rank of the covariance matrix. More... | |
const Vecdbl_& | avg () const |
avg(): returns a const ref. to the average of the distribution. | |
void | avg (const Vecdbl_ &Newavg) |
avg(Newavg): sets the average of the distribution to Newavg. | |
const Smatdbl_& | covar () const |
covar(): returns a const ref. to the covariance of the distribution. | |
int | covar (const Smatdbl_ &Newcov) |
covar(Newcov): sets the covariance of the distribution to Newcov if Newcov has the same dimension as the calling object and if it has at least rank 2. More... | |
double | pdf (const Vecdbl_ &X) const |
pdf(X): calculates the probability density function of the calling object at point X. | |
void | random (Vecdbl_ &X) const |
random(X): generates a dim()-dimensional random vector from the MVN distribution stored in the calling object. More... | |
double | maha_dist (const Vecdbl_ &X) const |
maha_dist(X): calculates and returns the Mahalanobis distance between X and the average vector in the calling object. | |
size_t | marginal (const Bits_ &Bitmask, Mvn_ &Marginal) const |
marginal(Bitmask, Marginal): changes Marginal so that it contains a marginal distribution of the calling object. More... | |
Private Attributes | |
size_t | Dim |
size_t | Covrank |
dimension of random vector, covar mtx rank. | |
Vecdbl_ | Avgvec |
average. | |
Smatdbl_ | Covarmat |
covariance matrix. | |
Vecdbl_ | Eval |
eigenvalues of Covarmat. | |
Rmatdbl_ | Evec |
eigenvectors of Covarmat. | |
Rmatdbl_ | Stdnmap |
lin. comb. coeffs that map N(0,1)-s onto MVN. | |
double | Normfactor |
the density normalisation factor. | |
Static Private Attributes | |
const double | TWO_PI |
Friends | |
istream& | operator>> (istream &In, Mvn_ &Mvn) |
Input from stream In. More... | |
ostream& | operator<< (ostream &Out, const Mvn_ &Mvn) |
Output to stream Out. |
Can be asked to calculate the MVN density and to generate MVN-distributed random vectors. I/O is provided.
Definition at line 44 of file Mvn.hh.
|
Inits to store a D-dimensional MVN centered on the origin, unit covariance matrix (standard MVN).
|
|
Inits to store a MVN distribution with average A and covariance matrix C. These should have the same dimension of course. |
|
dim(): returns the actual dimension.
Definition at line 78 of file Mvn.hh. Referenced by avg(). |
|
dim(D): adjusts the calling object to represent a D-dimensional MVN distribution. If D<2 then it will be set to 2 silently. Does nothing if D is the same as the previous dimension. Do not forget to call avg(Newavg) and covar(Newcov) afterwards! Return value: the old dimension. |
|
covrank(): returns the rank of the covariance matrix. |
|
avg(): returns a const ref. to the average of the distribution.
|
|
avg(Newavg): sets the average of the distribution to Newavg.
|
|
covar(): returns a const ref. to the covariance of the distribution.
|
|
covar(Newcov): sets the covariance of the distribution to Newcov if Newcov has the same dimension as the calling object and if it has at least rank 2. Otherwise nothing is changed. Return value: the rank if OK or 0 on error. |
|
pdf(X): calculates the probability density function of the calling object at point X.
|
|
random(X): generates a dim()-dimensional random vector from the MVN distribution stored in the calling object. The dimension of X is adjusted silently, previous contents are overwritten. |
|
maha_dist(X): calculates and returns the Mahalanobis distance between X and the average vector in the calling object.
Referenced by pdf(). |
|
marginal(Bitmask, Marginal): changes Marginal so that it contains a marginal distribution of the calling object. The variables corresponding to the bits set in Bitmask will be kept, the others will be "integrated out". E.g. if the calling object is a 4-dim MVN with PDF(x1,x2,x3,x4), and the bitmask is "1010", then Marginal will be a 2-dim MVN with PDF(x2,x4). The bitmask should contain exactly as many bits as dim(), otherwise a Dimexc_ exception will be thrown. At least two bits must be set to ON so that Marginal remains a valid Mvn_ object; otherwise a warning is printed and no action will be taken. To get a 1-D marginal distribution, simply obtain the corresponding average coordinate and variance and use a Gaussian_ object. Return value: the dimension of Marginal. |
|
Input from stream In. The ASCII format of an Mvn_ object is:- MVN AVERAGE <dbl vector> (center of distribution) COVARIANCE <dbl lower triangular matrix> (covariance matrix) ENDMVN |
|
Output to stream Out.
|
|
|
|
|
|
dimension of random vector, covar mtx rank.
|
|
average.
|
|
covariance matrix.
|
|
eigenvalues of Covarmat.
|
|
eigenvectors of Covarmat.
|
|
lin. comb. coeffs that map N(0,1)-s onto MVN.
|
|
the density normalisation factor.
|