Belle II Software development
|
Class to generate normal distributed, correlated random numbers given the mean values and the covariance matrix of all dimensions. More...
#include <MultivariateNormalGenerator.h>
Public Member Functions | |
MultivariateNormalGenerator () | |
default constructor to allow later initialization | |
MultivariateNormalGenerator (int n, const double *mean, const double *cov) | |
constructor with array interface: mean and covariance are passed as double arrays where the covariance is expected to be an NxN matrix in row major layout | |
MultivariateNormalGenerator (const Eigen::VectorXd &mean, const Eigen::MatrixXd &cov) | |
constructor with Eigen matrix interface. | |
Eigen::VectorXd | generate () const |
Generate a set of correlated random numbers with the previouly set mean and covariance. | |
void | reset () |
reset the generator setting the size to 0. | |
size_t | size () const |
Return the number of elements to be generated on generate() | |
void | generate (double *output) const |
Generate a set of correlated random numbers with the previouly set mean and covariance and store them in buffer output. | |
ROOT::Math::XYZVector | generateVec3 () const |
Generate a set of correlated random numbers with the previously set mean and covariance and return a ROOT::Math::XYZVector. | |
TVectorD | generateVecT () const |
Generate a set of correlated random numbers with the previouly set mean and covariance and return a TVectorT<double> | |
bool | setMeanCov (int n, const double *mean, const double *cov) |
set the mean and covariance for the distribution with array interface: mean and covariance are passed as double arrays where the covariance is expected to be an NxN matrix in row major layout | |
bool | setMeanCov (const Eigen::VectorXd &mean, const Eigen::MatrixXd &cov) |
set the mean and covariance for the distribution. | |
template<class value_type > | |
bool | setMeanCov (const TVectorT< value_type > &mean, const TMatrixTBase< value_type > &cov) |
set mean and covariance matrix from ROOT vector/matrix objects, e.g. | |
template<class value_type > | |
bool | setMeanCov (const ROOT::Math::XYZVector &mean, const TMatrixTBase< value_type > &cov) |
set the mean and covariance for the distribution. | |
Private Attributes | |
Eigen::VectorXd | m_mean |
Member to store the mean values of the distribution. | |
Eigen::MatrixXd | m_transform |
Member to store the transformation matrix for standard normal distributed random values. | |
Class to generate normal distributed, correlated random numbers given the mean values and the covariance matrix of all dimensions.
This class can be used to generate normal distributed random values according to a given covariance matrix (assuming the covariance matrix is positive semi-definite).
To use it first set the desired mean values and covariance matrix using setMeanCov() and then call generate() to generate one set of values.
To generate normal distributed random values according to a covariance matrix we need to decompose the covariance matrix into . Given the vector of mean values as and a vector of standard normal distributed random values as n we can obtain a set of correlated random values .
Usually the Cholesky decomposition is chosen as it computes . However the Cholesky composition only works for positive definite matrices so it does not work if for example one of the values is fixed and has no error.
To ease this restriction a little we use the LDLT decomposition given as where is a permutation matrix and D a diagonal matrix. We then can use to caluclate the correlated values also for positive semi-definite covariance matrices if the elements of D are positive.
Definition at line 54 of file MultivariateNormalGenerator.h.
|
inline |
default constructor to allow later initialization
Definition at line 57 of file MultivariateNormalGenerator.h.
|
inline |
constructor with array interface: mean and covariance are passed as double arrays where the covariance is expected to be an NxN matrix in row major layout
n | dimensionality |
mean | pointer to the n mean values of the distribution |
cov | pointer to the n*n covariance values in row major layout |
Definition at line 65 of file MultivariateNormalGenerator.h.
|
inline |
constructor with Eigen matrix interface.
mean | Vector of mean values |
cov | Matrix containing the covariance values |
Definition at line 73 of file MultivariateNormalGenerator.h.
|
inline |
Generate a set of correlated random numbers with the previouly set mean and covariance.
Definition at line 81 of file MultivariateNormalGenerator.h.
|
inline |
Generate a set of correlated random numbers with the previouly set mean and covariance and store them in buffer output.
output | pointer to array where generated values will be stored. |
Definition at line 101 of file MultivariateNormalGenerator.h.
|
inline |
Generate a set of correlated random numbers with the previously set mean and covariance and return a ROOT::Math::XYZVector.
Optimally, the set mean and covariance matrix should be of dimension three, otherwise just the first size() elements of the ROOT::Math::XYZVector are set and the remaining elements are zero. If size() is bigger than 3 the remaining values will be discarded.
Definition at line 113 of file MultivariateNormalGenerator.h.
|
inline |
Generate a set of correlated random numbers with the previouly set mean and covariance and return a TVectorT<double>
Definition at line 126 of file MultivariateNormalGenerator.h.
void reset | ( | ) |
reset the generator setting the size to 0.
Subsequent calls to generate will return 0-sized results until the generator is reinitialized using setMeanCov()
Definition at line 14 of file MultivariateNormalGenerator.cc.
bool setMeanCov | ( | const Eigen::VectorXd & | mean, |
const Eigen::MatrixXd & | cov | ||
) |
set the mean and covariance for the distribution.
mean | Vector of mean values |
cov | Matrix containing the covariance values |
Definition at line 36 of file MultivariateNormalGenerator.cc.
bool setMeanCov | ( | int | n, |
const double * | mean, | ||
const double * | cov | ||
) |
set the mean and covariance for the distribution with array interface: mean and covariance are passed as double arrays where the covariance is expected to be an NxN matrix in row major layout
n | dimensionality |
mean | pointer to the n mean values of the distribution |
cov | pointer to the n*n covariance values in row major layout |
Definition at line 20 of file MultivariateNormalGenerator.cc.
|
inline |
Return the number of elements to be generated on generate()
Definition at line 96 of file MultivariateNormalGenerator.h.
|
private |
Member to store the mean values of the distribution.
Definition at line 171 of file MultivariateNormalGenerator.h.
|
private |
Member to store the transformation matrix for standard normal distributed random values.
Definition at line 174 of file MultivariateNormalGenerator.h.