11 unsigned int nbParams = m_LowerBoundsPermutted.size();
12 unsigned int numLines = m_InputWResiduals.size();
14 m_PPermutted.set_size(nbParams);
15 m_PPermuttedShrunk.set_size(m_JRank);
20 m_RAlphaTranspose.set_size(nbParams,nbParams);
21 m_RAlphaTranspose.fill(0.0);
23 if (parameters[0] > 0.0)
26 m_WorkMatrix = m_InputWorkMatrix;
27 for (
unsigned int i = 0;i < nbParams;++i)
28 m_WorkMatrix.put(m_JRank + i,i,std::sqrt(parameters[0]) * m_DValues[m_PivotVector[i]]);
30 for (
unsigned int i = 0;i < numLines;++i)
31 m_WResiduals[i] = m_InputWResiduals[i];
36 for (
unsigned int i = 0;i < nbParams;++i)
38 for (
unsigned int j = i;j < nbParams;++j)
39 m_RAlphaTranspose.put(j,i,m_WorkMatrix.get(i,j));
51 for (
unsigned int i = 0;i < m_JRank;++i)
53 for (
unsigned int j = i;j < m_JRank;++j)
54 m_RAlphaTranspose.put(j,i,m_ZeroWorkMatrix.get(i,j));
57 for (
unsigned int i = 0;i < m_JRank;++i)
58 m_PPermutted[i] = m_PPermuttedShrunk[i];
59 for (
unsigned int i = m_JRank;i < nbParams;++i)
60 m_PPermutted[i] = 0.0;
63 if (!m_SolutionInBounds)
65 for (
unsigned int i = 0;i < nbParams;++i)
67 double value = m_PPermutted[i] + m_PreviousParametersPermutted[i];
68 value = std::min(m_UpperBoundsPermutted[i],std::max(m_LowerBoundsPermutted[i],value));
69 m_PPermutted[i] = value - m_PreviousParametersPermutted[i];
73 m_SolutionVector.set_size(nbParams);
76 for (
unsigned int i = 0;i < nbParams;++i)
78 m_SolutionVector[i] = m_PPermutted[m_InversePivotVector[i]];
79 double phiVal = m_DValues[i] * m_SolutionVector[i];
80 phiNorm += phiVal * phiVal;
83 phiNorm = std::sqrt(phiNorm);
85 return phiNorm - m_DeltaParameter;
90 unsigned int rank = solutionVector.size();
91 for (
unsigned int i = 0;i < rank;++i)
93 double value = m_PreviousParametersPermutted[i] + solutionVector[i];
94 if (value < m_LowerBoundsPermutted[i])
97 if (value > m_UpperBoundsPermutted[i])
109 derivative.set_size(1);
112 unsigned int nbParams = m_LowerBoundsPermutted.size();
116 for (
unsigned int i = 0;i < nbParams;++i)
118 q[i] = m_DValues[i] * m_SolutionVector[i];
119 normQ += q[i] * q[i];
122 normQ = std::sqrt(normQ);
123 for (
unsigned int i = 0;i < nbParams;++i)
124 workQ[i] = m_DValues[m_PivotVector[i]] * q[m_PivotVector[i]] / normQ;
127 if (parameters[0] == 0.0)
130 for (
unsigned int i = 0;i < m_JRank;++i)
131 derivative[0] -= q[i] * q[i];
136 for (
unsigned int i = 0;i < nbParams;++i)
137 derivative[0] -= q[i] * q[i];
140 derivative[0] *= normQ;
147 unsigned int nbParams = qrDerivative.cols();
148 unsigned int numLinesWorkMatrix = rank + nbParams;
150 m_ZeroWorkMatrix.set_size(rank,rank);
151 m_ZeroWorkMatrix.fill(0.0);
152 m_ZeroWResiduals.set_size(rank);
153 m_ZeroWResiduals.fill(0.0);
155 m_InputWorkMatrix.set_size(numLinesWorkMatrix,nbParams);
156 m_InputWorkMatrix.fill(0.0);
157 m_InputWResiduals.set_size(numLinesWorkMatrix);
158 m_InputWResiduals.fill(0.0);
160 m_WorkMatrix.set_size(numLinesWorkMatrix,nbParams);
161 m_WorkMatrix.fill(0.0);
162 m_WResiduals.set_size(numLinesWorkMatrix);
163 m_WResiduals.fill(0.0);
165 for (
unsigned int i = 0;i < rank;++i)
167 for (
unsigned int j = i;j < rank;++j)
169 double tmpVal = qrDerivative.get(i,j);
170 m_ZeroWorkMatrix.put(i,j,tmpVal);
171 m_InputWorkMatrix.put(i,j,tmpVal);
174 for (
unsigned int j = rank;j < nbParams;++j)
175 m_InputWorkMatrix.put(i,j,qrDerivative.get(i,j));
177 m_InputWResiduals[i] = - qtResiduals[i];
178 m_ZeroWResiduals[i] = - qtResiduals[i];
void LowerTriangularSolver(vnl_matrix< ScalarType > &matrix, VectorType &rhs, VectorType &result, unsigned int rank=0)
void SetInputWorkMatricesAndVectorsFromQRDerivative(vnl_matrix< double > &qrDerivative, ParametersType &qtResiduals, unsigned int rank)
virtual void GetDerivative(const ParametersType ¶meters, DerivativeType &derivative) const ITK_OVERRIDE
virtual MeasureType GetValue(const ParametersType ¶meters) const ITK_OVERRIDE
Superclass::MeasureType MeasureType
void QRGivensDecomposition(vnl_matrix< ScalarType > &aMatrix, vnl_vector< ScalarType > &bVector)
Superclass::DerivativeType DerivativeType
void UpperTriangularSolver(const vnl_matrix< ScalarType > &matrix, const VectorType &rhs, VectorType &result, unsigned int rank=0)
Superclass::ParametersType ParametersType
bool CheckSolutionIsInBounds(ParametersType &solutionVector) const