@@ -36,7 +36,7 @@ Last modification : April 20 2017
3636#include < Core/Algorithms/Legacy/Inverse/TikhonovAlgoAbstractBase.h>
3737#include < Core/Algorithms/Legacy/Inverse/TikhonovImpl.h>
3838#include < Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithStandardTikhonovImpl.h>
39- // #include <Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithTikhonovSVD_impl.h>
39+ #include < Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithTikhonovSVD_impl.h>
4040
4141// Datatypes
4242#include < Core/Datatypes/Matrix.h>
@@ -87,14 +87,13 @@ TikhonovAlgoAbstractBase::TikhonovAlgoAbstractBase()
8787{
8888 using namespace Parameters ;
8989
90- addParameter (TikhonovImplementation, " NoMethodSelected" );
91- addOption (RegularizationMethod, " lcurve" , " single|slider|lcurve" );
92- addParameter (regularizationChoice, 0 );
93- addParameter (LambdaFromDirectEntry,1e-6 );
94- // addParameter(lambdaDoubleSpinBox,1e-6);
90+ addParameter (Parameters::TikhonovImplementation, std::string (" NoMethodSelected" ) );
91+ addOption (Parameters::RegularizationMethod, " lcurve" , " single|slider|lcurve" );
92+ addParameter (Parameters::regularizationChoice, 0 );
93+ addParameter (Parameters::LambdaFromDirectEntry,1e-6 );
9594 addParameter (Parameters::LambdaMin,1e-6 );
9695 addParameter (Parameters::LambdaMax,1 );
97- addParameter (Parameters::LambdaNum,1000 );
96+ addParameter (Parameters::LambdaNum,200 );
9897 addParameter (Parameters::LambdaResolution,1e-6 );
9998 addParameter (Parameters::LambdaSliderValue,0 );
10099 addParameter (Parameters::LambdaCorner,0 );
@@ -209,19 +208,25 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
209208
210209 // Determine specific Tikhonov Implementation
211210 TikhonovImpl *algoImpl;
212- std::cout << " Selecting Tikhonov: " << TikhonovImplementation_gotten << std::endl;
213- if ( TikhonovImplementation_gotten == " standardTikhonov " ){
211+ if ( TikhonovImplementation_gotten == std::string ( " standardTikhonov " ) ){
212+
214213 // get Parameters
215214 int regularizationChoice_ = get (Parameters::regularizationChoice).toInt ();
216215 int regularizationSolutionSubcase_ = get (Parameters::regularizationSolutionSubcase).toInt ();
217216 int regularizationResidualSubcase_ = get (Parameters::regularizationResidualSubcase).toInt ();
218217
219218 algoImpl = new SolveInverseProblemWithStandardTikhonovImpl ( *castMatrix::toDense (forwardMatrix_), *castMatrix::toDense (measuredData_), *castMatrix::toDense (sourceWeighting_), *castMatrix::toDense (sensorWeighting_), regularizationChoice_, regularizationSolutionSubcase_, regularizationResidualSubcase_);
220219 }
221- else if ( TikhonovImplementation_gotten == " TikhonovSVD" ){
222- // algoImpl = new SolveInverseProblemWithTikhonovSVD_impl( *castMatrix::toDense(forwardMatrix_), *castMatrix::toDense(measuredData_), *castMatrix::toDense(sourceWeighting_), *castMatrix::toDense(sensorWeighting_));
220+ else if ( TikhonovImplementation_gotten == std::string (" TikhonovSVD" ) ){
221+
222+ // get Parameters
223+ int regularizationChoice_ = get (Parameters::regularizationChoice).toInt ();
224+ int regularizationSolutionSubcase_ = get (Parameters::regularizationSolutionSubcase).toInt ();
225+ int regularizationResidualSubcase_ = get (Parameters::regularizationResidualSubcase).toInt ();
226+
227+ algoImpl = new SolveInverseProblemWithTikhonovSVD_impl (*castMatrix::toDense (forwardMatrix_), *castMatrix::toDense (measuredData_), *castMatrix::toDense (sourceWeighting_), *castMatrix::toDense (sensorWeighting_));
223228 }
224- else if ( TikhonovImplementation_gotten== " TikhonovTSVD" ){
229+ else if ( TikhonovImplementation_gotten == std::string ( " TikhonovTSVD" ) ){
225230 THROW_ALGORITHM_PROCESSING_ERROR (" Tikhonov TSVD not implemented yet" );
226231 }
227232 else {
@@ -247,6 +252,7 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
247252 else if (RegularizationMethod_gotten == " lcurve" )
248253 {
249254 lambda_ = computeLcurve ( algoImpl, input );
255+ std::cout << " Lambda: " << lambda_ << std::endl;
250256 }
251257 else
252258 {
@@ -287,21 +293,18 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
287293// ///// compute L-curve
288294double TikhonovAlgoAbstractBase::computeLcurve ( const SCIRun::Core::Algorithms::Inverse::TikhonovImpl * algoImpl, const AlgorithmInput & input ) const
289295{
290-
291296 // get inputs
292297 auto forwardMatrix_ = input.get <Matrix>(TikhonovAlgoAbstractBase::ForwardMatrix);
293298 auto measuredData_ = input.get <Matrix>(TikhonovAlgoAbstractBase::MeasuredPotentials);
294299 auto sourceWeighting_ = input.get <Matrix>(TikhonovAlgoAbstractBase::WeightingInSourceSpace);
295300 auto sensorWeighting_ = input.get <Matrix>(TikhonovAlgoAbstractBase::WeightingInSensorSpace);
296-
297301 // define the step size of the lambda vector to be computed (distance between min and max divided by number of desired lambdas in log scale)
298302 const int nLambda = get (Parameters::LambdaNum).toInt ();
299- const int lambdaMin_ = get (Parameters::LambdaMin).toDouble ();
300- const int lambdaMax_ = get (Parameters::LambdaMax).toDouble ();
301- const double lam_step = pow (10.0 , lambdaMax_ / lambdaMin_) / (nLambda-1 );
303+ const double lambdaMin_ = get (Parameters::LambdaMin).toDouble ();
304+ const double lambdaMax_ = get (Parameters::LambdaMax).toDouble ();
305+ const double lam_step = (log10 (lambdaMax_) - log10 (lambdaMin_)) / (nLambda-1 );
306+ std::cout << " Lambda power step: " << lam_step << " . Number: " << nLambda <<" . Lambda min: " << lambdaMin_ << " . Lambda max: " << lambdaMax_<< " . Ratio: " << lambdaMax_ / lambdaMin_ << std::endl;
302307 double lambda = 0 ;
303-
304- const int sizeSolution = forwardMatrix_->ncols ();
305308 double lambda_sq;
306309
307310 // prealocate vector of lambdas and eta and rho
@@ -314,15 +317,12 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
314317
315318 lambdaArray[0 ] = lambdaMin_;
316319
317- // initialize counter
318- int lambda_index = 0 ;
319-
320320 // for all lambdas
321321 for (int j = 0 ; j < nLambda; j++)
322322 {
323323 if (j)
324324 {
325- lambdaArray[j] = lambdaArray[j-1 ] * lam_step;
325+ lambdaArray[j] = lambdaArray[j-1 ] * pow ( 10.0 , lam_step) ;
326326 }
327327
328328 // set current lambda
@@ -377,13 +377,9 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
377377
378378 }
379379
380- // // update L-curve
381- // boost::shared_ptr<TikhonovAlgorithm::LCurveInput> lcurveInput(new TikhonovAlgorithm::LCurveInput(rho, eta, lambdaArray, nLambda));
382- // lcurveInput_handle_ = lcurveInput;
383- //
384- // // Find corner in L-curve
385- // lambda = FindCorner(*lcurveInput_handle_, lambda_index);
386- //
380+ // Find corner in L-curve
381+ lambda = FindCorner ( rho, eta, lambdaArray, nLambda );
382+
387383 // // update GUI
388384 // if (updateLCurveGui_)
389385 // updateLCurveGui_(lambda, *lcurveInput_handle_, lambda_index);
@@ -397,13 +393,9 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
397393
398394
399395// /// Find Corner, find the maximal curvature which corresponds to the L-curve corner
400- double TikhonovAlgoAbstractBase::FindCorner ( LCurveInput & Linput , const AlgorithmInput & input, int & lambda_index )
396+ double TikhonovAlgoAbstractBase::FindCorner ( const std::vector< double >& rho , const std::vector< double >& eta, const std::vector< double >& lambdaArray, const int nLambda )
401397{
402- const int nLambda = Linput.nLambda_ ;
403- const std::vector<double >& rho = Linput.rho_ ;
404- const std::vector<double >& eta = Linput.eta_ ;
405- const std::vector<double >& lambdaArray = Linput.lambdaArray_ ;
406-
398+ int lambda_index;
407399 std::vector<double > deta (nLambda);
408400 std::vector<double > ddeta (nLambda);
409401 std::vector<double > drho (nLambda);
@@ -450,38 +442,38 @@ double TikhonovAlgoAbstractBase::FindCorner( LCurveInput & Linput, const Algorit
450442 return lambdaArray[lambda_index];
451443}
452444
453- // /// Search for closest Lambda to given lambda
454- double TikhonovAlgoAbstractBase::LambdaLookup ( LCurveInput& Linput, double lambda, int & lambda_index, const double epsilon)
455- {
456- const int nLambda = Linput.nLambda_ ;
457- const std::vector<double >& lambdaArray = Linput.lambdaArray_ ;
458-
459- for (int i = 0 ; i < nLambda-1 ; ++i)
460- {
461- if (i > 0 && (lambda < lambdaArray[i-1 ] || lambda > lambdaArray[i+1 ])) continue ;
462-
463- double lambda_step_midpoint = std::abs (lambdaArray[i+1 ] - lambdaArray[i])/2 ;
464-
465- if (std::abs (lambda - lambdaArray[i]) <= epsilon) // TODO: is this a reasonable comparison???
466- {
467- lambda_index = i;
468- return lambdaArray[lambda_index];
469- }
470-
471- if (std::abs (lambda - lambdaArray[i]) < lambda_step_midpoint)
472- {
473- lambda_index = i;
474- return lambdaArray[lambda_index];
475- }
476-
477- if (std::abs (lambda - lambdaArray[i+1 ]) < lambda_step_midpoint)
478- {
479- lambda_index = i+1 ;
480- return lambdaArray[lambda_index];
481- }
482- }
483- return -1 ;
484- }
445+ // // /// Search for closest Lambda to given lambda
446+ // double TikhonovAlgoAbstractBase::LambdaLookup( LCurveInput& Linput, double lambda, int& lambda_index, const double epsilon)
447+ // {
448+ // const int nLambda = Linput.nLambda_;
449+ // const std::vector<double>& lambdaArray = Linput.lambdaArray_;
450+ //
451+ // for (int i = 0; i < nLambda-1; ++i)
452+ // {
453+ // if (i > 0 && (lambda < lambdaArray[i-1] || lambda > lambdaArray[i+1])) continue;
454+ //
455+ // double lambda_step_midpoint = std::abs(lambdaArray[i+1] - lambdaArray[i])/2;
456+ //
457+ // if (std::abs(lambda - lambdaArray[i]) <= epsilon) // TODO: is this a reasonable comparison???
458+ // {
459+ // lambda_index = i;
460+ // return lambdaArray[lambda_index];
461+ // }
462+ //
463+ // if (std::abs(lambda - lambdaArray[i]) < lambda_step_midpoint)
464+ // {
465+ // lambda_index = i;
466+ // return lambdaArray[lambda_index];
467+ // }
468+ //
469+ // if (std::abs(lambda - lambdaArray[i+1]) < lambda_step_midpoint)
470+ // {
471+ // lambda_index = i+1;
472+ // return lambdaArray[lambda_index];
473+ // }
474+ // }
475+ // return -1;
476+ // }
485477
486478// ////////// update L-curve graph
487479// void TikhonovAlgoAbstractBase::update_graph( LCurveInput & input, double lambda, int lambda_index, const double epsilon)
0 commit comments