FLIPACK  3.1
Fast Linear Inversion Package
 All Classes Files Functions Variables Pages
FLIPACK.hpp
Go to the documentation of this file.
1 
11 #ifndef __FLIPACK_hpp__
12 #define __FLIPACK_hpp__
13 
14 #include"BBFMM2D.hpp"
15 #include"environment.hpp"
16 
17 using namespace Eigen;
18 using namespace std;
19 
21 template <typename T>
22 class FLIPACK{
23 public:
25  FLIPACK(MatrixXd& Htranspose, MatrixXd& X, MatrixXd& measurements, MatrixXd& R, H2_2D_Tree*Atree);
27  void get_QHtranspose();
29  void get_HQHtranspose();
31  void get_Psi();
33  void get_Phi();
35  void get_Xi();
37  void get_Beta();
42  void get_Solution();
43  void get_Posterior_Variance();
44 
45  MatrixXd QHtranspose;
46  MatrixXd HQHtranspose;
47  MatrixXd Psi;
48  MatrixXd Phi;
49  MatrixXd Solution;
50  MatrixXd Xi;
51  MatrixXd Beta;
52  MatrixXd vDiag;
53  H2_2D_Tree *Atree;
55 private:
56  MatrixXd Htranspose;
57  MatrixXd X;
58  MatrixXd measurements;
59  MatrixXd R;
61 
62  MatrixXd mainMatrix;
63 
64 
65  bool computedQHtranspose, computedHQHtranspose, computedPsi, computedPhi, computedSolution, computedXi, computedBeta, computedVDiag, computedMainMatrix, computedIntermediateSolution;
66 
68  unsigned long N;
69  unsigned m;
70  unsigned nMeasurementSets;
71  unsigned p;
73  void get_Main_Matrix();
74 
75  void get_Intermediate_Solution();
76 
77  FullPivLU<MatrixXd> lu;
78 
79  MatrixXd intermediateSolution;
80 };
81 
82 
83 
84 template <typename T>
85 FLIPACK<T>::FLIPACK( MatrixXd& Htranspose, MatrixXd& X, MatrixXd& measurements, MatrixXd& R, H2_2D_Tree *Atree){
87  this->Htranspose = Htranspose;
88  this->X = X;
89  this->measurements = measurements;
90  this->R = R;
92  this->Atree = Atree;
93 
94  computedQHtranspose = false;
95  computedHQHtranspose = false;
96  computedPsi = false;
97  computedPhi = false;
98  computedMainMatrix = false;
99  computedIntermediateSolution = false;
100  computedXi = false;
101  computedBeta = false;
102  computedVDiag = false;
103  computedSolution = false;
104 
105  N = Htranspose.rows();
106  m = Htranspose.cols();
107  p = X.cols();
108  nMeasurementSets = measurements.cols();
109 
110  mainMatrix = MatrixXd(m+p,m+p);
111  QHtranspose = MatrixXd(N,m);
112 }
113 
114 
115 template <typename T>
117  if (computedQHtranspose==false) {
118  cout << endl << "Performing FMM to obtain QHtranspose..." << endl;
119  QHtranspose = MatrixXd(N,m);
120  T A;
121  A.calculate_Potential(*Atree,QHtranspose);
122  computedQHtranspose = true;
123  cout << endl << "Obtained QHtranspose" << endl;
124  }
125 }
126 
127 
128 template <typename T>
130  if (computedHQHtranspose==false) {
131  get_QHtranspose();
132  HQHtranspose = Htranspose.transpose()*QHtranspose;
133  computedHQHtranspose = true;
134  cout << "Obtained HQHtranspose" << endl;
135  }
136 }
137 
138 template <typename T>
140  if (computedPsi==false) {
141  get_HQHtranspose();
142  Psi = HQHtranspose + R;
143  computedPsi = true;
144  cout << "Obtained Psi" << endl;
145  }
146 }
147 
148 template <typename T>
150  if (computedPhi==false) {
151  Phi = Htranspose.transpose()*X;
152  computedPhi = true;
153  cout << "Obtained Phi" << endl;
154  }
155 }
156 
157 template <typename T>
159  if (computedMainMatrix==false) {
160  get_Psi();
161  mainMatrix.block(0,0,m,m) = Psi;
162  get_Phi();
163  mainMatrix.block(0,m,m,p) = Phi;
164  mainMatrix.block(m,0,p,m) = Phi.transpose();
165  mainMatrix.block(m,m,p,p) = MatrixXd::Zero(p,p);
166  lu.compute(mainMatrix);
167  computedMainMatrix = true;
168  cout << "Obtained Main matrix" << endl;
169  }
170 }
171 
172 template <typename T>
174  if (computedIntermediateSolution==false) {
175  get_Main_Matrix();
176  MatrixXd rhs = MatrixXd::Zero(m+p,nMeasurementSets);
177  rhs.block(0,0,m,nMeasurementSets) = measurements;
178  intermediateSolution = lu.solve(rhs);
179  computedIntermediateSolution = true;
180  cout << "Obtained Intermediate solution" << endl;
181  }
182 }
183 
184 template <typename T>
186  if (computedXi==false) {
187  get_Intermediate_Solution();
188  Xi = intermediateSolution.block(0,0,m,nMeasurementSets);
189  computedXi = true;
190  cout << "Obtained Xi" << endl;
191  }
192 }
193 
194 template <typename T>
196  if (computedXi==false) {
197  get_Intermediate_Solution();
198  Beta = intermediateSolution.block(m,0,p,nMeasurementSets);
199  computedBeta = true;
200  cout << "Obtained Beta" << endl;
201  }
202 }
203 
204 template <typename T>
206  if (computedSolution==false) {
207  get_QHtranspose();
208  get_Beta();
209  get_Xi();
210  Solution = X*Beta + QHtranspose*Xi;
211  computedSolution = true;
212  cout << "Obtained Solution" << endl;
213  }
214 }
215 
216 
217 
218 #endif //__FLIPACK_hpp__