11 #ifndef __FLIPACK_hpp__
12 #define __FLIPACK_hpp__
17 using namespace Eigen;
25 FLIPACK(MatrixXd& Htranspose, MatrixXd& X, MatrixXd& measurements, MatrixXd& R, H2_2D_Tree*Atree);
27 void get_QHtranspose();
29 void get_HQHtranspose();
43 void get_Posterior_Variance();
58 MatrixXd measurements;
65 bool computedQHtranspose, computedHQHtranspose, computedPsi, computedPhi, computedSolution, computedXi, computedBeta, computedVDiag, computedMainMatrix, computedIntermediateSolution;
73 void get_Main_Matrix();
75 void get_Intermediate_Solution();
77 FullPivLU<MatrixXd> lu;
79 MatrixXd intermediateSolution;
85 FLIPACK<T>::FLIPACK( MatrixXd& Htranspose, MatrixXd& X, MatrixXd& measurements, MatrixXd& R, H2_2D_Tree *Atree){
87 this->Htranspose = Htranspose;
89 this->measurements = measurements;
94 computedQHtranspose =
false;
95 computedHQHtranspose =
false;
98 computedMainMatrix =
false;
99 computedIntermediateSolution =
false;
101 computedBeta =
false;
102 computedVDiag =
false;
103 computedSolution =
false;
105 N = Htranspose.rows();
106 m = Htranspose.cols();
108 nMeasurementSets = measurements.cols();
110 mainMatrix = MatrixXd(m+p,m+p);
111 QHtranspose = MatrixXd(N,m);
115 template <
typename T>
117 if (computedQHtranspose==
false) {
118 cout << endl <<
"Performing FMM to obtain QHtranspose..." << endl;
119 QHtranspose = MatrixXd(N,m);
121 A.calculate_Potential(*Atree,QHtranspose);
122 computedQHtranspose =
true;
123 cout << endl <<
"Obtained QHtranspose" << endl;
128 template <
typename T>
130 if (computedHQHtranspose==
false) {
132 HQHtranspose = Htranspose.transpose()*QHtranspose;
133 computedHQHtranspose =
true;
134 cout <<
"Obtained HQHtranspose" << endl;
138 template <
typename T>
140 if (computedPsi==
false) {
142 Psi = HQHtranspose + R;
144 cout <<
"Obtained Psi" << endl;
148 template <
typename T>
150 if (computedPhi==
false) {
151 Phi = Htranspose.transpose()*X;
153 cout <<
"Obtained Phi" << endl;
157 template <
typename T>
159 if (computedMainMatrix==
false) {
161 mainMatrix.block(0,0,m,m) = Psi;
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;
172 template <
typename T>
174 if (computedIntermediateSolution==
false) {
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;
184 template <
typename T>
186 if (computedXi==
false) {
187 get_Intermediate_Solution();
188 Xi = intermediateSolution.block(0,0,m,nMeasurementSets);
190 cout <<
"Obtained Xi" << endl;
194 template <
typename T>
196 if (computedXi==
false) {
197 get_Intermediate_Solution();
198 Beta = intermediateSolution.block(m,0,p,nMeasurementSets);
200 cout <<
"Obtained Beta" << endl;
204 template <
typename T>
206 if (computedSolution==
false) {
210 Solution = X*Beta + QHtranspose*Xi;
211 computedSolution =
true;
212 cout <<
"Obtained Solution" << endl;
218 #endif //__FLIPACK_hpp__