CovarianceMatrix.h
Go to the documentation of this file.
1 #ifndef _utl_CovarianceMatrix_h_
2 #define _utl_CovarianceMatrix_h_
3 
4 #include <vector>
5 #include <cmath>
6 
7 
8 namespace utl {
9 
11  public:
12  CovarianceMatrix(const unsigned int n = 1)
13  {
14  SetExtent(n);
15  }
16 
17  void
18  SetExtent(const unsigned int n)
19  {
20  fExtent = n;
21  fData.resize(n*(n+1)/2);
22  }
23 
24  unsigned int
25  GetExtent()
26  const
27  {
28  return fExtent;
29  }
30 
31  double&
32  operator()(const unsigned int i, const unsigned int j)
33  {
34  return fData[Internal(i, j)];
35  }
36 
37  const double&
38  operator()(const unsigned int i, const unsigned int j)
39  const
40  {
41  return fData[Internal(i, j)];
42  }
43 
44  double&
45  operator[](const unsigned int i)
46  {
47  return fData[Internal(i, i)];
48  }
49 
50  const double&
51  operator[](const unsigned int i)
52  const
53  {
54  return fData[Internal(i, i)];
55  }
56 
58  double
59  Std(const unsigned int i)
60  const
61  {
62  return std::sqrt(fData[Internal(i, i)]);
63  }
64 
67  operator=(const double x)
68  {
69  for (unsigned int i = 0; i < fExtent; ++i)
70  for (unsigned int j = i; j < fExtent; ++j)
71  fData[Internal(i, j)] = (i == j) ? x : 0;
72  return *this;
73  }
74 
75  protected:
76  unsigned int
77  Internal(unsigned int i, unsigned int j)
78  const
79  {
80  if (i > j)
81  std::swap(i, j);
82  return j + i*fExtent - i*(i+1)/2;
83  }
84 
85  unsigned int fExtent;
86  std::vector<double> fData;
87  };
88 
89 } // NS utl
90 
91 
92 #endif
void swap(utl::Trace< T > &t1, utl::Trace< T > &t2)
Definition: Trace.h:363
CovarianceMatrix(const unsigned int n=1)
double & operator()(const unsigned int i, const unsigned int j)
return j i *fExtent i * i
std::vector< double > fData
const double & operator()(const unsigned int i, const unsigned int j) const
const double & operator[](const unsigned int i) const
void SetExtent(const unsigned int n)
double & operator[](const unsigned int i)
CovarianceMatrix & operator=(const double x)
filling matrix with x in diagonal and zero everywhere else

, generated on Tue Sep 26 2023.