maspack.matrix
Class CholeskyDecomposition

java.lang.Object
  extended by maspack.matrix.CholeskyDecomposition

public class CholeskyDecomposition
extends java.lang.Object

Constructs the Cholesky decomposition of a symmetric positive definite matrix. This takes the form
M = L L'
where M is the original matrix, L is a lower-triangular matrix and L' denotes its transpose. Once this decomposition has been constructed, it can be used to perform various computations related to M, such as solving equations, computing the determinant, or estimating the condition number.

Providing a separate class for the Cholesky decomposition allows an application to perform such decompositions repeatedly without having to reallocate temporary storage space.


Constructor Summary
CholeskyDecomposition()
          Creates an uninitialized CholeskyDecomposition.
CholeskyDecomposition(int n)
          Creates an uninitialized CholeskyDecomposition with enough capacity to handle matrices of size n.
CholeskyDecomposition(Matrix M)
          Creates a CholeskyDecomposition for the Matrix specified by M.
 
Method Summary
 void addRowAndColumn(VectorNd col)
           
 boolean addRowAndColumn(VectorNd col, double tol)
           
 void clear()
           
 double conditionEstimate(Matrix M)
          Estimates the condition number of the original matrix M associated with this decomposition.
 void deleteRowAndColumn(int idx)
           
 double determinant()
          Compute the determinant of the original matrix M associated with this decomposition.
 void factor(Matrix M)
          Peforms a Cholesky decomposition on the Matrix M.
 void get(MatrixNd L)
          Gets the lower-triangular matrix L associated with the Cholesky decomposition.
 double[] getBuffer()
           
 int getBufferWidth()
           
 boolean inverse(DenseMatrix R)
          Computes the inverse of the original matrix M associated with this decomposition, and places the result in R.
 boolean leftSolveL(DenseMatrix X, Matrix B)
          Solves the linear equation
X L = B
for X, where L is the lower triangular factor associated with this decomposition, and X and B are matrices.
 boolean leftSolveL(Vector x, Vector b)
          Solves the linear equation
x L = b
for x, where L is the lower triangular factor associated this decomposition, and x and b are vectors.
 void setCapacity(int n)
           
 boolean solve(DenseMatrix X, Matrix B)
          Solves the linear equation
M X = B
for X, where M is the original matrix associated with this decomposition, and X and B are matrices.
 boolean solve(Vector x, Vector b)
          Solves the linear equation
M x = b
for x, where M is the original matrix associated with this decomposition, and x and b are vectors.
 boolean solveL(DenseMatrix X, Matrix B)
          Solves the linear equation
L X = B
for X, where L is the lower triangular factor associated with this decomposition, and X and B are matrices.
 boolean solveL(Vector x, Vector b)
          Solves the linear equation
L x = b
for x, where L is the lower triangular factor associated this decomposition, and x and b are vectors.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CholeskyDecomposition

public CholeskyDecomposition()
Creates an uninitialized CholeskyDecomposition.


CholeskyDecomposition

public CholeskyDecomposition(int n)
Creates an uninitialized CholeskyDecomposition with enough capacity to handle matrices of size n. This capacity will later be increased on demand.

Parameters:
n - initial maximum matrix size

CholeskyDecomposition

public CholeskyDecomposition(Matrix M)
                      throws ImproperSizeException
Creates a CholeskyDecomposition for the Matrix specified by M.

Parameters:
M - matrix to perform the Cholesky decomposition on
Throws:
ImproperSizeException - if M is not square
Method Detail

setCapacity

public void setCapacity(int n)

factor

public void factor(Matrix M)
            throws ImproperSizeException
Peforms a Cholesky decomposition on the Matrix M.

Parameters:
M - matrix to perform the Cholesky decomposition on
Throws:
ImproperSizeException - if M is not square
java.lang.IllegalArgumentException - if M is detected to be not symmetric positive definite

get

public void get(MatrixNd L)
         throws ImproperStateException,
                ImproperSizeException
Gets the lower-triangular matrix L associated with the Cholesky decomposition.

