11 #include <framework/utilities/MultivariateNormalGenerator.h>
12 #include <framework/logging/Logger.h>
24 Eigen::VectorXd emean(n);
25 Eigen::MatrixXd ecov(n, n);
27 for (
int i = 0; i < n; ++i) {
29 for (
int j = 0; j < n; ++j) {
30 ecov(i, j) = cov[i * n + j];
41 if (mean.rows() != cov.rows()) {
42 B2ERROR(
"Mean values and covariance matrix need to be of the same dimension");
45 if (cov.rows() != cov.cols()) {
46 B2ERROR(
"Covariance matrix needs to be a square matrix");
57 auto ldlt = cov.ldlt();
58 if (ldlt.info() != Eigen::Success) {
59 B2ERROR(
"Cannot compute LDLT decomposition of covariance "
60 "matrix, maybe not positive semi-definite?");
63 Eigen::MatrixXd L = ldlt.matrixL();
64 Eigen::MatrixXd D = ldlt.vectorD().asDiagonal();
65 if (D.minCoeff() < 0) {
66 B2ERROR(
"MultivariateNormalGenerator: Negative values when computing LDL^T "
67 "decomposition, cannot compute M=AA^T, resulting random numbers "
68 "will not be correct");
71 auto P = ldlt.transpositionsP().transpose();