@@ -67,21 +67,37 @@ using namespace SCIRun::Core::Algorithms::Inverse;
6767// ///// prealocate Matrices for inverse compuation
6868// / This function precalcualtes the SVD of the forward matrix and prepares singular vectors and values for posterior computations
6969// /////////////////////////////////////////////////////////////////
70- 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_)
70+ 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- // Compute the SVD of the forward matrix
74- Eigen::JacobiSVD<SCIRun::Core::Datatypes::DenseMatrix::EigenBase> svd ( forwardMatrix_, Eigen::ComputeFullU | Eigen::ComputeFullV);
75- SVDdecomposition = svd;
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{
7681
77- // determine rank
78- rank = SVDdecomposition.nonzeroSingularValues ();
82+ std::cout << " No precomputed SVD... computing now" << std::endl;
7983
80- // Compute the projection of data y on the left singular vectors
81- auto tempUy = SVDdecomposition. matrixU (). transpose () * (measuredData_ );
84+ // Compute the SVD of the forward matrix
85+ Eigen::JacobiSVD<SCIRun::Core::Datatypes::DenseMatrix::EigenBase> SVDdecomposition ( forwardMatrix_, Eigen::ComputeFullU | Eigen::ComputeFullV );
8286
83- Uy = tempUy;
87+ // alocate the left and right singular vectors and the singular values
88+ svd_MatrixU = SVDdecomposition.matrixU ();
89+ svd_MatrixV = SVDdecomposition.matrixV ();
90+ svd_SingularValues = SVDdecomposition.singularValues ();
8491
92+ // determine rank
93+ rank = SVDdecomposition.nonzeroSingularValues ();
94+
95+ // Compute the projection of data y on the left singular vectors
96+ auto tempUy = SVDdecomposition.matrixU ().transpose () * (measuredData_);
97+
98+ Uy = tempUy;
99+
100+ // }
85101}
86102
87103// ////////////////////////////////////////////////////////////////////
@@ -91,8 +107,8 @@ SCIRun::Core::Datatypes::DenseMatrix SolveInverseProblemWithTikhonovSVD_impl::co
91107{
92108
93109 // prealocate matrices
94- const int N = SVDdecomposition. matrixV () .cols ();
95- const int M = SVDdecomposition. matrixU () .rows ();
110+ const int N = svd_MatrixV .cols ();
111+ const int M = svd_MatrixU .rows ();
96112 const int numTimeSamples = Uy.ncols ();
97113 DenseMatrix solution (DenseMatrix::Zero (N,numTimeSamples));
98114 DenseMatrix tempInverse (DenseMatrix::Zero (N,M));
@@ -101,15 +117,15 @@ SCIRun::Core::Datatypes::DenseMatrix SolveInverseProblemWithTikhonovSVD_impl::co
101117 for (int rr=0 ; rr<rank ; rr++)
102118 {
103119 // evaluate filter factor
104- double singVal = SVDdecomposition. singularValues () [rr];
120+ double singVal = svd_SingularValues [rr];
105121 double filterFactor_i = singVal / ( lambda_sq + singVal * singVal ) * Uy (rr);
106-
122+
107123 // u[date solution
108- solution += filterFactor_i * SVDdecomposition. matrixV () .col (rr);
124+ solution += filterFactor_i * svd_MatrixV .col (rr);
109125
110126 // update inverse operator
111127 if (inverseCalculation)
112- tempInverse += filterFactor_i * ( SVDdecomposition. matrixV (). col (rr) * SVDdecomposition. matrixU () .col (rr).transpose () );
128+ tempInverse += filterFactor_i * ( svd_MatrixV. col (rr) * svd_MatrixU .col (rr).transpose () );
113129 }
114130
115131 // output solutions
0 commit comments