Parameters:
L - lower triangular matrix
Throws:
ImproperStateException - if this CholeskyDecomposition is uninitialized
ImproperSizeException - if L is not of the proper dimension and cannot be resized

solve

public boolean solve(Vector x,
                     Vector b)
              throws ImproperStateException,
                     ImproperSizeException
Solves the linear equation
M x = b
for x, where M is the original matrix associated with this decomposition, and x and b are vectors.

Parameters:
x - unknown vector to solve for
b - constant vector
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if b does not have a size compatible with M, or if x does not have a size compatible with M and cannot be resized.

solve

public boolean solve(DenseMatrix X,
                     Matrix B)
              throws ImproperStateException,
                     ImproperSizeException
Solves the linear equation
M X = B
for X, where M is the original matrix associated with this decomposition, and X and B are matrices.

Parameters:
X - unknown matrix to solve for
B - constant matrix
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if B has a different number of rows than M, or if X has a different number of rows than M or a different number of columns than B and cannot be resized.

solveL

public boolean solveL(Vector x,
                      Vector b)
               throws ImproperStateException,
                      ImproperSizeException
Solves the linear equation
L x = b
for x, where L is the lower triangular factor associated this decomposition, and x and b are vectors.

Parameters:
x - unknown vector to solve for
b - constant vector
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if b does not have a size compatible with L, or if x does not have a size compatible with L and cannot be resized.

solveL

public boolean solveL(DenseMatrix X,
                      Matrix B)
               throws ImproperStateException,
                      ImproperSizeException
Solves the linear equation
L X = B
for X, where L is the lower triangular factor associated with this decomposition, and X and B are matrices.

Parameters:
X - unknown matrix to solve for
B - constant matrix
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if B does not have a size compatible with L, or if X does not have a size compatible with L or B and cannot be resized.

leftSolveL

public boolean leftSolveL(Vector x,
                          Vector b)
                   throws ImproperStateException,
                          ImproperSizeException
Solves the linear equation
x L = b
for x, where L is the lower triangular factor associated this decomposition, and x and b are vectors.

Parameters:
x - unknown vector to solve for
b - constant vector
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if b does not have a size compatible with L, or if x does not have a size compatible with L and cannot be resized.

leftSolveL

public boolean leftSolveL(DenseMatrix X,
                          Matrix B)
                   throws ImproperStateException,
                          ImproperSizeException
Solves the linear equation
X L = B
for X, where L is the lower triangular factor associated with this decomposition, and X and B are matrices.

Parameters:
X - unknown matrix to solve for
B - constant matrix
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if B does not have a size compatible with L, or if X does not have a size compatible with L or B and cannot be resized.

conditionEstimate

public double conditionEstimate(Matrix M)
                         throws ImproperStateException,
                                ImproperSizeException
Estimates the condition number of the original matrix M associated with this decomposition. M must also be supplied as an argument. The algorithm for estimating the condition numberis based on Section 3.5.4 of Golub and Van Loan, Matrix Computations (Second Edition).

Parameters:
M - original matrix
Returns:
condition number estimate
Throws:
ImproperStateException - if this CholeskyDecomposition is uninitialized
ImproperSizeException - if the size of M does not match the size of the current Cholesky decomposition

determinant

public double determinant()
                   throws ImproperStateException
Compute the determinant of the original matrix M associated with this decomposition.

Returns:
determinant
Throws:
ImproperStateException - if this decomposition is uninitialized

inverse

public boolean inverse(DenseMatrix R)
                throws ImproperStateException
Computes the inverse of the original matrix M associated with this decomposition, and places the result in R.

Parameters:
R - matrix in which the inverse is stored
Returns:
false if M is singular (within working precision)
Throws:
ImproperStateException - if this decomposition is uninitialized
ImproperSizeException - if R does not have the same size as M and cannot be resized.

getBuffer

public double[] getBuffer()

getBufferWidth

public int getBufferWidth()

clear

public void clear()

addRowAndColumn

public void addRowAndColumn(VectorNd col)

addRowAndColumn

public boolean addRowAndColumn(VectorNd col,
                               double tol)

deleteRowAndColumn

public void deleteRowAndColumn(int idx)