25 const double epsilon = 1
E-12;
27 int ncols = cov_matrix.GetNcols();
28 int nrows = cov_matrix.GetNrows();
36 for (
int i = 0; i <
n; ++i) {
40 for (
int k = 0;
k < i; ++
k) {
46 if(fabs(L(i,i)) < epsilon){
49 <<
"Changed element (" << i <<
", " << i <<
") to " << L(i,i);
53 <<
"Decomposed covariance matrix not positive-definite";
55 <<
"L(" << i <<
"," << i <<
") = " << L(i,i);
59 L(i,i) = TMath::Sqrt(L(i,i));
61 for (
int j = i+1; j <
n; ++j) {
63 for (
int k = 0;
k < i; ++
k) {
64 L(i,j) -= L(
k,i)*L(
k,j);
71 TMatrixD LT(TMatrixD::kTransposed,L);
77 const TMatrixD& cholesky_triangular, TVectorD& mean_params)
81 int ncols = cholesky_triangular.GetNcols();
82 int nrows = cholesky_triangular.GetNrows();
83 int npars = mean_params.GetNrows();
87 <<
"Mismatch between number of columns (" << ncols
88 <<
") & rows (" << nrows <<
")";
93 <<
"Mismatch between number of parameters (" << npars
94 <<
") & array size (" << nrows <<
")";
103 for (
int k = 0;
k <
n; ++
k) {
104 g(
k) = RandomGen::Instance()->RndNum().Gaus();
106 g *= cholesky_triangular;
109 TVectorD correlated_params(n);
110 for (
int i = 0; i <
n; ++i) {
111 double v = mean_params[i];
113 correlated_params[i] = v;
116 return correlated_params;
120 const TMatrixD& cholesky_triangular, TVectorD& mean_params, TVectorD& g_uncorrelated)
124 int ncols = cholesky_triangular.GetNcols();
125 int nrows = cholesky_triangular.GetNrows();
126 int npars = mean_params.GetNrows();
127 int nunco = g_uncorrelated.GetNrows();
131 <<
"Mismatch between number of columns (" << ncols
132 <<
") & rows (" << nrows <<
")";
137 <<
"Mismatch between number of parameters (" << npars
138 <<
") & array size (" << nrows <<
")";
143 <<
"Mismatch between size of uncorrelated parameter vector (" << nunco
144 <<
") & array size (" << nrows <<
")";
152 g_uncorrelated *= cholesky_triangular;
155 TVectorD correlated_params(n);
156 for (
int i = 0; i <
n; ++i) {
157 double v = mean_params[i];
158 v += g_uncorrelated(i);
159 correlated_params[i] = v;
162 return correlated_params;
166 const TMatrixD& cholesky_triangular)
168 int ncols = cholesky_triangular.GetNcols();
169 int nrows = cholesky_triangular.GetNrows();
171 assert(ncols==nrows);
178 for (
int k = 0;
k <
n; ++
k) {
179 g(
k) = RandomGen::Instance()->RndNum().Gaus();
181 g *= cholesky_triangular;
187 const TMatrixD& cholesky_triangular, TVectorD & g_uncorrelated)
189 int ncols = cholesky_triangular.GetNcols();
190 int nrows = cholesky_triangular.GetNrows();
191 int npars = g_uncorrelated.GetNrows();
193 assert(ncols==nrows);
194 assert(npars==nrows);
198 TVectorD
g(g_uncorrelated);
199 g *= cholesky_triangular;
211 for(
unsigned int i=1; i<
n; i++) {
227 for(
unsigned int i=1; i<x.
size(); i++) {
238 double err = 0.001*DBL_EPSILON;
239 double dx = TMath::Abs(x1-x2);
249 float err = FLT_EPSILON;
250 float dx = TMath::Abs(x1-x2);
260 return ( x >= range.
min && x <= range.
max );
265 return ( x >= range.
min && x <= range.
max );
270 return ( i >= range.
min && i <= range.
max );
277 return TMath::Max(0., x);
284 return TMath::Max( (
float)0., x);
A simple [min,max] interval for integers.
static constexpr double g
bool AreEqual(double x1, double x2)
A simple [min,max] interval for doubles.
TVectorD CholeskyGenerateCorrelatedParams(const TMatrixD &Lch, TVectorD &mean)
bool IsWithinLimits(double x, Range1D_t range)
A simple [min,max] interval for floats.
TVectorD CholeskyCalculateCorrelatedParamVariations(const TMatrixD &Lch, TVectorD &g_uncorrelated)
TMatrixD CholeskyDecomposition(const TMatrixD &cov)
double KahanSummation(double x[], unsigned int n)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
void err(const char *fmt,...)
TVectorD CholeskyGenerateCorrelatedParamVariations(const TMatrixD &Lch)
double NonNegative(double x)
unsigned nrows(sqlite3 *db, std::string const &tablename)