6 #include <boost/math/special_functions/erf.hpp> 17 m_TestedParameters[i] = parameters[i];
30 itkExceptionMacro(
"Derivative not handled here. Too much work worth nothing.")
36 unsigned int numT2Signals = m_T2RelaxometrySignals.size();
37 unsigned int numDistributions = m_GaussianMeans.size();
44 m_PredictedSignalAttenuations.set_size(numT2Signals,numDistributions);
53 for (
unsigned int i = 0;i < numDistributions;++i)
59 double minInterestZoneValue = std::max(0.0, m_GaussianMeans[i] - 5.0 * std::sqrt(m_GaussianVariances[i]));
60 double theoreticalMinValue = m_GaussianMeans[i] - i * std::sqrt(m_GaussianVariances[i]);
61 double maxInterestZoneValue = m_GaussianMeans[i] + 5.0 * std::sqrt(m_GaussianVariances[i]);
62 if (theoreticalMinValue < 0.0)
63 maxInterestZoneValue -= theoreticalMinValue;
67 double truncationAbscissa = 2.0 * m_GaussianMeans[i];
68 double truncatedGaussianIntegral = 0.5 * (1.0 + boost::math::erf((truncationAbscissa - m_GaussianMeans[i]) / (std::sqrt(2.0 * m_GaussianVariances[i]))));
70 for (
unsigned int j = 0;j < numT2Signals;++j)
73 m_PredictedSignalAttenuations(j,i) = glQuad.
GetIntegralValue(t2Integrand) / truncatedGaussianIntegral;
77 m_CholeskyMatrix.set_size(numDistributions,numDistributions);
78 m_FSignals.SetSize(numDistributions);
80 for (
unsigned int i = 0;i < numDistributions;++i)
83 for (
unsigned int j = 0;j < numT2Signals;++j)
84 m_FSignals[i] += m_PredictedSignalAttenuations(j,i) * m_T2RelaxometrySignals[j];
86 for (
unsigned int j = i;j < numDistributions;++j)
88 m_CholeskyMatrix(i,j) = 0;
89 for (
unsigned int k = 0;k < numT2Signals;++k)
90 m_CholeskyMatrix(i,j) += m_PredictedSignalAttenuations(k,i) * m_PredictedSignalAttenuations(k,j);
93 m_CholeskyMatrix(j,i) = m_CholeskyMatrix(i,j);
101 bool nnlsNeeded =
false;
103 for (
unsigned int i = 0;i < numDistributions;++i)
105 if (m_OptimalT2Weights[i] <= 0.0)
114 m_NNLSBordersOptimizer->SetDataMatrix(m_CholeskyMatrix);
115 m_NNLSBordersOptimizer->SetPoints(m_FSignals);
116 m_NNLSBordersOptimizer->SetSquaredProblem(
true);
117 m_NNLSBordersOptimizer->StartOptimization();
119 m_OptimalT2Weights = m_NNLSBordersOptimizer->GetCurrentPosition();
122 m_Residuals.set_size(numT2Signals);
128 unsigned int numT2Signals = m_T2RelaxometrySignals.size();
129 unsigned int numDistributions = m_GaussianMeans.size();
133 for (
unsigned int i = 0;i < numT2Signals;++i)
135 m_Residuals[i] = m_T2RelaxometrySignals[i];
136 for (
unsigned int j = 0;j < numDistributions;++j)
137 m_Residuals[i] -= m_PredictedSignalAttenuations(i,j) * m_OptimalT2Weights[j];
139 m_SigmaSquare += m_Residuals[i] * m_Residuals[i];
142 m_SigmaSquare /= numT2Signals;
double GetIntegralValue(FunctionType integrand)
Computes the Gauss Laguerre quadrature of a function defined from R^+ into R. Recenters the function ...
void SolveLinearLeastSquares() const
Computes maximum likelihood estimates of weights.
unsigned int GetNumberOfParameters() const ITK_OVERRIDE
void PerformDecomposition()
Performs LDL decomposition from input matrix.
void SetFlipAngle(double val)
void SetInputMatrix(const MatrixType &matrix)
Set input matrix to decompose.
virtual MeasureType GetValue(const ParametersType ¶meters) const ITK_OVERRIDE
void SetEchoNumber(unsigned int val)
void SetGaussianMean(double val)
virtual void GetDerivative(const ParametersType ¶meters, DerivativeType &derivative) const ITK_OVERRIDE
Superclass::ParametersType ParametersType
void PrepareDataForLLS() const
Superclass::DerivativeType DerivativeType
std::map< double, anima::EPGSignalSimulator::RealVectorType > EPGVectorsMapType
void SetGaussianVariance(double val)
VectorType & SolveLinearSystem(const VectorType &b)
Solves linear system Ax=b and outputs result in new variable.
void SetT1Value(double val)
Superclass::MeasureType MeasureType
void SetEchoSpacing(double val)
void SetExcitationFlipAngle(double val)
Integrand to compute the internal integral per distribution in B1GMMRelaxometryCostFunction.
void SetInterestZone(double minVal, double maxVal)
Specifies region on which the main part of the function is to be seen. If not specified, R^+ is the region.
void SetNumberOfEchoes(unsigned int val)