@@ -37,6 +37,7 @@ Last modification : April 20 2017
3737#include < Core/Algorithms/Legacy/Inverse/TikhonovImpl.h>
3838#include < Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithStandardTikhonovImpl.h>
3939#include < Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithTikhonovSVD_impl.h>
40+ #include < Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithTikhonovTSVD_impl.h>
4041
4142// Datatypes
4243#include < Core/Datatypes/Matrix.h>
@@ -90,6 +91,7 @@ ALGORITHM_PARAMETER_DEF( Inverse, LCurveText);
9091ALGORITHM_PARAMETER_DEF ( Inverse, regularizationSolutionSubcase);
9192ALGORITHM_PARAMETER_DEF ( Inverse, regularizationResidualSubcase);
9293
94+
9395TikhonovAlgoAbstractBase::TikhonovAlgoAbstractBase ()
9496{
9597 using namespace Parameters ;
@@ -207,7 +209,7 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
207209
208210 // Alocate Variable
209211 DenseMatrix solution;
210- double lambda_sq = 0 ;
212+ double lambda = 0 ;
211213 double lambda_ = 0 ;
212214
213215 // check input MATRICES
@@ -223,6 +225,9 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
223225 int regularizationResidualSubcase_ = get (Parameters::regularizationResidualSubcase).toInt ();
224226
225227 algoImpl = new SolveInverseProblemWithStandardTikhonovImpl ( *castMatrix::toDense (forwardMatrix_), *castMatrix::toDense (measuredData_), *castMatrix::toDense (sourceWeighting_), *castMatrix::toDense (sensorWeighting_), regularizationChoice_, regularizationSolutionSubcase_, regularizationResidualSubcase_);
228+
229+
230+
226231 }
227232 else if ( TikhonovImplementation_gotten == std::string (" TikhonovSVD" ) ){
228233
@@ -236,21 +241,45 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
236241 auto singularValues_ = input.get <Matrix>(TikhonovAlgoAbstractBase::singularValues);
237242 auto matrixV_ = input.get <Matrix>(TikhonovAlgoAbstractBase::matrixV);
238243
239- // If there is a missing matrix from the precomputed SVD input
244+
245+ // If there is a missing matrix from the precomputed SVD input
240246 if ( (matrixU_ == NULL ) || (singularValues_ == NULL ) || ( matrixV_ == NULL ) )
241247 algoImpl = new SolveInverseProblemWithTikhonovSVD_impl ( *castMatrix::toDense (forwardMatrix_), *castMatrix::toDense (measuredData_), *castMatrix::toDense (sourceWeighting_), *castMatrix::toDense (sensorWeighting_) );
242248 else
243249 algoImpl = new SolveInverseProblemWithTikhonovSVD_impl ( *castMatrix::toDense (forwardMatrix_), *castMatrix::toDense (measuredData_), *castMatrix::toDense (sourceWeighting_), *castMatrix::toDense (sensorWeighting_), *castMatrix::toDense (matrixU_), *castMatrix::toDense (singularValues_), *castMatrix::toDense (matrixV_) );
244250
251+
252+
245253 }
246254 else if ( TikhonovImplementation_gotten == std::string (" TikhonovTSVD" ) ){
247- THROW_ALGORITHM_PROCESSING_ERROR (" Tikhonov TSVD not implemented yet" );
255+
256+ // get Parameters
257+ int regularizationChoice_ = get (Parameters::regularizationChoice).toInt ();
258+ int regularizationSolutionSubcase_ = get (Parameters::regularizationSolutionSubcase).toInt ();
259+ int regularizationResidualSubcase_ = get (Parameters::regularizationResidualSubcase).toInt ();
260+
261+ // get TikhonovSVD special inputs
262+ auto matrixU_ = input.get <Matrix>(TikhonovAlgoAbstractBase::matrixU);
263+ auto singularValues_ = input.get <Matrix>(TikhonovAlgoAbstractBase::singularValues);
264+ auto matrixV_ = input.get <Matrix>(TikhonovAlgoAbstractBase::matrixV);
265+
266+
267+ // If there is a missing matrix from the precomputed SVD input
268+ if ( (matrixU_ == NULL ) || (singularValues_ == NULL ) || ( matrixV_ == NULL ) )
269+ algoImpl = new SolveInverseProblemWithTikhonovTSVD_impl ( *castMatrix::toDense (forwardMatrix_), *castMatrix::toDense (measuredData_), *castMatrix::toDense (sourceWeighting_), *castMatrix::toDense (sensorWeighting_) );
270+ else
271+ algoImpl = new SolveInverseProblemWithTikhonovTSVD_impl ( *castMatrix::toDense (forwardMatrix_), *castMatrix::toDense (measuredData_), *castMatrix::toDense (sourceWeighting_), *castMatrix::toDense (sensorWeighting_), *castMatrix::toDense (matrixU_), *castMatrix::toDense (singularValues_), *castMatrix::toDense (matrixV_) );
272+
273+
274+
248275 }
249276 else {
250277 THROW_ALGORITHM_PROCESSING_ERROR (" Not a valid Tikhonov Implementation selection" );
278+
251279 }
252280
253- // preAlocateInverseMatrices(forwardMatrix_,measuredData_,sourceWeighting_,sensorWeighting_);
281+
282+
254283
255284 // Get Regularization parameter(s) : Lambda
256285 if ((RegularizationMethod_gotten == " single" ) || (RegularizationMethod_gotten == " slider" ))
@@ -276,21 +305,12 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
276305 }
277306
278307 std::cout << " Lambda: " << lambda_ << std::endl;
279- lambda_sq = lambda_ * lambda_;
308+ lambda = lambda_;
280309
281310
282- // compute inverse solution
283- solution = algoImpl->computeInverseSolution (lambda_sq , true );
311+ // compute final inverse solution
312+ solution = algoImpl->computeInverseSolution (lambda , true );
284313
285- //
286- // // set final result
287- // inverseSolution_.reset(new DenseMatrix(solution));
288-
289- // output regularization parameter
290- // DenseColumnMatrix tempLambda(1);
291- // tempLambda[0] = lambda_;
292- //
293- // regularizationParameter_. reset( new DenseColumnMatrix(tempLambda) );
294314
295315
296316 // Set outputs
@@ -321,7 +341,6 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
321341 const double lam_step = (log10 (lambdaMax_) - log10 (lambdaMin_)) / (nLambda-1 );
322342 std::cout << " Lambda power step: " << lam_step << " . Number: " << nLambda <<" . Lambda min: " << lambdaMin_ << " . Lambda max: " << lambdaMax_<< " . Ratio: " << lambdaMax_ / lambdaMin_ << std::endl;
323343 double lambda = 0 ;
324- double lambda_sq;
325344
326345 // prealocate vector of lambdas and eta and rho
327346 std::vector<double > lambdaArray (nLambda, 0.0 );
@@ -341,11 +360,8 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
341360 lambdaArray[j] = lambdaArray[j-1 ] * pow (10.0 ,lam_step);
342361 }
343362
344- // set current lambda
345- lambda_sq = lambdaArray[j] * lambdaArray[j];
346-
347363 // COMPUTE INVERSE SOLUTION
348- solution = algoImpl->computeInverseSolution ( lambda_sq , false );
364+ solution = algoImpl->computeInverseSolution ( lambdaArray[j] , false );
349365
350366
351367 // if using source regularization matrix, apply it to compute Rx (for the eta computations)
@@ -373,23 +389,8 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
373389
374390
375391 // compute rho and eta
376- rho[j]=0 ; eta[j]=0 ;
377- for (int k = 0 ; k < CAx.nrows (); k++)
378- {
379- double T = CAx (k);
380- rho[j] += T*T; // norm of the data fit term
381- }
382-
383- for (int k = 0 ; k < Rx.nrows (); k++)
384- {
385- double T = Rx (k);
386- eta[j] += T*T; // norm of the model term
387- }
388-
389- // eta and rho needed to plot the Lcurve and determine the L corner
390- rho[j] = sqrt (rho[j]);
391- eta[j] = sqrt (eta[j]);
392-
392+ rho[j] = CAx.norm ();
393+ eta[j] = Rx.norm ();
393394
394395 }
395396
0 commit comments