Skip to content

Commit 97e7aad

Browse files
committed
Tikhonov SVD working. Coded two different TikhSVD algos to consider the case where the SVD is precomputed or not. Also fixed the UI of the TikhSVD module to allow for different lambda selection options
1 parent 8c5558f commit 97e7aad

File tree

4 files changed

+68
-17
lines changed

4 files changed

+68
-17
lines changed

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,32 @@ using namespace SCIRun::Core::Algorithms::Inverse;
7070
void SolveInverseProblemWithTikhonovSVD_impl::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_, const SCIRun::Core::Datatypes::DenseMatrix& matrixU_, const SCIRun::Core::Datatypes::DenseMatrix& singularValues_, const SCIRun::Core::Datatypes::DenseMatrix& matrixV_)
7171
{
7272

73-
// if (!matrixU_.size())&&(!matrixV_.size())&&(!singularValues_.size()){
74-
// std::cout << "Precomputed SVD variables found as an input" << std::endl;
75-
//
76-
// svd_MatrixU = *matrixU_;
77-
// svd_MatrixV = *matrixV_;
78-
// svd_SingularValues = *singularValues_;
79-
//
80-
// }else{
73+
// alocate U and V matrices
74+
svd_MatrixU = matrixU_;
75+
svd_MatrixV = matrixV_;
76+
77+
// alocate singular values
78+
if (singularValues_.ncols() == 1 ){
79+
svd_SingularValues = singularValues_;
80+
}
81+
else{
82+
svd_SingularValues = singularValues_.diagonal();
83+
}
84+
85+
// Compute the projection of data y on the left singular vectors
86+
Uy = svd_MatrixU.transpose() * (measuredData_);
87+
88+
// determine rank
89+
rank = svd_SingularValues.nrows();
90+
}
8191

82-
std::cout << "No precomputed SVD... computing now" << std::endl;
92+
void SolveInverseProblemWithTikhonovSVD_impl::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_)
93+
{
8394

8495
// Compute the SVD of the forward matrix
8596
Eigen::JacobiSVD<SCIRun::Core::Datatypes::DenseMatrix::EigenBase> SVDdecomposition( forwardMatrix_, Eigen::ComputeFullU | Eigen::ComputeFullV);
8697

87-
// alocate the left and right singular vectors and the singular values
98+
// alocate the left and right singular vectors and the singular values
8899
svd_MatrixU = SVDdecomposition.matrixU();
89100
svd_MatrixV = SVDdecomposition.matrixV();
90101
svd_SingularValues = SVDdecomposition.singularValues();
@@ -93,11 +104,7 @@ void SolveInverseProblemWithTikhonovSVD_impl::preAlocateInverseMatrices(const SC
93104
rank = SVDdecomposition.nonzeroSingularValues();
94105

95106
// Compute the projection of data y on the left singular vectors
96-
auto tempUy = SVDdecomposition.matrixU().transpose() * (measuredData_);
97-
98-
Uy = tempUy;
99-
100-
// }
107+
Uy = svd_MatrixU.transpose() * (measuredData_);
101108
}
102109

103110
//////////////////////////////////////////////////////////////////////

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ namespace Inverse {
6363
preAlocateInverseMatrices( forwardMatrix_, measuredData_ , sourceWeighting_, sensorWeighting_, matrixU_, singularValues_, matrixV_ );
6464
};
6565

66+
SolveInverseProblemWithTikhonovSVD_impl(const SCIRun::Core::Datatypes::DenseMatrix& forwardMatrix_, const SCIRun::Core::Datatypes::DenseMatrix& measuredData_ , const SCIRun::Core::Datatypes::DenseMatrix& sourceWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& sensorWeighting_)
67+
{
68+
preAlocateInverseMatrices( forwardMatrix_, measuredData_ , sourceWeighting_, sensorWeighting_);
69+
};
70+
6671
private:
6772

6873
// Data Members
@@ -75,6 +80,7 @@ namespace Inverse {
7580

7681
// Methods
7782
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_, const SCIRun::Core::Datatypes::DenseMatrix& matrixU_, const SCIRun::Core::Datatypes::DenseMatrix& singularValues_, const SCIRun::Core::Datatypes::DenseMatrix& matrixV_);
83+
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_);
7884

7985
virtual SCIRun::Core::Datatypes::DenseMatrix computeInverseSolution( double lambda_sq, bool inverseCalculation) const;
8086
// bool checkInputMatrixSizes(); // DEFINED IN PARENT, MIGHT WANT TO OVERRIDE SOME OTHER TIME

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ AlgorithmOutput TikhonovAlgoAbstractBase::run(const AlgorithmInput & input) cons
236236
auto singularValues_ = input.get<Matrix>(TikhonovAlgoAbstractBase::singularValues);
237237
auto matrixV_ = input.get<Matrix>(TikhonovAlgoAbstractBase::matrixV);
238238

239-
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_) );
239+
// If there is a missing matrix from the precomputed SVD input
240+
if ( (matrixU_ == NULL) || (singularValues_ == NULL) || ( matrixV_ == NULL) )
241+
algoImpl = new SolveInverseProblemWithTikhonovSVD_impl( *castMatrix::toDense(forwardMatrix_), *castMatrix::toDense(measuredData_), *castMatrix::toDense(sourceWeighting_), *castMatrix::toDense(sensorWeighting_) );
242+
else
243+
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_) );
244+
240245
}
241246
else if ( TikhonovImplementation_gotten == std::string("TikhonovTSVD") ){
242247
THROW_ALGORITHM_PROCESSING_ERROR("Tikhonov TSVD not implemented yet");

src/Interface/Modules/Inverse/SolveInverseProblemWithTikhonovSVDDialog.ui

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,38 @@
234234
</layout>
235235
</widget>
236236
<resources/>
237-
<connections/>
237+
<connections>
238+
<connection>
239+
<sender>lambdaMethodComboBox_</sender>
240+
<signal>currentIndexChanged(int)</signal>
241+
<receiver>stackedWidget</receiver>
242+
<slot>setCurrentIndex(int)</slot>
243+
<hints>
244+
<hint type="sourcelabel">
245+
<x>182</x>
246+
<y>49</y>
247+
</hint>
248+
<hint type="destinationlabel">
249+
<x>182</x>
250+
<y>196</y>
251+
</hint>
252+
</hints>
253+
</connection>
254+
<connection>
255+
<sender>stackedWidget</sender>
256+
<signal>currentChanged(int)</signal>
257+
<receiver>lambdaMethodComboBox_</receiver>
258+
<slot>setCurrentIndex(int)</slot>
259+
<hints>
260+
<hint type="sourcelabel">
261+
<x>182</x>
262+
<y>196</y>
263+
</hint>
264+
<hint type="destinationlabel">
265+
<x>182</x>
266+
<y>49</y>
267+
</hint>
268+
</hints>
269+
</connection>
270+
</connections>
238271
</ui>

0 commit comments

Comments
 (0)