upperTriangularMatrix.cc
Go to the documentation of this file.
1 
11 #include "upperTriangularMatrix.h"
13 
14 using namespace oBLAS;
15 
16 
17 /*****************************************************
18  *
19  * constructor of upperTriangularMatrix
20  *
21  *****************************************************/
23  ublas::triangular_matrix<double, ublas::upper>(i, i)
24 {
25  Init();
26 }
27 
28 
29 /*****************************************************
30  *
31  * copy constructor from ublas::matrix
32  *
33  *****************************************************/
34 upperTriangularMatrix::upperTriangularMatrix(const ublas::matrix<double>& r) :
35  ublas::triangular_matrix<double, ublas::upper>(r)
36 {
37  Init();
38 }
39 
40 
41 /*****************************************************
42  *
43  * initialize
44  *
45  *****************************************************/
46 void
48 {
49  fInverse = NULL;
50 }
51 
52 
53 /*****************************************************
54  *
55  * destructor of upperTriangularMatrix
56  *
57  *****************************************************/
59 {
60  delete fInverse;
61 }
62 
63 
64 /*****************************************************
65  *
66  * assignment to boost matrix
67  *
68  *****************************************************/
69 void
70 upperTriangularMatrix::operator=(const ublas::matrix<double>& r)
71 {
72  const unsigned int size = this->size1();
73  for (unsigned int i = 0; i < size; ++i)
74  for (unsigned int j = 0; j <= i; ++j)
75  (*this)(j, i) = r(j, i);
76 }
77 
78 
79 /************************************************************
80  *
81  * calculate and return inverse using recursive method from
82  * V. Blobel and E. Lohrmann "Statistische und numerische
83  * Methoden der Datenanalyse", Teubner Verlag, 1998
84  *
85  ************************************************************/
88 {
89  const unsigned int size = this->size1();
90  if (fInverse == NULL)
91  fInverse = new upperTriangularMatrix(size);
92 
93  const double epsilon = std::numeric_limits<double>::epsilon();
94 
95  // some abbreviatons ...
96 
97  upperTriangularMatrix& t = *this;
99 
100  // first calculate diagonal elements ...
101  for (unsigned int i = 0; i < size; ++i) {
102  const double tmp = t(i, i);
103  if (fabs(tmp) > epsilon)
104  r(i, i) = 1/tmp;
105  else
106  throw SingularMatrixException();
107  }
108 
109  // ... then off diagonal
110  for (unsigned int i = 1; i < size; ++i) {
111  const double diag = t(i, i);
112  for (unsigned int k = 0; k < i; ++k) {
113  double sum = 0;
114  for (unsigned int j = k; j < i; ++j) {
115  sum += t(j, i) * r(k, j);
116  }
117  r(k, i) = -sum / diag;
118  }
119  }
120  return fInverse;
121 }
void diag(const std::string &msg)
Definition: testlib.cc:59
void operator=(const ublas::matrix< double > &r)
upperTriangularMatrix * fInverse
const upperTriangularMatrix * GetInverse()

, generated on Tue Sep 26 2023.