Updateable Cholesky decomposition: A=LDL'. More...
#include <vnl_ldl_cholesky.h>
Public Types | |
| enum | Operation { quiet, verbose, estimate_condition } |
| Modes of computation. See constructor for details. More... | |
Public Member Functions | |
| vnl_ldl_cholesky (vnl_matrix< double > const &M, Operation mode=verbose) | |
| Make cholesky decomposition of M optionally computing the reciprocal condition number. More... | |
| ~vnl_ldl_cholesky ()=default | |
| vnl_vector< double > | solve (vnl_vector< double > const &b) const |
| Solve LS problem M x = b. More... | |
| void | solve (vnl_vector< double > const &b, vnl_vector< double > *x) const |
| Solve LS problem M x = b. More... | |
| void | solve_lx (vnl_vector< double > &y) |
| Solve equation of form Lx=y (in-place). More... | |
| double | determinant () const |
| Compute determinant. More... | |
| void | rank1_update (const vnl_vector< double > &v) |
| Compute rank-1 update, ie the decomposition of (M+v.v'). More... | |
| void | update (const vnl_matrix< double > &W) |
| Multi-rank update, ie the decomposition of (M+W.W'). More... | |
| vnl_matrix< double > | inverse () const |
| Compute inverse. Not efficient. More... | |
| const vnl_matrix< double > & | lower_triangle () const |
| Return lower-triangular factor. More... | |
| vnl_matrix< double > | upper_triangle () const |
| Return upper-triangular factor. More... | |
| const vnl_vector< double > & | diagonal () const |
| Return elements of diagonal matrix D in LDL'. More... | |
| double | xt_m_inv_x (const vnl_vector< double > &x) const |
| Efficient computation of x' * inv(M) * x. More... | |
| double | xt_m_x (const vnl_vector< double > &x) const |
| Efficient computation of x' * M * x. More... | |
| int | rank_deficiency () const |
| A Success/failure flag. More... | |
| double | rcond () const |
| Return reciprocal condition number (smallest/largest singular values). More... | |
| vnl_vector< double > & | nullvector () |
| Return computed nullvector. More... | |
| vnl_vector< double > const & | nullvector () const |
Protected Attributes | |
| vnl_matrix< double > | L_ |
| Lower triangular matrix. More... | |
| vnl_vector< double > | d_ |
| Elements of diagonal matrix. More... | |
| double | rcond_ |
| 1/(condition number). More... | |
| long | num_dims_rank_def_ |
| vnl_vector< double > | nullvector_ |
Private Member Functions | |
| vnl_ldl_cholesky (vnl_ldl_cholesky const &that)=delete | |
| Copy constructor - privatised to avoid it being used. More... | |
| vnl_ldl_cholesky & | operator= (vnl_ldl_cholesky const &that)=delete |
| Assignment operator - privatised to avoid it being used. More... | |
| void | inplace_solve (double *x) const |
| Solve Mx=b, overwriting input vector with the solution. More... | |
Updateable Cholesky decomposition: A=LDL'.
A class to hold the Cholesky decomposition of a positive definite symmetric matrix, using the form A=LDL', where L is lower triangular with ones on the leading diagonal, and D is a diagonal matrix. This differs from vnl_cholesky, which decomposes as A=LL', without a constraint on the diagonal. The advantage of the LDL' form is that it can be efficiently updated. Thus given the decomposition of A, we can compute the decomposition of (A+v.v') in O(n^2) time.
This can be used to solve linear systems, compute determinants and inverses.
To check that the decomposition can be used safely for solving a linear equation it is wise to construct with mode==estimate_condition and check that rcond()>sqrt(machine precision). If this is not the case it might be a good idea to use vnl_svd instead.
Definition at line 29 of file vnl_ldl_cholesky.h.
Modes of computation. See constructor for details.
| Enumerator | |
|---|---|
| quiet | |
| verbose | |
| estimate_condition | |
Definition at line 33 of file vnl_ldl_cholesky.h.
| vnl_ldl_cholesky::vnl_ldl_cholesky | ( | vnl_matrix< double > const & | M, |
| Operation | mode = verbose |
||
| ) |
Make cholesky decomposition of M optionally computing the reciprocal condition number.
Cholesky decomposition.
Make cholesky decomposition of M optionally computing the reciprocal condition number. If mode is estimate_condition, the condition number and an approximate nullspace are estimated, at a cost of a factor of (1 + 18/n). Here's a table of 1 + 18/n:
n: 3 5 10 50 100 500 1000 slowdown: 7.0 4.6 2.8 1.4 1.18 1.04 1.02
Sqrt of elements of diagonal matrix.
Definition at line 25 of file vnl_ldl_cholesky.cxx.
|
default |
|
privatedelete |
Copy constructor - privatised to avoid it being used.
| double vnl_ldl_cholesky::determinant | ( | ) | const |
Compute determinant.
Definition at line 177 of file vnl_ldl_cholesky.cxx.
|
inline |
Return elements of diagonal matrix D in LDL'.
Definition at line 78 of file vnl_ldl_cholesky.h.
|
private |
Solve Mx=b, overwriting input vector with the solution.
x points to beginning of an n-element vector containing b On exit, x[i] filled with solution vector.
Definition at line 98 of file vnl_ldl_cholesky.cxx.
| vnl_matrix< double > vnl_ldl_cholesky::inverse | ( | ) | const |
Compute inverse. Not efficient.
Note that you rarely need the inverse - backsubstitution is faster and less prone to rounding errors.
Definition at line 249 of file vnl_ldl_cholesky.cxx.
|
inline |
Return lower-triangular factor.
Definition at line 72 of file vnl_ldl_cholesky.h.
|
inline |
Return computed nullvector.
Not calculated unless Operation mode at construction was estimate_condition.
Definition at line 99 of file vnl_ldl_cholesky.h.
|
inline |
Definition at line 100 of file vnl_ldl_cholesky.h.
|
privatedelete |
Assignment operator - privatised to avoid it being used.
| void vnl_ldl_cholesky::rank1_update | ( | const vnl_vector< double > & | v | ) |
Compute rank-1 update, ie the decomposition of (M+v.v').
If the initial state is the decomposition of M, then L and D are updated so that on exit LDL'=M+v.v'
If the initial state is the decomposition of M, then L and D are updated so that on exit LDL'=M+v.v'
Uses the algorithm given by Davis and Hager in "Multiple-Rank Modifications of a Sparse Cholesky Factorization",2001.
Definition at line 191 of file vnl_ldl_cholesky.cxx.
|
inline |
A Success/failure flag.
Definition at line 89 of file vnl_ldl_cholesky.h.
|
inline |
Return reciprocal condition number (smallest/largest singular values).
As long as rcond()>sqrt(precision) the decomposition can be used for solving equations safely. Not calculated unless Operation mode at construction was estimate_condition.
Definition at line 95 of file vnl_ldl_cholesky.h.
| vnl_vector< double > vnl_ldl_cholesky::solve | ( | vnl_vector< double > const & | b | ) | const |
Solve LS problem M x = b.
Solve least squares problem M x = b.
Definition at line 167 of file vnl_ldl_cholesky.cxx.
| void vnl_ldl_cholesky::solve | ( | vnl_vector< double > const & | b, |
| vnl_vector< double > * | xp | ||
| ) | const |
Solve LS problem M x = b.
Solve least squares problem M x = b.
The right-hand-side std::vector x may be b, which will give a fractional increase in speed.
Definition at line 158 of file vnl_ldl_cholesky.cxx.
| void vnl_ldl_cholesky::solve_lx | ( | vnl_vector< double > & | x | ) |
Solve equation of form Lx=y (in-place).
Solve Lx=y (in-place).
x is overwritten with solution
Definition at line 88 of file vnl_ldl_cholesky.cxx.
| void vnl_ldl_cholesky::update | ( | const vnl_matrix< double > & | W0 | ) |
Multi-rank update, ie the decomposition of (M+W.W').
If the initial state is the decomposition of M, then L and D are updated so that on exit LDL'=M+W.W'
Definition at line 216 of file vnl_ldl_cholesky.cxx.
|
inline |
Return upper-triangular factor.
Definition at line 75 of file vnl_ldl_cholesky.h.
| double vnl_ldl_cholesky::xt_m_inv_x | ( | const vnl_vector< double > & | x | ) | const |
Efficient computation of x' * inv(M) * x.
Useful when M is a covariance matrix!
Useful when M is a covariance matrix! Solves Ly=x for y, then returns sum y[i]*y[i]/d[i]
Definition at line 121 of file vnl_ldl_cholesky.cxx.
| double vnl_ldl_cholesky::xt_m_x | ( | const vnl_vector< double > & | x | ) | const |
Efficient computation of x' * M * x.
Twice as fast as explicitly computing x' * M * x
Definition at line 138 of file vnl_ldl_cholesky.cxx.
|
protected |
Elements of diagonal matrix.
Definition at line 109 of file vnl_ldl_cholesky.h.
|
protected |
Lower triangular matrix.
Definition at line 106 of file vnl_ldl_cholesky.h.
|
protected |
Definition at line 114 of file vnl_ldl_cholesky.h.
|
protected |
Definition at line 113 of file vnl_ldl_cholesky.h.
|
protected |
1/(condition number).
Definition at line 112 of file vnl_ldl_cholesky.h.
1.8.15