NumericalErrorPropagator.cc
Go to the documentation of this file.
1 #include <utl/NumericalErrorPropagator.h>
2 #include <utl/CovarianceMatrix.h>
3 #include <vector>
4 
5 using namespace std;
8 
9 
10 void
11 NumericalErrorPropagator::operator()(vector<double>& oVec,
12  CovarianceMatrix& oCov,
13  const vector<double>& iVec,
14  const CovarianceMatrix& iCov,
15  const Quality quality)
16  const
17 {
18  const unsigned int nInput = iVec.size();
19 
20  Transform(oVec,iVec);
21 
22  const unsigned int nOutput = oVec.size();
23 
24  double jacobi[nOutput][nInput];
25 
26  vector<double> xp(iVec), xm(iVec);
27  vector<double> fp(nOutput), fm(nOutput);
28 
29  if (quality == eFaster)
30  {
31  for (unsigned inp = 0; inp < nInput; ++inp) {
32 
33  if (inp > 0)
34  {
35  xp [inp-1] = iVec[inp-1];
36  xm [inp-1] = iVec[inp-1];
37  }
38 
39  if (iCov(inp,inp)>0)
40  {
41  const double dx = 0.1*iCov.Std(inp);
42 
43  xp [inp] += dx;
44  xm [inp] -= dx;
45 
46  Transform(fp , xp);
47  Transform(fm , xm);
48 
49  for (unsigned out = 0; out < nOutput; ++out)
50  jacobi[out][inp] = ( fp[out] - fm[out] ) / (2*dx);
51  }
52  else
53  {
54  for (unsigned out = 0; out < nOutput; ++out)
55  jacobi[out][inp] = 0.0;
56  }
57  }
58  }
59  else // quality == eBetter -> use Five-Point-Stencil derivative
60  {
61  vector<double> xpp(iVec), xmm(iVec);
62  vector<double> fpp(nOutput), fmm(nOutput);
63 
64  for (unsigned inp = 0; inp < nInput; ++inp) {
65 
66  if (inp > 0)
67  {
68  xpp[inp-1] = iVec[inp-1];
69  xp [inp-1] = iVec[inp-1];
70  xm [inp-1] = iVec[inp-1];
71  xmm[inp-1] = iVec[inp-1];
72  }
73 
74  if (iCov(inp,inp)>0)
75  {
76  const double dx = 0.1*iCov.Std(inp);
77 
78  xpp[inp] += 2*dx;
79  xp [inp] += dx;
80  xm [inp] -= dx;
81  xmm[inp] -= 2*dx;
82 
83  Transform(fpp,xpp);
84  Transform(fp ,xp );
85  Transform(fm ,xm );
86  Transform(fmm,xmm);
87 
88  for (unsigned out = 0; out < nOutput; ++out)
89  jacobi[out][inp] = ( -fpp[out] + 8*fp[out] - 8*fm[out] + fmm[out] ) / (12*dx);
90  }
91  else
92  {
93  for (unsigned out = 0; out < nOutput; ++out)
94  jacobi[out][inp] = 0.0;
95  }
96  }
97  }
98 
99  oCov.SetExtent(nOutput);
100 
101  for (unsigned int i=0;i<nOutput;++i)
102  for (unsigned int j=0;j<nOutput;++j)
103  {
104  oCov(i,j) = 0.0;
105  for (unsigned int k=0;k<nInput;++k)
106  for (unsigned int l=0;l<nInput;++l)
107  oCov(i,j) += jacobi[i][k] * jacobi[j][l] * iCov(k,l);
108  }
109 }
vector< t2list > out
output of the algorithm: a list of clusters
Definition: XbAlgo.cc:32
void SetExtent(const unsigned int n)

, generated on Tue Sep 26 2023.