@@ -57,7 +57,7 @@ using namespace SCIRun::Core::Algorithms::Inverse;
5757
5858// ///////////////////////
5959// /////// compute Inverse solution
60- DenseColumnMatrix SolveInverseProblemWithTikhonovImpl_child::computeInverseSolution ( double lambda_sq, bool inverseCalculation)
60+ DenseMatrix SolveInverseProblemWithTikhonovImpl_child::computeInverseSolution ( double lambda_sq, bool inverseCalculation) const
6161 {
6262 // ............................
6363 // OPERATIONS PERFORMED IN THIS SECTION:
@@ -73,10 +73,11 @@ using namespace SCIRun::Core::Algorithms::Inverse;
7373
7474 const int sizeB = M1.ncols ();
7575 const int sizeSolution = M3.nrows ();
76+ const int numTimeSamples = y.ncols ();
7677 DenseMatrix inverseG (sizeB,sizeB);
7778
7879 DenseColumnMatrix b (sizeB);
79- DenseColumnMatrix solution (sizeSolution);
80+ DenseMatrix solution (sizeSolution,numTimeSamples );
8081 DenseMatrix G;
8182
8283 G = M1 + lambda_sq * M2;
@@ -98,16 +99,23 @@ using namespace SCIRun::Core::Algorithms::Inverse;
9899
99100// ///// precomputeInverseMatrices
100101// /////////////
101- void SolveInverseProblemWithTikhonovImpl_child::preAlocateInverseMatrices (SCIRun::Core::Datatypes::DenseMatrix& forwardMatrix_, SCIRun::Core::Datatypes::DenseMatrix& measuredData_ , SCIRun::Core::Datatypes::DenseMatrix& sourceWeighting_, SCIRun::Core::Datatypes::DenseMatrix& sensorWeighting_)
102+ void SolveInverseProblemWithTikhonovImpl_child::preAlocateInverseMatrices (const SCIRun::Core::Datatypes::DenseMatrix& forwardMatrix_, const SCIRun::Core::Datatypes::DenseMatrix& measuredData_ , const SCIRun::Core::Datatypes::DenseMatrix& sourceWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& sensorWeighting_)
102103 {
103104
104105 // TODO: use DimensionMismatch exception where appropriate
105106 // DIMENSION CHECK!!
106- const int M = forwardMatrix_->nrows ();
107- const int N = forwardMatrix_->ncols ();
107+ const int M = forwardMatrix_.nrows ();
108+ const int N = forwardMatrix_.ncols ();
109+
110+ int x = 0 ;
108111
109112 // PREALOCATE VARIABLES and MATRICES
110- DenseMatrix forward_transpose = forwardMatrix_->transpose ();
113+ DenseMatrix forward_transpose = forwardMatrix_.transpose ();
114+
115+ // get Parameters
116+ auto regularizationChoice_ = get (regularizationChoice).toInt ();
117+ auto regularizationSolutionSubcase_ = get (regularizationSolutionSubcase).toInt ();
118+ auto regularizationResidualSubcase_ = get (regularizationResidualSubcase).toInt ();
111119
112120 // select underdetermined case if user decides so or the option is set to automatic and number of measurements is smaller than number of unknowns.
113121 if ( ( (M < N) && (regularizationChoice_ == automatic) ) || (regularizationChoice_ == underdetermined))
@@ -132,7 +140,7 @@ using namespace SCIRun::Core::Algorithms::Inverse;
132140
133141 // DEFINITIONS AND PREALOCATION OF SOURCE REGULARIZATION MATRIX 'R'
134142 // if R does not exist, set as identity of size equal to N (columns of fwd matrix)
135- if (! sourceWeighting_)
143+ if (true ) // (& sourceWeighting_==NULL )
136144 {
137145 RRtr = DenseMatrix::Identity (N, N);
138146 iRRtr = RRtr;
@@ -143,28 +151,19 @@ using namespace SCIRun::Core::Algorithms::Inverse;
143151 // if provided the non-squared version of R
144152 if ( regularizationSolutionSubcase_==solution_constrained )
145153 {
146- RRtr = sourceWeighting_-> transpose () * * sourceWeighting_;
154+ RRtr = sourceWeighting_. transpose () * sourceWeighting_;
147155 }
148156 // otherwise, if the source regularization is provided as the squared version (RR^T)
149157 else if ( regularizationSolutionSubcase_==solution_constrained_squared )
150158 {
151- RRtr = * sourceWeighting_;
159+ RRtr = sourceWeighting_;
152160 }
153161
154162 // check if squared regularization matrix is invertible
155163 if ( !RRtr.fullPivLu ().isInvertible () )
156164 {
157- const std::string errorMessage (" Regularization matrix in the source space is not invertible." );
158- if (pr_)
159- {
160- pr_->error (errorMessage);
161- }
162- else
163- {
164- std::cerr << errorMessage << std::endl;
165- }
166165
167- THROW_ALGORITHM_INPUT_ERROR_SIMPLE (errorMessage );
166+ THROW_ALGORITHM_INPUT_ERROR_SIMPLE (" Regularization matrix in the source space is not invertible. " );
168167 }
169168
170169 // COMPUTE inverse
@@ -175,7 +174,7 @@ using namespace SCIRun::Core::Algorithms::Inverse;
175174
176175 // DEFINITIONS AND PREALOCATIONS OF MEASUREMENTS COVARIANCE MATRIX 'C'
177176 // if C does not exist, set as identity of size equal to M (rows of fwd matrix)
178- if (! sensorWeighting_)
177+ if (true ) // (& sensorWeighting_==NULL )
179178 {
180179 CCtr = DenseMatrix::Identity (M, M);
181180 iCCtr = CCtr;
@@ -187,30 +186,21 @@ using namespace SCIRun::Core::Algorithms::Inverse;
187186 if (regularizationResidualSubcase_ == residual_constrained)
188187 {
189188 // check that the matrix is of appropriate size (equal number of rows as rows in fwd matrix)
190- if (M != sensorWeighting_-> ncols ())
189+ if (M != sensorWeighting_. ncols ())
191190 {
192- CCtr = sensorWeighting_-> transpose () * * sensorWeighting_;
191+ CCtr = sensorWeighting_. transpose () * sensorWeighting_;
193192 }
194193 }
195194 // otherwise if the source covariance matrix is provided in squared form
196195 else if ( regularizationResidualSubcase_ == residual_constrained_squared )
197196 {
198- CCtr = * sensorWeighting_;
197+ CCtr = sensorWeighting_;
199198 }
200199
201200 // check if squared regularization matrix is invertible
202201 if ( !CCtr.fullPivLu ().isInvertible () )
203202 {
204- const std::string errorMessage (" Residual covariance matrix is not invertible." );
205- if (pr_)
206- {
207- pr_->error (errorMessage);
208- }
209- else
210- {
211- std::cerr << errorMessage << std::endl;
212- }
213- THROW_ALGORITHM_INPUT_ERROR_SIMPLE (errorMessage);
203+ THROW_ALGORITHM_INPUT_ERROR_SIMPLE (" Residual covariance matrix is not invertible." );
214204 }
215205 iCCtr = CCtr.inverse ().eval ();
216206
@@ -220,7 +210,7 @@ using namespace SCIRun::Core::Algorithms::Inverse;
220210
221211 // DEFINE M1 = (A * (R^T*R)^-1 * A^T MATRIX FOR FASTER COMPUTATION
222212 DenseMatrix RAtr = iRRtr * forward_transpose;
223- M1 = * forwardMatrix_ * RAtr;
213+ M1 = forwardMatrix_ * RAtr;
224214
225215 // DEFINE M2 = (C^TC)^-1
226216 M2 = iCCtr;
@@ -232,7 +222,7 @@ using namespace SCIRun::Core::Algorithms::Inverse;
232222 M4 = DenseMatrix::Identity (M, N);
233223
234224 // DEFINE measurement vector
235- y = * measuredData_;
225+ y = measuredData_;
236226
237227
238228
@@ -263,7 +253,7 @@ using namespace SCIRun::Core::Algorithms::Inverse;
263253 // DEFINITIONS AND PREALOCATION OF SOURCE REGULARIZATION MATRIX 'R'
264254
265255 // if R does not exist, set as identity of size equal to N (columns of fwd matrix)
266- if (! sourceWeighting_)
256+ if (true ) // (& sourceWeighting_==NULL )
267257 {
268258 RtrR = DenseMatrix::Identity (N, N);
269259 }
@@ -272,19 +262,19 @@ using namespace SCIRun::Core::Algorithms::Inverse;
272262 // if provided the non-squared version of R
273263 if ( regularizationSolutionSubcase_==solution_constrained )
274264 {
275- RtrR = sourceWeighting_-> transpose () * * sourceWeighting_;
265+ RtrR = sourceWeighting_. transpose () * sourceWeighting_;
276266 }
277267 // otherwise, if the source regularization is provided as the squared version (RR^T)
278268 else if ( regularizationSolutionSubcase_==solution_constrained_squared )
279269 {
280- RtrR = * sourceWeighting_;
270+ RtrR = sourceWeighting_;
281271 }
282272 }
283273
284274
285275 // DEFINITIONS AND PREALOCATIONS OF MEASUREMENTS COVARIANCE MATRIX 'C'
286276 // if C does not exist, set as identity of size equal to M (rows of fwd matrix)
287- if (! sensorWeighting_)
277+ if (true ) // (& sensorWeighting_==NULL )
288278 {
289279 CtrC = DenseMatrix::Identity (M, M);
290280 }
@@ -293,18 +283,18 @@ using namespace SCIRun::Core::Algorithms::Inverse;
293283 // if measurement covariance matrix provided in non-squared form
294284 if (regularizationResidualSubcase_ == residual_constrained)
295285 {
296- CtrC = sensorWeighting_-> transpose () * * sensorWeighting_;
286+ CtrC = sensorWeighting_. transpose () * sensorWeighting_;
297287 }
298288 // otherwise if the source covariance matrix is provided in squared form
299289 else if ( regularizationResidualSubcase_ == residual_constrained_squared )
300290 {
301- CtrC = * sensorWeighting_;
291+ CtrC = sensorWeighting_;
302292 }
303293
304294 }
305295
306296 // DEFINE M1 = (A * (R*R^T)^-1 * A^T MATRIX FOR FASTER COMPUTATION
307- DenseMatrix CtrCA = CtrC * (* forwardMatrix_);
297+ DenseMatrix CtrCA = CtrC * (forwardMatrix_);
308298 M1 = forward_transpose * CtrCA;
309299
310300 // DEFINE M2 = (CC^T)^-1
@@ -317,7 +307,7 @@ using namespace SCIRun::Core::Algorithms::Inverse;
317307 M4 = CtrCA.transpose ();
318308
319309 // DEFINE measurement vector
320- y = CtrCA.transpose () * * measuredData_;
310+ y = CtrCA.transpose () * measuredData_;
321311
322312 }
323313
0 commit comments