8 ::SetReferenceModels(
const std::vector <MCMPointer> &refModels,
const std::vector <GradientType> &gradients,
9 const double &smallDelta,
const double &bigDelta,
const std::vector <double> &gradientStrengths)
11 unsigned int numRefModels = refModels.size();
12 m_ReferenceModelSignalValues.resize(numRefModels);
13 unsigned int numSamples = gradients.size();
14 std::vector <double> modelSignalValues(numSamples,0);
16 for (
unsigned int i = 0;i < numRefModels;++i)
18 for (
unsigned int j = 0;j < numSamples;++j)
19 modelSignalValues[j] = refModels[i]->GetPredictedSignal(smallDelta, bigDelta,
20 gradientStrengths[j], gradients[j]);
22 m_ReferenceModelSignalValues[i] = modelSignalValues;
30 ::SetMovingModels(
const std::vector<MCMPointer> &movingModels,
const std::vector <GradientType> &gradients,
31 const double &smallDelta,
const double &bigDelta,
const std::vector <double> &gradientStrengths)
33 unsigned int numMovingModels = movingModels.size();
34 m_MovingModelSignalValues.resize(numMovingModels);
35 unsigned int numSamples = gradients.size();
36 std::vector <double> modelSignalValues(numSamples,0);
38 for (
unsigned int i = 0;i < numMovingModels;++i)
40 for (
unsigned int j = 0;j < numSamples;++j)
41 modelSignalValues[j] = movingModels[i]->GetPredictedSignal(smallDelta, bigDelta,
42 gradientStrengths[j], gradients[j]);
44 m_MovingModelSignalValues[i] = modelSignalValues;
70 m_GradientStrengths = val;
78 m_GradientDirections = val;
86 m_BValueWeightIndexes = val;
94 m_SphereWeights = val;
102 unsigned int numDataPoints = m_ReferenceModelSignalValues.size();
103 if (numDataPoints == 0)
106 double gaussianSigma = parameters[0] * m_ParameterScale;
112 for (
unsigned int j = 0;j < m_GradientDirections.size();++j)
114 double constantAddonValue = 0;
115 for (
unsigned int l = 0;l < numDataPoints;++l)
116 constantAddonValue += m_MovingModelSignalValues[l][j] * m_MovingModelSignalValues[l][j];
118 m_ConstantTerm += m_SphereWeights[m_BValueWeightIndexes[j]] * constantAddonValue;
122 outputValue = m_ConstantTerm;
124 for (
unsigned int j = 0;j < m_GradientDirections.size();++j)
127 double gaussianValue = 0;
128 for (
unsigned int i = 0;i < m_GradientDirections[j].size();++i)
129 gaussianValue += m_GradientDirections[j][i] * m_GradientDirections[j][i];
131 gaussianValue = std::exp (- bValue * gaussianSigma * gaussianValue);
133 double addonValue = 0;
134 for (
unsigned int l = 0;l < numDataPoints;++l)
136 addonValue -= 2.0 * m_MovingModelSignalValues[l][j] * m_ReferenceModelSignalValues[l][j];
137 addonValue += gaussianValue * m_ReferenceModelSignalValues[l][j] * m_ReferenceModelSignalValues[l][j];
140 outputValue += m_SphereWeights[m_BValueWeightIndexes[j]] * gaussianValue * addonValue;
143 if (outputValue <= 0)
146 return outputValue / numDataPoints;
153 unsigned int numDataPoints = m_ReferenceModelSignalValues.size();
154 derivative.set_size(this->GetNumberOfParameters());
157 if (numDataPoints == 0)
160 double gaussianSigma = parameters[0] * m_ParameterScale;
162 for (
unsigned int j = 0;j < m_GradientDirections.size();++j)
165 double addonValue = 0;
166 double gaussianDotProduct = 0;
167 for (
unsigned int i = 0;i < m_GradientDirections[j].size();++i)
168 gaussianDotProduct += m_GradientDirections[j][i] * m_GradientDirections[j][i];
169 gaussianDotProduct *= bValue;
171 double gaussianDerivativeValue = - gaussianDotProduct * std::exp (- gaussianSigma * gaussianDotProduct);
172 double gaussianSqDerivativeValue = - 2.0 * gaussianDotProduct * std::exp (- 2.0 * gaussianSigma * gaussianDotProduct);
174 for (
unsigned int l = 0;l < numDataPoints;++l)
176 double firstTerm = gaussianSqDerivativeValue * m_ReferenceModelSignalValues[l][j] * m_ReferenceModelSignalValues[l][j];
177 double secondTerm = - 2.0 * gaussianDerivativeValue * m_MovingModelSignalValues[l][j] - m_ReferenceModelSignalValues[l][j];
179 addonValue += firstTerm + secondTerm;
182 derivative[0] += m_SphereWeights[m_BValueWeightIndexes[j]] * addonValue;
185 derivative[0] /= numDataPoints;
Superclass::MeasureType MeasureType
void SetSphereWeights(const std::vector< double > &val)
Superclass::ParametersType ParametersType
void SetBigDelta(double val)
virtual MeasureType GetValue(const ParametersType ¶meters) const ITK_OVERRIDE
double GetBValueFromAcquisitionParameters(double smallDelta, double bigDelta, double gradientStrength)
Given gyromagnetic ratio in rad/s/T, gradient strength in T/mm and deltas in s, computes b-value in s...
void SetMovingModels(const std::vector< MCMPointer > &movingModels, const std::vector< GradientType > &gradients, const double &smallDelta, const double &bigDelta, const std::vector< double > &gradientStrengths)
void SetBValueWeightIndexes(const std::vector< unsigned int > &val)
Superclass::DerivativeType DerivativeType
void SetGradientStrengths(const std::vector< double > &val)
void SetGradientDirections(const std::vector< GradientType > &val)
void SetSmallDelta(double val)
virtual void GetDerivative(const ParametersType ¶meters, DerivativeType &derivative) const ITK_OVERRIDE
void SetReferenceModels(const std::vector< MCMPointer > &refModels, const std::vector< GradientType > &gradients, const double &smallDelta, const double &bigDelta, const std::vector< double > &gradientStrengths)