[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

Functions
Advanced Matrix Algebra
Linear Algebra

Solution of linear systems, eigen systems, linear least squares etc. More...

Functions

template<class T , class C1 , class C2 >
bool choleskyDecomposition (MultiArrayView< 2, T, C1 > const &A, MultiArrayView< 2, T, C2 > &L)
template<class T , class C1 , class C2 , class C3 >
void choleskySolve (MultiArrayView< 2, T, C1 > &L, MultiArrayView< 2, T, C2 > const &b, MultiArrayView< 2, T, C3 > &x)
template<class T , class C1 >
determinant (MultiArrayView< 2, T, C1 > const &a, std::string method="LU")
template<class T , class C1 , class C2 >
bool inverse (const MultiArrayView< 2, T, C1 > &v, MultiArrayView< 2, T, C2 > &res)
template<class T , class C >
TemporaryMatrix< T > inverse (const MultiArrayView< 2, T, C > &v)
template<class T , class C1 , class C2 , class C3 >
bool linearSolve (const MultiArrayView< 2, T, C1 > &A, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &res, std::string method="QR")
template<class T , class C1 , class C2 , class C3 >
bool linearSolveLowerTriangular (const MultiArrayView< 2, T, C1 > &l, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > x)
template<class T , class C1 , class C2 , class C3 >
bool linearSolveUpperTriangular (const MultiArrayView< 2, T, C1 > &r, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > x)
template<class T , class C1 >
logDeterminant (MultiArrayView< 2, T, C1 > const &a)
template<class T , class C1 , class C2 , class C3 >
bool nonsymmetricEigensystem (MultiArrayView< 2, T, C1 > const &a, MultiArrayView< 2, std::complex< T >, C2 > &ew, MultiArrayView< 2, T, C3 > &ev)
template<class POLYNOMIAL , class VECTOR >
bool polynomialRealRootsEigenvalueMethod (POLYNOMIAL const &p, VECTOR &roots, bool)
template<class POLYNOMIAL , class VECTOR >
bool polynomialRootsEigenvalueMethod (POLYNOMIAL const &poly, VECTOR &roots, bool polishRoots)
template<class T , class C1 , class C2 , class C3 >
bool qrDecomposition (MultiArrayView< 2, T, C1 > const &a, MultiArrayView< 2, T, C2 > &q, MultiArrayView< 2, T, C3 > &r, double epsilon=0.0)
template<class T , class C1 , class C2 , class C3 >
bool reverseElimination (const MultiArrayView< 2, T, C1 > &r, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > x)
template<class T , class C1 , class C2 , class C3 , class C4 >
unsigned int singularValueDecomposition (MultiArrayView< 2, T, C1 > const &A, MultiArrayView< 2, T, C2 > &U, MultiArrayView< 2, T, C3 > &S, MultiArrayView< 2, T, C4 > &V)
template<class T , class C1 , class C2 , class C3 >
bool symmetricEigensystem (MultiArrayView< 2, T, C1 > const &a, MultiArrayView< 2, T, C2 > &ew, MultiArrayView< 2, T, C3 > &ev)

Detailed Description

Solution of linear systems, eigen systems, linear least squares etc.


Function Documentation

bool vigra::linalg::symmetricEigensystem ( MultiArrayView< 2, T, C1 > const &  a,
MultiArrayView< 2, T, C2 > &  ew,
MultiArrayView< 2, T, C3 > &  ev 
)
Compute the eigensystem of a symmetric matrix.

\a a is a real symmetric matrix, \a ew is a single-column matrix
holding the eigenvalues, and \a ev is a matrix of the same size as
\a a whose columns are the corresponding eigenvectors. Eigenvalues
will be sorted from largest to smallest magnitude.
The algorithm returns <tt>false</tt> when it doesn't
converge. It can be applied in-place, i.e. <tt>&a == &ev</tt> is allowed.
The code of this function was adapted from JAMA.

#include <vigra/eigensystem.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

bool vigra::linalg::nonsymmetricEigensystem ( MultiArrayView< 2, T, C1 > const &  a,
MultiArrayView< 2, std::complex< T >, C2 > &  ew,
MultiArrayView< 2, T, C3 > &  ev 
)
Compute the eigensystem of a square, but
not necessarily symmetric matrix.

\a a is a real square matrix, \a ew is a single-column matrix
holding the possibly complex eigenvalues, and \a ev is a matrix of
the same size as \a a whose columns are the corresponding eigenvectors.
Eigenvalues will be sorted from largest to smallest magnitude.
The algorithm returns <tt>false</tt> when it doesn't
converge. It can be applied in-place, i.e. <tt>&a == &ev</tt> is allowed.
The code of this function was adapted from JAMA.

#include <vigra/eigensystem.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

bool vigra::linalg::polynomialRootsEigenvalueMethod ( POLYNOMIAL const &  poly,
VECTOR &  roots,
bool  polishRoots 
)

Compute the roots of a polynomial using the eigenvalue method.

poly is a real polynomial (compatible to vigra::PolynomialView), and roots a complex valued vector (compatible to std::vector with a value_type compatible to the type POLYNOMIAL::Complex) to which the roots are appended. The function calls nonsymmetricEigensystem() with the standard companion matrix yielding the roots as eigenvalues. It returns false if it fails to converge.

#include <vigra/eigensystem.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

See also:
polynomialRoots(), vigra::Polynomial
bool vigra::linalg::polynomialRealRootsEigenvalueMethod ( POLYNOMIAL const &  p,
VECTOR &  roots,
bool   
)

Compute the real roots of a real polynomial using the eigenvalue method.

poly is a real polynomial (compatible to vigra::PolynomialView), and roots a real valued vector (compatible to std::vector with a value_type compatible to the type POLYNOMIAL::Real) to which the roots are appended. The function calls polynomialRootsEigenvalueMethod() and throws away all complex roots. It returns false if it fails to converge. The parameter polishRoots is ignored (it is only here for syntax compatibility with polynomialRealRoots()).

#include <vigra/eigensystem.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

See also:
polynomialRealRoots(), vigra::Polynomial
bool vigra::linalg::inverse ( const MultiArrayView< 2, T, C1 > &  v,
MultiArrayView< 2, T, C2 > &  res 
)
Create the inverse or pseudo-inverse of matrix \a v.

If the matrix \a v is square, \a res must have the same shape and will contain the
inverse of \a v. If \a v is rectangular, it must have more rows than columns, and \a res
must have the transposed shape of \a v. The inverse is then computed in the least-squares 
sense, i.e. \a res will be the pseudo-inverse (Moore-Penrose inverse).
The function returns <tt>true</tt> upon success, and <tt>false</tt> if \a v 
is not invertible (has not full rank). The inverse is computed by means of QR 
decomposition. This function can be applied in-place.

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

TemporaryMatrix<T> vigra::linalg::inverse ( const MultiArrayView< 2, T, C > &  v)
Create the inverse or pseudo-inverse of matrix \a v.

The result is returned as a temporary matrix. If the matrix \a v is square, 
the result will have the same shape and contains the inverse of \a v. 
If \a v is rectangular, it must have more rows than columns, and the result will
have the transposed shape of \a v. The inverse is then computed in the least-squares 
sense, i.e. \a res will be the pseudo-inverse (Moore-Penrose inverse).
The inverse is computed by means of QR decomposition. If \a v
is not invertible, <tt>vigra::PreconditionViolation</tt> exception is thrown.
Usage:

@code 
vigra::Matrix<double> v(n, n);
v = ...;

vigra::Matrix<double> m = inverse(v);
\endcode

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

T vigra::linalg::determinant ( MultiArrayView< 2, T, C1 > const &  a,
std::string  method = "LU" 
)
Compute the determinant of a square matrix.

\a method must be one of the following:
<DL>
<DT>"Cholesky"<DD> Compute the solution by means of Cholesky decomposition. This
                   method is faster than "LU", but requires the matrix \a a 
                   to be symmetric positive definite. If this is 
                   not the case, a <tt>ContractViolation</tt> exception is thrown.

<DT>"LU"<DD> (default) Compute the solution by means of LU decomposition.
</DL>

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

T vigra::linalg::logDeterminant ( MultiArrayView< 2, T, C1 > const &  a)
Compute the logarithm of the determinant of a symmetric positive definite matrix.

This is useful to avoid multiplication of very large numbers in big matrices.
It is implemented by means of Cholesky decomposition.

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

bool vigra::linalg::choleskyDecomposition ( MultiArrayView< 2, T, C1 > const &  A,
MultiArrayView< 2, T, C2 > &  L 
)
Cholesky decomposition.

\a A must be a symmetric positive definite matrix, and \a L will be a lower
triangular matrix, such that (up to round-off errors):

@code 
A == L * transpose(L);
\endcode

This implementation cannot be applied in-place, i.e. <tt>&L == &A</tt> is an error.
If \a A is not symmetric, a <tt>ContractViolation</tt> exception is thrown. If it
is not positive definite, the function returns <tt>false</tt>.

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

bool vigra::linalg::qrDecomposition ( MultiArrayView< 2, T, C1 > const &  a,
MultiArrayView< 2, T, C2 > &  q,
MultiArrayView< 2, T, C3 > &  r,
double  epsilon = 0.0 
)
QR decomposition.

\a a contains the original matrix, results are returned in \a q and \a r, where
\a q is a orthogonal matrix, and \a r is an upper triangular matrix, such that 
(up to round-off errors):

@code 
a == q * r;
\endcode

If \a a dosn't have full rank, the function returns <tt>false</tt>. 
The decomposition is computed by householder transformations. It can be applied in-place,
i.e. <tt>&a == &q</tt> or <tt>&a == &r</tt> are allowed.

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

bool vigra::linalg::reverseElimination ( const MultiArrayView< 2, T, C1 > &  r,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 >  x 
)

Deprecated, use linearSolveUpperTriangular().

bool vigra::linalg::linearSolveUpperTriangular ( const MultiArrayView< 2, T, C1 > &  r,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 >  x 
)
Solve a linear system with upper-triangular coefficient matrix.

The square matrix \a r must be an upper-triangular coefficient matrix as can,
for example, be obtained by means of QR decomposition. If \a r doesn't have full rank
the function fails and returns <tt>false</tt>, otherwise it returns <tt>true</tt>. The 
lower triangular part of matrix \a r will not be touched, so it doesn't need to contain zeros.

The column vectors of matrix \a b are the right-hand sides of the equation (several equations
with the same coefficients can thus be solved in one go). The result is returned
int \a x, whose columns contain the solutions for the corresponding
columns of \a b. This implementation can be applied in-place, i.e. <tt>&b == &x</tt> is allowed.
The following size requirements apply:

@code 
rowCount(r) == columnCount(r);
rowCount(r) == rowCount(b);
columnCount(r) == rowCount(x);
columnCount(b) == columnCount(x);
\endcode

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

bool vigra::linalg::linearSolveLowerTriangular ( const MultiArrayView< 2, T, C1 > &  l,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 >  x 
)
Solve a linear system with lower-triangular coefficient matrix.

The square matrix \a l must be a lower-triangular coefficient matrix. If \a l 
doesn't have full rank the function fails and returns <tt>false</tt>, 
otherwise it returns <tt>true</tt>. The upper triangular part of matrix \a l will not be touched, 
so it doesn't need to contain zeros.

The column vectors of matrix \a b are the right-hand sides of the equation (several equations
with the same coefficients can thus be solved in one go). The result is returned
in \a x, whose columns contain the solutions for the correspoinding
columns of \a b. This implementation can be applied in-place, i.e. <tt>&b == &x</tt> is allowed.
The following size requirements apply:

@code 
rowCount(l) == columnCount(l);
rowCount(l) == rowCount(b);
columnCount(l) == rowCount(x);
columnCount(b) == columnCount(x);
\endcode

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

void vigra::linalg::choleskySolve ( MultiArrayView< 2, T, C1 > &  L,
MultiArrayView< 2, T, C2 > const &  b,
MultiArrayView< 2, T, C3 > &  x 
)
Solve a linear system when the Cholesky decomposition of the left hand side is given.

The square matrix \a L must be a lower-triangular matrix resulting from Cholesky
decomposition of some positive definite coefficient matrix.

The column vectors of matrix \a b are the right-hand sides of the equation (several equations
with the same matrix \a L can thus be solved in one go). The result is returned
in \a x, whose columns contain the solutions for the correspoinding
columns of \a b. This implementation can be applied in-place, i.e. <tt>&b == &x</tt> is allowed.
The following size requirements apply:

@code 
rowCount(L) == columnCount(L);
rowCount(L) == rowCount(b);
columnCount(L) == rowCount(x);
columnCount(b) == columnCount(x);
\endcode

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

bool vigra::linalg::linearSolve ( const MultiArrayView< 2, T, C1 > &  A,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 > &  res,
std::string  method = "QR" 
)
Solve a linear system.

\a A is the coefficient matrix, and the column vectors
in \a b are the right-hand sides of the equation (so, several equations
with the same coefficients can be solved in one go). The result is returned 
in \a res, whose columns contain the solutions for the corresponding
columns of \a b. The number of columns of \a A must equal the number of rows of
both \a b and \a res, and the number of columns of \a b and \a res must match. 

\a method must be one of the following:
<DL>
<DT>"Cholesky"<DD> Compute the solution by means of Cholesky decomposition. The 
                   coefficient matrix \a A must by symmetric positive definite. If
                   this is not the case, the function returns <tt>false</tt>.

<DT>"QR"<DD> (default) Compute the solution by means of QR decomposition.  The 
                   coefficient matrix \a A can be square or rectangular. In the latter case,
                   it must have more rows than columns, and the solution will be computed in the 
                   least squares sense. If \a A doesn't have full rank, the function 
                   returns <tt>false</tt>.

<DT>"SVD"<DD> Compute the solution by means of singular value decomposition.  The 
                   coefficient matrix \a A can be square or rectangular. In the latter case,
                   it must have more rows than columns, and the solution will be computed in the 
                   least squares sense. If \a A doesn't have full rank, the function 
                   returns <tt>false</tt>.

<DT>"NE"<DD> Compute the solution by means of the normal equations, i.e. by applying Cholesky
                   decomposition to the equivalent problem <tt>A'*A*x = A'*b</tt>. This only makes sense
                   when the equation is to be solved in the least squares sense, i.e. when \a A is a 
                   rectangular matrix with more rows than columns. If \a A doesn't have full column rank, 
                   the function returns <tt>false</tt>.
</DL>

This function can be applied in-place, i.e. <tt>&b == &res</tt> or <tt>&A == &res</tt> are allowed
(provided they have the required shapes).

The following size requirements apply:

@code 
rowCount(r) == rowCount(b);
columnCount(r) == rowCount(x);
columnCount(b) == columnCount(x);
\endcode

#include <vigra/linear_solve.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

unsigned int vigra::linalg::singularValueDecomposition ( MultiArrayView< 2, T, C1 > const &  A,
MultiArrayView< 2, T, C2 > &  U,
MultiArrayView< 2, T, C3 > &  S,
MultiArrayView< 2, T, C4 > &  V 
)
Singular Value Decomposition.

For an m-by-n matrix A with m >= n, the singular value decomposition is an m-by-n orthogonal matrix U, an n-by-n diagonal matrix S, and an n-by-n orthogonal matrix V so that A = U*S*V'.

To save memory, this functions stores the matrix S in a column vector of appropriate length (a diagonal matrix can be obtained by diagonalMatrix(S)). The singular values, sigma[k] = S(k, 0), are ordered so that sigma[0] >= sigma[1] >= ... >= sigma[n-1].

The singular value decomposition always exists, so this function will never fail (except if the shapes of the argument matrices don't match). The effective numerical rank of A is returned.

(Adapted from JAMA, a Java Matrix Library, developed jointly by the Mathworks and NIST; see http://math.nist.gov/javanumerics/jama).

#include <vigra/singular_value_decomposition.hxx> or
#include <vigra/linear_algebra.hxx>
Namespaces: vigra and vigra::linalg

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.7.1 (Tue Jul 10 2012)