9#include <framework/utilities/MultivariateNormalGenerator.h>
10#include <framework/logging/Logger.h>
22 Eigen::VectorXd emean(n);
23 Eigen::MatrixXd ecov(n, n);
25 for (
int i = 0; i < n; ++i) {
27 for (
int j = 0; j < n; ++j) {
28 ecov(i, j) = cov[i * n + j];
39 if (mean.rows() != cov.rows()) {
40 B2ERROR(
"Mean values and covariance matrix need to be of the same dimension");
43 if (cov.rows() != cov.cols()) {
44 B2ERROR(
"Covariance matrix needs to be a square matrix");
55 auto ldlt = cov.ldlt();
56 if (ldlt.info() != Eigen::Success) {
57 B2ERROR(
"Cannot compute LDLT decomposition of covariance "
58 "matrix, maybe not positive semi-definite?");
61 Eigen::MatrixXd L = ldlt.matrixL();
62 Eigen::MatrixXd D = ldlt.vectorD().asDiagonal();
63 if (D.minCoeff() < 0) {
64 B2ERROR(
"MultivariateNormalGenerator: Negative values when computing LDL^T "
65 "decomposition, cannot compute M=AA^T, resulting random numbers "
66 "will not be correct");
69 auto P = ldlt.transpositionsP().transpose();
Eigen::VectorXd m_mean
Member to store the mean values of the distribution.
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...
void reset()
reset the generator setting the size to 0.
Eigen::MatrixXd m_transform
Member to store the transformation matrix for standard normal distributed random values.
Abstract base class for different kinds of events.