4 #include <boost/numeric/ublas/matrix.hpp>
5 #include <boost/numeric/ublas/io.hpp>
7 #include <utl/ErrorLogger.h>
8 #include <utl/AugerException.h>
9 #include <utl/NumericalErrorPropagation.h>
10 #include <utl/CorrelationMatrix.h>
13 using namespace boost::numeric;
20 NumericalErrorPropagation::NumericalErrorPropagation(
const FCNCalculator& fcn,
21 const vector<Parameter>& par,
30 "#parameter: " << par.size() <<
" is different from size of "
61 vector<double> x(J_cols),xm(J_cols),xmm(J_cols),xp(J_cols),xpp(J_cols);
63 for (
unsigned int i = 0; i < J_cols; ++i)
64 x[i] = xm[i] = xmm[i] = xp[i] = xpp[i] =
fParameter[i].value;
68 const unsigned int J_rows =
fResult.size();
70 ublas::matrix<double> J(J_rows, J_cols);
72 for (
unsigned col = 0; col < J_cols; ++col) {
76 xpp[col-1] = x[col-1];
77 xp [col-1] = x[col-1];
78 xm [col-1] = x[col-1];
79 xmm[col-1] = x[col-1];
96 vector<double> fpp =
fFcn(xpp);
97 vector<double> fp =
fFcn(xp);
98 vector<double> fm =
fFcn(xm);
99 vector<double> fmm =
fFcn(xmm);
101 for (
unsigned row = 0; row < J_rows; ++row)
102 J(row, col) = (-fpp[row] + 8*fp[row] - 8*fm[row] + fmm[row]) / (12*dx);
106 for (
unsigned row = 0; row < J_rows; ++row)
117 ublas::matrix<double> V_input(J_cols, J_cols);
119 for (
unsigned row = 0; row < J_cols; ++row)
120 for (
unsigned col = 0; col < J_cols; ++col)
124 const ublas::matrix<double> temp = ublas::prod(V_input, trans(J));
125 ublas::matrix<double> V_output = ublas::prod(J, temp);
133 for (
unsigned i = 0; i < J_rows; ++i) {
134 const double V = V_output(i, i);
136 if (V < 0 || std::isnan(V)) {
138 err <<
"invalid variance " <<
V;
148 for (
unsigned i = 0; i < J_rows; ++i) {
149 for (
unsigned j = i+1; j < J_rows; ++j) {
151 const double tmp = V_output(i, i) * V_output(j, j);
153 const double correlation = tmp > 0 ? V_output(i, j) /
sqrt(tmp) : 0;
155 if (correlation < -1 || correlation > 1 || std::isnan(correlation)) {
157 err <<
"correlation = " << correlation <<
" is invalid, converted to 0 (!)";
const std::vector< Parameter > fParameter
std::vector< double > fPropagatedErrors
unsigned int GetNParameter() const
Exception for reporting variable out of valid range.
void Set(const int iPar, const int jPar, const double corr)
std::vector< double > fResult
double Get(const int iPar, const int jPar) const
const FCNCalculator & fFcn
~NumericalErrorPropagation()
#define ERROR(message)
Macro for logging error messages.
const CorrelationMatrix & fCorrelation
CorrelationMatrix * fPropagatedCorrelation