11 m_MatrixSize = val.rows();
16 m_LMatrix.set_size(m_MatrixSize, m_MatrixSize);
17 m_LMatrix.set_identity();
18 m_DMatrix.set_size(m_MatrixSize);
20 for (
unsigned int i = 0;i < m_MatrixSize;++i)
22 m_DMatrix[i] = m_InputMatrix.get(i,i);
23 for (
unsigned int j = 0;j < i;++j)
25 double tmpVal = m_LMatrix.get(i,j);
26 m_DMatrix[i] -= tmpVal * tmpVal * m_DMatrix[j];
29 for (
unsigned int j = i + 1;j < m_MatrixSize;++j)
32 for (
unsigned int k = 0;k < i;++k)
33 diffVal += m_LMatrix.get(j,k) * m_LMatrix.get(i,k) * m_DMatrix[k];
35 double lVal = (m_InputMatrix.get(j,i) - diffVal) / m_DMatrix[i];
36 m_LMatrix.put(j,i,lVal);
43 double minVal = m_DMatrix[0];
44 double maxVal = m_DMatrix[0];
46 for (
unsigned int i = 1;i < m_MatrixSize;++i)
48 double absVal = std::abs(m_DMatrix[i]);
57 return std::numeric_limits<double>::max();
59 return maxVal / minVal;
64 m_ProblemSolution = b;
66 return m_ProblemSolution;
71 for (
unsigned int i = 1;i < m_MatrixSize;++i)
73 for (
unsigned int j = 0;j < i;++j)
74 b[i] -= m_LMatrix.get(i,j) * b[j];
77 for (
unsigned int i = 0;i < m_MatrixSize;++i)
80 for (
int i = m_MatrixSize - 2;i >= 0;--i)
82 for (
unsigned int j = i + 1;j < m_MatrixSize;++j)
83 b[i] -= m_LMatrix.get(j,i) * b[j];
92 for (
unsigned int i = 0;i < m_MatrixSize;++i)
94 double p = m_WorkVector[i];
95 double oldDValue = m_DMatrix[i];
96 m_DMatrix[i] += a * p * p;
97 double b = p * a / m_DMatrix[i];
98 a *= oldDValue / m_DMatrix[i];
100 for (
unsigned int j = i + 1;j < m_MatrixSize;++j)
102 m_WorkVector[j] -= p * m_LMatrix.get(j,i);
103 m_LMatrix(j,i) += b * m_WorkVector[j];
110 for (
unsigned int i = 0;i < m_MatrixSize;++i)
112 for (
unsigned int j = i;j < m_MatrixSize;++j)
115 for (
unsigned int k = 0;k <= i;++k)
116 iValue += m_LMatrix.get(i,k) * m_DMatrix[k] * m_LMatrix.get(j,k);
118 m_InputMatrix.put(i,j,iValue);
120 m_InputMatrix.put(j,i,iValue);
vnl_vector< double > VectorType
double GetConditionNumber()
Get condition number from decomposition.
void PerformDecomposition()
Performs LDL decomposition from input matrix.
void SetInputMatrix(const MatrixType &matrix)
Set input matrix to decompose.
void SolveLinearSystemInPlace(VectorType &b)
Solves linear system Ax=b and outputs result in input b variable.
void Recompose()
Recompose input matrix from LDL decomposition.
VectorType & SolveLinearSystem(const VectorType &b)
Solves linear system Ax=b and outputs result in new variable.
void Update(const VectorType &x)
Update decomposition with x so that LDL matches A + x x^T.
vnl_matrix< double > MatrixType