Skip to content

Commit 06fde43

Browse files
committed
added functionality to allow each inverse method to generate its special sequence of lambdas. If not implemented, the default option is logarithmic increase
1 parent 63c698e commit 06fde43

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

src/Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithTikhonovTSVD_impl.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,19 @@ SCIRun::Core::Datatypes::DenseMatrix SolveInverseProblemWithTikhonovTSVD_impl::c
144144

145145
return solution;
146146
}
147+
148+
//////////////////////////////////////////////////////////////////////
149+
// THIS FUNCTION returns a string of lambdas from which the L-curve is computed
150+
//////////////////////////////////////////////////////////////////////
151+
std::vector<double> SolveInverseProblemWithTikhonovTSVD_impl::computeLambdaArray( double lambdaMin, double lambdaMax, int nLambda ) const
152+
{
153+
std::vector<double> lambdaArray(nLambda,0.0);
154+
const double lam_step = 1;
155+
156+
lambdaArray[0] = lambdaMin;
157+
for (int j = 1; j < nLambda; j++)
158+
{
159+
lambdaArray[j] = lambdaArray[j-1] + lam_step;
160+
}
161+
return lambdaArray;
162+
}

src/Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithTikhonovTSVD_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace Inverse {
8383
void 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_);
8484

8585
virtual SCIRun::Core::Datatypes::DenseMatrix computeInverseSolution( double truncationPoint, bool inverseCalculation) const;
86+
std::vector<double> computeLambdaArray( double lambdaMin, double lambdaMax, int nLambda ) const;
8687
// bool checkInputMatrixSizes(); // DEFINED IN PARENT, MIGHT WANT TO OVERRIDE SOME OTHER TIME
8788

8889

src/Core/Algorithms/Legacy/Inverse/TikhonovAlgoAbstractBase.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,17 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
336336
const int nLambda = get(Parameters::LambdaNum).toInt();
337337
const double lambdaMin_ = get(Parameters::LambdaMin).toDouble();
338338
const double lambdaMax_ = get(Parameters::LambdaMax).toDouble();
339-
const double lam_step = (log10(lambdaMax_) - log10(lambdaMin_)) / (nLambda-1);
340-
std::cout << "Lambda power step: " << lam_step << ". Number: "<< nLambda <<". Lambda min: " << lambdaMin_ << ". Lambda max: "<< lambdaMax_<< ". Ratio: "<< lambdaMax_ / lambdaMin_ << std::endl;
341-
double lambda = 0;
339+
double lambda = 0;
342340

343-
// prealocate vector of lambdas and eta and rho
344-
std::vector<double> lambdaArray(nLambda, 0.0);
341+
// prealocate vector of lambdas and eta and rho
345342
std::vector<double> rho(nLambda, 0.0);
346343
std::vector<double> eta(nLambda, 0.0);
347344

345+
// Compute the lambda array
346+
std::vector<double> lambdaArray(nLambda, 0.0);
347+
lambdaArray = algoImpl->computeLambdaArray( lambdaMin_, lambdaMax_, nLambda );
348+
349+
348350
DenseMatrix CAx, Rx;
349351
DenseMatrix solution;
350352

@@ -353,10 +355,6 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
353355
// for all lambdas
354356
for (int j = 0; j < nLambda; j++)
355357
{
356-
if (j)
357-
{
358-
lambdaArray[j] = lambdaArray[j-1] * pow(10.0,lam_step);
359-
}
360358

361359
// COMPUTE INVERSE SOLUTION
362360
solution = algoImpl->computeInverseSolution( lambdaArray[j], false);
@@ -386,7 +384,7 @@ double TikhonovAlgoAbstractBase::computeLcurve( const SCIRun::Core::Algorithms::
386384
CAx = residualSolution;
387385

388386

389-
// compute rho and eta
387+
// compute rho and eta. Using Frobenious norm when using matrices
390388
rho[j] = CAx.norm();
391389
eta[j] = Rx.norm();
392390

src/Core/Algorithms/Legacy/Inverse/TikhonovImpl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ namespace Inverse {
4848

4949
virtual SCIRun::Core::Datatypes::DenseMatrix computeInverseSolution( double lambda_sq, bool inverseCalculation) const = 0;
5050

51+
// default lambda step. Can ve overriden if necessary (see TSVD as reference)
52+
virtual std::vector<double> computeLambdaArray( double lambdaMin, double lambdaMax, int nLambda ) const {
53+
54+
std::vector<double> lambdaArray(nLambda,0.0);
55+
double lam_step = (log10(lambdaMax) - log10(lambdaMin)) / (nLambda-1);
56+
57+
lambdaArray[0] = lambdaMin;
58+
for (int j = 1; j < nLambda; j++)
59+
{
60+
lambdaArray[j] = lambdaArray[j-1] * pow(10.0,lam_step);
61+
}
62+
63+
return lambdaArray;
64+
};
65+
5166
};
5267

5368
}}}}

src/Modules/Legacy/Inverse/SolveInverseProblemWithTikhonovTSVD.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void SolveInverseProblemWithTikhonovTSVD::execute()
122122
// set parameters
123123
auto state = get_state();
124124

125-
// state->setValue( Parameters::TikhonovImplementation, std::string("TikhonovTSVD") );
125+
state->setValue( Parameters::TikhonovImplementation, std::string("TikhonovTSVD") );
126126
setAlgoStringFromState(Parameters::TikhonovImplementation);
127127
setAlgoOptionFromState(Parameters::RegularizationMethod);
128128
setAlgoDoubleFromState(Parameters::LambdaFromDirectEntry);

0 commit comments

Comments
 (0)