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

vigra::linalg Namespace Reference

Linear algebra functions. More...

Classes

class  LeastAngleRegressionOptions
 Pass options to leastAngleRegression(). More...
 
class  Matrix
 

Functions

template<class T , class C >
linalg::TemporaryMatrix< T > abs (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
linalg::TemporaryMatrix< T > acos (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C1 , class C2 , class C3 >
void add (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
 
template<class T , class C >
int argMax (MultiArrayView< 2, T, C > const &a)
 Find the index of the maximum element in a matrix.
 
template<class T , class C , class UnaryFunctor >
int argMaxIf (MultiArrayView< 2, T, C > const &a, UnaryFunctor condition)
 Find the index of the maximum element in a matrix subject to a condition.
 
template<class T , class C >
int argMin (MultiArrayView< 2, T, C > const &a)
 Find the index of the minimum element in a matrix.
 
template<class T , class C , class UnaryFunctor >
int argMinIf (MultiArrayView< 2, T, C > const &a, UnaryFunctor condition)
 Find the index of the minimum element in a matrix subject to a condition.
 
template<class T , class C >
linalg::TemporaryMatrix< T > asin (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
linalg::TemporaryMatrix< T > atan (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
linalg::TemporaryMatrix< T > ceil (MultiArrayView< 2, T, C > const &v)
 
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 > const &L, MultiArrayView< 2, T, C2 > const &b, MultiArrayView< 2, T, C3 > &x)
 
template<class T , class C >
MultiArrayIndex columnCount (const MultiArrayView< 2, T, C > &x)
 
template<... >
void columnStatistics (...)
 
template<class T , class C >
MultiArrayView< 2, T, CcolumnVector (MultiArrayView< 2, T, C > const &m, MultiArrayIndex d)
 
template<class T , class C >
MultiArrayView< 2, T, CcolumnVector (MultiArrayView< 2, T, C > const &m, MultiArrayShape< 2 >::type first, int end)
 
template<class T , class C >
linalg::TemporaryMatrix< T > cos (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
TemporaryMatrix< T > covarianceMatrixOfColumns (MultiArrayView< 2, T, C > const &features)
 Compute the covariance matrix between the columns of a matrix features.
 
template<class T1 , class C1 , class T2 , class C2 >
void covarianceMatrixOfColumns (MultiArrayView< 2, T1, C1 > const &features, MultiArrayView< 2, T2, C2 > &covariance)
 Compute the covariance matrix between the columns of a matrix features.
 
template<class T , class C >
TemporaryMatrix< T > covarianceMatrixOfRows (MultiArrayView< 2, T, C > const &features)
 Compute the covariance matrix between the rows of a matrix features.
 
template<class T1 , class C1 , class T2 , class C2 >
void covarianceMatrixOfRows (MultiArrayView< 2, T1, C1 > const &features, MultiArrayView< 2, T2, C2 > &covariance)
 Compute the covariance matrix between the rows of a matrix features.
 
template<class T , class C1 , class C2 , class C3 >
void cross (const MultiArrayView< 1, T, C1 > &x, const MultiArrayView< 1, T, C2 > &y, MultiArrayView< 1, T, C3 > &r)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > cross (const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y)
 
template<class T , class C1 , class C2 , class C3 >
void cross (const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y, MultiArrayView< 2, T, C3 > &r)
 
template<class T , class C1 >
NumericTraits< T >::Promote determinant (MultiArrayView< 2, T, C1 > const &a, std::string method="default")
 
template<class T , class C >
TemporaryMatrix< T > diagonalMatrix (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C1 , class C2 >
void diagonalMatrix (MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r)
 
template<class T , class C1 , class C2 >
NormTraits< T >::SquaredNormType dot (const MultiArrayView< 1, T, C1 > &x, const MultiArrayView< 1, T, C2 > &y)
 
template<class T , class C1 , class C2 >
NormTraits< T >::SquaredNormType dot (const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y)
 
template<class T , class C >
linalg::TemporaryMatrix< T > exp (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
linalg::TemporaryMatrix< T > floor (MultiArrayView< 2, T, C > const &v)
 
template<class T >
TemporaryMatrix< T > identityMatrix (MultiArrayIndex size)
 
template<class T , class C >
void identityMatrix (MultiArrayView< 2, T, C > &r)
 
template<class T , class C >
TemporaryMatrix< T > inverse (const MultiArrayView< 2, T, C > &v)
 
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 >
bool isSymmetric (const MultiArrayView< 2, T, C > &v)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > joinHorizontally (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > joinVertically (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<... >
unsigned int leastAngleRegression (...)
 
template<class T , class C1 , class C2 , class C3 >
bool leastSquares (MultiArrayView< 2, T, C1 > const &A, MultiArrayView< 2, T, C2 > const &b, MultiArrayView< 2, T, C3 > &x, std::string method="QR")
 
template<... >
bool linearSolve (...)
 
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 C >
linalg::TemporaryMatrix< T > log (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
linalg::TemporaryMatrix< T > log10 (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C1 >
logDeterminant (MultiArrayView< 2, T, C1 > const &a)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > mmul (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<class T , class C1 , class C2 , class C3 >
void mmul (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
 
template<... >
unsigned int nonnegativeLeastSquares (...)
 
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 T , class ALLOC >
Matrix< T, ALLLOC >::NormType norm (const Matrix< T, ALLLOC > &a)
 
template<class T >
TemporaryMatrix< T > ones (MultiArrayIndex rows, MultiArrayIndex cols)
 
template<class T , class A , int N, class DATA , class DERIVED >
TinyVector< T, N > operator* (const Matrix< T, A > &a, const TinyVectorBase< T, N, DATA, DERIVED > &b)
 
template<class T , class C , class U >
TemporaryMatrix< T > operator* (const MultiArrayView< 2, T, C > &a, PointWise< U > b)
 
template<class T , class C >
TemporaryMatrix< T > operator* (const MultiArrayView< 2, T, C > &a, T b)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > operator* (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<class T , int N, class DATA , class DERIVED , class A >
TinyVector< T, N > operator* (const TinyVectorBase< T, N, DATA, DERIVED > &a, const Matrix< T, A > &b)
 
template<class T , class C >
TemporaryMatrix< T > operator* (T a, const MultiArrayView< 2, T, C > &b)
 
template<class T , class C >
TemporaryMatrix< T > operator+ (const MultiArrayView< 2, T, C > &a, T b)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > operator+ (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<class T , class C >
TemporaryMatrix< T > operator+ (T a, const MultiArrayView< 2, T, C > &b)
 
template<class T , class C >
TemporaryMatrix< T > operator- (const MultiArrayView< 2, T, C > &a)
 
template<class T , class C >
TemporaryMatrix< T > operator- (const MultiArrayView< 2, T, C > &a, T b)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > operator- (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<class T , class C >
TemporaryMatrix< T > operator- (T a, const MultiArrayView< 2, T, C > &b)
 
template<class T , class C , class U >
TemporaryMatrix< T > operator/ (const MultiArrayView< 2, T, C > &a, PointWise< U > b)
 
template<class T , class C >
TemporaryMatrix< T > operator/ (const MultiArrayView< 2, T, C > &a, T b)
 
template<class T , class C >
TemporaryMatrix< T > operator/ (T a, const MultiArrayView< 2, T, C > &b)
 
template<class T , class C >
TemporaryMatrix< T > outer (const MultiArrayView< 2, T, C > &x)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > outer (const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y)
 
template<class T , class C1 , class C2 , class C3 >
void outer (const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y, MultiArrayView< 2, T, C3 > &r)
 
template<class T , int N>
TemporaryMatrix< T > outer (const TinyVector< T, N > &x)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > pdiv (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<class T , class C1 , class C2 , class C3 >
void pdiv (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
 
template<class T , class C1 , class C2 >
TemporaryMatrix< T > pmul (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b)
 
template<class T , class C1 , class C2 , class C3 >
void pmul (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
 
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 C >
linalg::TemporaryMatrix< T > pow (MultiArrayView< 2, T, C > const &v, T exponent)
 
template<... >
void prepareColumns (...)
 Standardize the columns of a matrix according to given DataPreparationGoals.
 
template<... >
void prepareRows (...)
 Standardize the rows of a matrix according to given DataPreparationGoals.
 
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 C >
TemporaryMatrix< T > repeatMatrix (MultiArrayView< 2, T, C > const &v, unsigned int verticalCount, unsigned int horizontalCount)
 
template<class T , class C1 , class C2 >
void repeatMatrix (MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r, unsigned int verticalCount, unsigned int horizontalCount)
 
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 >
bool ridgeRegression (MultiArrayView< 2, T, C1 > const &A, MultiArrayView< 2, T, C2 > const &b, MultiArrayView< 2, T, C3 > &x, double lambda)
 
template<class T , class C1 , class C2 , class C3 , class Array >
bool ridgeRegressionSeries (MultiArrayView< 2, T, C1 > const &A, MultiArrayView< 2, T, C2 > const &b, MultiArrayView< 2, T, C3 > &x, Array const &lambda)
 
template<class T , class C >
linalg::TemporaryMatrix< T > round (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
MultiArrayIndex rowCount (const MultiArrayView< 2, T, C > &x)
 
template<... >
void rowStatistics (...)
 
template<class T , class C >
MultiArrayView< 2, T, CrowVector (MultiArrayView< 2, T, C > const &m, MultiArrayIndex d)
 
template<class T , class C >
MultiArrayView< 2, T, CrowVector (MultiArrayView< 2, T, C > const &m, MultiArrayShape< 2 >::type first, MultiArrayIndex end)
 
template<class T , class C1 , class C2 >
void sdiv (const MultiArrayView< 2, T, C1 > &a, T b, MultiArrayView< 2, T, C2 > &r)
 
template<class T , class C >
linalg::TemporaryMatrix< T > sign (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
linalg::TemporaryMatrix< T > sin (MultiArrayView< 2, T, C > const &v)
 
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 >
void smul (const MultiArrayView< 2, T, C1 > &a, T b, MultiArrayView< 2, T, C2 > &r)
 
template<class T , class C2 , class C3 >
void smul (T a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
 
template<class T , class C >
linalg::TemporaryMatrix< T > sq (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
linalg::TemporaryMatrix< T > sqrt (MultiArrayView< 2, T, C > const &v)
 
template<class T , class ALLOC >
Matrix< T, ALLLOC >::SquaredNormType squaredNorm (const Matrix< T, ALLLOC > &a)
 
template<class T , class C1 , class C2 , class C3 >
void sub (const MultiArrayView< 2, T, C1 > &a, const MultiArrayView< 2, T, C2 > &b, MultiArrayView< 2, T, C3 > &r)
 
template<class T , class C >
MultiArrayView< 2, T, CsubVector (MultiArrayView< 2, T, C > const &m, int first, int end)
 
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)
 
template<class T , class C1 , class C2 , class C3 >
bool symmetricEigensystemNoniterative (MultiArrayView< 2, T, C1 > const &a, MultiArrayView< 2, T, C2 > &ew, MultiArrayView< 2, T, C3 > &ev)
 
template<class T , class C >
linalg::TemporaryMatrix< T > tan (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C >
NumericTraits< T >::Promote trace (MultiArrayView< 2, T, C > const &m)
 
template<class T , class C1 , class C2 >
void transpose (const MultiArrayView< 2, T, C1 > &v, MultiArrayView< 2, T, C2 > &r)
 
template<class T , class C >
MultiArrayView< 2, T, StridedArrayTagtranspose (MultiArrayView< 2, T, C > const &v)
 
template<class T , class C1 , class C2 , class C3 , class C4 >
bool weightedLeastSquares (MultiArrayView< 2, T, C1 > const &A, MultiArrayView< 2, T, C2 > const &b, MultiArrayView< 2, T, C3 > const &weights, MultiArrayView< 2, T, C4 > &x, std::string method="QR")
 
template<class T , class C1 , class C2 , class C3 , class C4 >
bool weightedRidgeRegression (MultiArrayView< 2, T, C1 > const &A, MultiArrayView< 2, T, C2 > const &b, MultiArrayView< 2, T, C3 > const &weights, MultiArrayView< 2, T, C4 > &x, double lambda)
 

Detailed Description

Linear algebra functions.

Namespace vigra/linalg hold VIGRA's linear algebra functionality. But most of its contents is exported into namespace vigra via using directives.

Function Documentation

◆ symmetricEigensystem()

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 
)

Compute the eigensystem of a symmetric matrix.

a is a real symmetric matrix, ew is a single-column matrix holding the eigenvalues, and ev is a matrix of the same size as a whose columns are the corresponding eigenvectors. Eigenvalues will be sorted from largest to smallest. The algorithm returns false when it doesn't converge. It can be applied in-place, i.e. &a == &ev 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

◆ symmetricEigensystemNoniterative()

template<class T , class C1 , class C2 , class C3 >
bool symmetricEigensystemNoniterative ( MultiArrayView< 2, T, C1 > const a,
MultiArrayView< 2, T, C2 > &  ew,
MultiArrayView< 2, T, C3 > &  ev 
)

Fast computation of the eigensystem of a 2x2 or 3x3 symmetric matrix.

The function works like symmetricEigensystem(), but uses fast analytic formula to avoid iterative computations.

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

◆ nonsymmetricEigensystem()

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 
)

Compute the eigensystem of a square, but not necessarily symmetric matrix.

a is a real square matrix, ew is a single-column matrix holding the possibly complex eigenvalues, and ev is a matrix of the same size as a whose columns are the corresponding eigenvectors. Eigenvalues will be sorted from largest to smallest magnitude. The algorithm returns false when it doesn't converge. It can be applied in-place, i.e. &a == &ev 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

◆ polynomialRootsEigenvalueMethod()

template<class POLYNOMIAL , class VECTOR >
bool 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

◆ polynomialRealRootsEigenvalueMethod()

template<class POLYNOMIAL , class VECTOR >
bool 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

◆ inverse() [1/2]

template<class T , class C1 , class C2 >
bool inverse ( const MultiArrayView< 2, T, C1 > &  v,
MultiArrayView< 2, T, C2 > &  res 
)

Create the inverse or pseudo-inverse of matrix v.

If the matrix v is square, res must have the same shape and will contain the inverse of v. If v is rectangular, res must have the transposed shape of v. The inverse is then computed in the least-squares sense, i.e. res will be the pseudo-inverse (Moore-Penrose inverse). The function returns true upon success, and false if 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

◆ inverse() [2/2]

template<class T , class C >
TemporaryMatrix< T > inverse ( const MultiArrayView< 2, T, C > &  v)

Create the inverse or pseudo-inverse of matrix v.

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

v = ...;
Class for a single RGB value.
Definition rgbvalue.hxx:128
bool inverse(const MultiArrayView< 2, T, C1 > &v, MultiArrayView< 2, T, C2 > &res)
Definition linear_solve.hxx:760

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

◆ determinant()

template<class T , class C1 >
NumericTraits< T >::Promote determinant ( MultiArrayView< 2, T, C1 > const a,
std::string  method = "default" 
)

Compute the determinant of a square matrix.

method must be one of the following:

"default"
Use "minor" for integral types and "LU" for any other.
"Cholesky"
Compute the solution by means of Cholesky decomposition. This method is faster than "LU", but requires the matrix a to be symmetric positive definite. If this is not the case, a ContractViolation exception is thrown.
"LU"
Compute the solution by means of LU decomposition.
"minor"
Compute the solution by means of determinants of minors.

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

◆ logDeterminant()

template<class T , class C1 >
T 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

◆ choleskyDecomposition()

template<class T , class C1 , class C2 >
bool choleskyDecomposition ( MultiArrayView< 2, T, C1 > const A,
MultiArrayView< 2, T, C2 > &  L 
)

Cholesky decomposition.

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

A == L * transpose(L);
void transpose(const MultiArrayView< 2, T, C1 > &v, MultiArrayView< 2, T, C2 > &r)
Definition matrix.hxx:965

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

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

◆ qrDecomposition()

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 
)

QR decomposition.

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

a == q * r;

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

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

◆ reverseElimination()

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 
)

Deprecated, use linearSolveUpperTriangular().

◆ linearSolveUpperTriangular()

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 
)

Solve a linear system with upper-triangular coefficient matrix.

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

The column vectors of matrix 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 x, whose columns contain the solutions for the corresponding columns of b. This implementation can be applied in-place, i.e. &b == &x is allowed. The following size requirements apply:

rowCount(r) == rowCount(b);
MultiArrayIndex columnCount(const MultiArrayView< 2, T, C > &x)
Definition matrix.hxx:684
MultiArrayIndex rowCount(const MultiArrayView< 2, T, C > &x)
Definition matrix.hxx:671

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

◆ linearSolveLowerTriangular()

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 
)

Solve a linear system with lower-triangular coefficient matrix.

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

The column vectors of matrix 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 x, whose columns contain the solutions for the corresponding columns of b. This implementation can be applied in-place, i.e. &b == &x is allowed. The following size requirements apply:

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

◆ choleskySolve()

template<class T , class C1 , class C2 , class C3 >
void choleskySolve ( MultiArrayView< 2, T, C1 > const 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 L must be a lower-triangular matrix resulting from Cholesky decomposition of some positive definite coefficient matrix.

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

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

◆ linearSolve()

template<... >
bool linearSolve (   ...)

Solve a linear system.

Declarations:

// use MultiArrayViews for input and output
template <class T, class C1, class C2, class C3>
std::string method = "QR");
// use TinyVector for RHS and result
template <class T, class C1, int N>
TinyVector<T, N> const & b,
std::string method = "QR");
bool linearSolve(...)

A is the coefficient matrix, and the column vectors in 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 res, whose columns contain the solutions for the corresponding columns of b. The number of columns of A must equal the number of rows of both b and res, and the number of columns of b and res must match. If right-hand-side and result are specified as TinyVector, the number of columns of A must equal N.

method must be one of the following:

"Cholesky"

Compute the solution by means of Cholesky decomposition. The coefficient matrix A must by symmetric positive definite. If this is not the case, the function returns false.

"QR"

(default) Compute the solution by means of QR decomposition. The coefficient matrix 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 doesn't have full rank, the function returns false.

"SVD"

Compute the solution by means of singular value decomposition. The coefficient matrix 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 doesn't have full rank, the function returns false.

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

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

The following size requirements apply:

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

◆ rowCount()

template<class T , class C >
MultiArrayIndex rowCount ( const MultiArrayView< 2, T, C > &  x)

Number of rows of a matrix represented as a MultiArrayView<2, ...>

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

◆ columnCount()

template<class T , class C >
MultiArrayIndex columnCount ( const MultiArrayView< 2, T, C > &  x)

Number of columns of a matrix represented as a MultiArrayView<2, ...>

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

◆ rowVector() [1/2]

template<class T , class C >
MultiArrayView< 2, T, C > rowVector ( MultiArrayView< 2, T, C > const m,
MultiArrayIndex  d 
)

Create a row vector view for row d of the matrix m

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

◆ columnVector() [1/2]

template<class T , class C >
MultiArrayView< 2, T, C > columnVector ( MultiArrayView< 2, T, C > const m,
MultiArrayIndex  d 
)

Create a column vector view for column d of the matrix m

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

◆ transpose() [1/2]

template<class T , class C1 , class C2 >
void transpose ( const MultiArrayView< 2, T, C1 > &  v,
MultiArrayView< 2, T, C2 > &  r 
)

transpose matrix v. The result is written into r which must have the correct (i.e. transposed) shape.

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

◆ isSymmetric()

template<class T , class C >
bool isSymmetric ( MultiArrayView< 2, T, C > const m)

Check whether matrix m is symmetric.

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

◆ rowVector() [2/2]

template<class T , class C >
MultiArrayView< 2, T, C > rowVector ( MultiArrayView< 2, T, C > const m,
MultiArrayShape< 2 >::type  first,
MultiArrayIndex  end 
)

Create a row vector view of the matrix m starting at element first and ranging to column end (non-inclusive).

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

◆ columnVector() [2/2]

template<class T , class C >
MultiArrayView< 2, T, C > columnVector ( MultiArrayView< 2, T, C > const m,
MultiArrayShape< 2 >::type  first,
int  end 
)

Create a column vector view of the matrix m starting at element first and ranging to row end (non-inclusive).

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

◆ subVector()

template<class T , class C >
MultiArrayView< 2, T, C > subVector ( MultiArrayView< 2, T, C > const m,
int  first,
int  end 
)

Create a sub vector view of the vector m starting at element first and ranging to row end (non-inclusive).

Note: This function may only be called when either rowCount(m) == 1 or columnCount(m) == 1, i.e. when m really represents a vector. Otherwise, a PreconditionViolation exception is raised.

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

◆ trace()

template<class T , class C >
NumericTraits< T >::Promote trace ( MultiArrayView< 2, T, C > const m)

Compute the trace of a square matrix.

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

◆ squaredNorm()

template<class T , class ALLOC >
Matrix< T, ALLLOC >::SquaredNormType squaredNorm ( const Matrix< T, ALLLOC > &  a)

calculate the squared Frobenius norm of a matrix. Equal to the sum of squares of the matrix elements.

#include <vigra/matrix.hxx> Namespace: vigra

◆ norm()

template<class T , class ALLOC >
Matrix< T, ALLLOC >::NormType norm ( const Matrix< T, ALLLOC > &  a)

calculate the Frobenius norm of a matrix. Equal to the root of the sum of squares of the matrix elements.

#include <vigra/matrix.hxx> Namespace: vigra

◆ identityMatrix() [1/2]

template<class T , class C >
void identityMatrix ( MultiArrayView< 2, T, C > &  r)

initialize the given square matrix as an identity matrix.

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

◆ identityMatrix() [2/2]

template<class T >
TemporaryMatrix< T > identityMatrix ( MultiArrayIndex  size)

create an identity matrix of the given size. Usage:

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

◆ ones()

template<class T >
TemporaryMatrix< T > ones ( MultiArrayIndex  rows,
MultiArrayIndex  cols 
)

create matrix of ones of the given size. Usage:

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

◆ diagonalMatrix() [1/2]

template<class T , class C1 , class C2 >
void diagonalMatrix ( MultiArrayView< 2, T, C1 > const v,
MultiArrayView< 2, T, C2 > &  r 
)

make a diagonal matrix from a vector. The vector is given as matrix v, which must either have a single row or column. The result is written into the square matrix r.

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

◆ diagonalMatrix() [2/2]

template<class T , class C >
TemporaryMatrix< T > diagonalMatrix ( MultiArrayView< 2, T, C > const v)

create a diagonal matrix from a vector. The vector is given as matrix v, which must either have a single row or column. The result is returned as a temporary matrix. Usage:

v = ...;
void diagonalMatrix(MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r)
Definition matrix.hxx:915

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

◆ transpose() [2/2]

template<class T , class C >
MultiArrayView< 2, T, StridedArrayTag > transpose ( MultiArrayView< 2, T, C > const v)

create the transpose of matrix v. This does not copy any data, but only creates a transposed view to the original matrix. A copy is only made when the transposed view is assigned to another matrix. Usage:

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

◆ joinVertically()

template<class T , class C1 , class C2 >
TemporaryMatrix< T > joinVertically ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

Create new matrix by concatenating two matrices a and b vertically, i.e. on top of each other. The two matrices must have the same number of columns. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ joinHorizontally()

template<class T , class C1 , class C2 >
TemporaryMatrix< T > joinHorizontally ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

Create new matrix by concatenating two matrices a and b horizontally, i.e. side by side. The two matrices must have the same number of rows. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ repeatMatrix() [1/2]

template<class T , class C1 , class C2 >
void repeatMatrix ( MultiArrayView< 2, T, C1 > const v,
MultiArrayView< 2, T, C2 > &  r,
unsigned int  verticalCount,
unsigned int  horizontalCount 
)

Initialize a matrix with repeated copies of a given matrix.

Matrix r will consist of verticalCount downward repetitions of v, and horizontalCount side-by-side repetitions. When v has size m by n, r must have size (m*verticalCount) by (n*horizontalCount).

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ repeatMatrix() [2/2]

template<class T , class C >
TemporaryMatrix< T > repeatMatrix ( MultiArrayView< 2, T, C > const v,
unsigned int  verticalCount,
unsigned int  horizontalCount 
)

Create a new matrix by repeating a given matrix.

The resulting matrix r will consist of verticalCount downward repetitions of v, and horizontalCount side-by-side repetitions, i.e. it will be of size (m*verticalCount) by (n*horizontalCount) when v has size m by n. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ add()

template<class T , class C1 , class C2 , class C3 >
void add ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 > &  r 
)

add matrices a and b. The result is written into r. All three matrices must have the same shape.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator+() [1/3]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > operator+ ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

add matrices a and b. The two matrices must have the same shape. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator+() [2/3]

template<class T , class C >
TemporaryMatrix< T > operator+ ( const MultiArrayView< 2, T, C > &  a,
b 
)

add scalar b to every element of the matrix a. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator+() [3/3]

template<class T , class C >
TemporaryMatrix< T > operator+ ( a,
const MultiArrayView< 2, T, C > &  b 
)

add scalar a to every element of the matrix b. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ sub()

template<class T , class C1 , class C2 , class C3 >
void sub ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 > &  r 
)

subtract matrix b from a. The result is written into r. All three matrices must have the same shape.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator-() [1/4]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > operator- ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

subtract matrix b from a. The two matrices must have the same shape. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator-() [2/4]

template<class T , class C >
TemporaryMatrix< T > operator- ( const MultiArrayView< 2, T, C > &  a)

negate matrix a. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator-() [3/4]

template<class T , class C >
TemporaryMatrix< T > operator- ( const MultiArrayView< 2, T, C > &  a,
b 
)

subtract scalar b from every element of the matrix a. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator-() [4/4]

template<class T , class C >
TemporaryMatrix< T > operator- ( a,
const MultiArrayView< 2, T, C > &  b 
)

subtract every element of the matrix b from scalar a. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ dot() [1/2]

template<class T , class C1 , class C2 >
NormTraits< T >::SquaredNormType dot ( const MultiArrayView< 2, T, C1 > &  x,
const MultiArrayView< 2, T, C2 > &  y 
)

calculate the inner product of two matrices representing vectors. Typically, matrix x has a single row, and matrix y has a single column, and the other dimensions match. In addition, this function handles the cases when either or both of the two inputs are transposed (e.g. it can compute the dot product of two column vectors). A PreconditionViolation exception is thrown when the shape conditions are violated.

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

◆ dot() [2/2]

template<class T , class C1 , class C2 >
NormTraits< T >::SquaredNormType dot ( const MultiArrayView< 1, T, C1 > &  x,
const MultiArrayView< 1, T, C2 > &  y 
)

calculate the inner product of two vectors. The vector lengths must match.

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

◆ cross() [1/3]

template<class T , class C1 , class C2 , class C3 >
void cross ( const MultiArrayView< 1, T, C1 > &  x,
const MultiArrayView< 1, T, C2 > &  y,
MultiArrayView< 1, T, C3 > &  r 
)

calculate the cross product of two vectors of length 3. The result is written into r.

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

◆ cross() [2/3]

template<class T , class C1 , class C2 , class C3 >
void cross ( const MultiArrayView< 2, T, C1 > &  x,
const MultiArrayView< 2, T, C2 > &  y,
MultiArrayView< 2, T, C3 > &  r 
)

calculate the cross product of two matrices representing vectors. That is, x, y, and r must have a single column of length 3. The result is written into r.

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

◆ cross() [3/3]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > cross ( const MultiArrayView< 2, T, C1 > &  x,
const MultiArrayView< 2, T, C2 > &  y 
)

calculate the cross product of two matrices representing vectors. That is, x, and y must have a single column of length 3. The result is returned as a temporary matrix.

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

◆ outer() [1/4]

template<class T , class C1 , class C2 , class C3 >
void outer ( const MultiArrayView< 2, T, C1 > &  x,
const MultiArrayView< 2, T, C2 > &  y,
MultiArrayView< 2, T, C3 > &  r 
)

calculate the outer product of two matrices representing vectors. That is, matrix x must have a single column, and matrix y must have a single row, and the other dimensions must match. The result is written into r.

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

◆ outer() [2/4]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > outer ( const MultiArrayView< 2, T, C1 > &  x,
const MultiArrayView< 2, T, C2 > &  y 
)

calculate the outer product of two matrices representing vectors. That is, matrix x must have a single column, and matrix y must have a single row, and the other dimensions must match. The result is returned as a temporary matrix.

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

◆ outer() [3/4]

template<class T , class C >
TemporaryMatrix< T > outer ( const MultiArrayView< 2, T, C > &  x)

calculate the outer product of a matrix (representing a vector) with itself. The result is returned as a temporary matrix.

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

◆ outer() [4/4]

template<class T , int N>
TemporaryMatrix< T > outer ( const TinyVector< T, N > &  x)

calculate the outer product of a TinyVector with itself. The result is returned as a temporary matrix.

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

◆ smul() [1/2]

template<class T , class C1 , class C2 >
void smul ( const MultiArrayView< 2, T, C1 > &  a,
b,
MultiArrayView< 2, T, C2 > &  r 
)

multiply matrix a with scalar b. The result is written into r. a and r must have the same shape.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ smul() [2/2]

template<class T , class C2 , class C3 >
void smul ( a,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 > &  r 
)

multiply scalar a with matrix b. The result is written into r. b and r must have the same shape.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ mmul() [1/2]

template<class T , class C1 , class C2 , class C3 >
void mmul ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 > &  r 
)

perform matrix multiplication of matrices a and b. The result is written into r. The three matrices must have matching shapes.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ mmul() [2/2]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > mmul ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

perform matrix multiplication of matrices a and b. a and b must have matching shapes. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ pmul() [1/2]

template<class T , class C1 , class C2 , class C3 >
void pmul ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 > &  r 
)

multiply two matrices a and b pointwise. The result is written into r. All three matrices must have the same shape.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ pmul() [2/2]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > pmul ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

multiply matrices a and b pointwise. a and b must have matching shapes. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator*() [1/6]

template<class T , class C , class U >
TemporaryMatrix< T > operator* ( const MultiArrayView< 2, T, C > &  a,
PointWise< U b 
)

multiply matrices a and b pointwise. a and b must have matching shapes. The result is returned as a temporary matrix.

Usage:

Matrix<double> a(m,n), b(m,n);
Matrix<double> c = a * pointWise(b);
// is equivalent to
// Matrix<double> c = pmul(a, b);

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator*() [2/6]

template<class T , class C >
TemporaryMatrix< T > operator* ( const MultiArrayView< 2, T, C > &  a,
b 
)

multiply matrix a with scalar b. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator*() [3/6]

template<class T , class C >
TemporaryMatrix< T > operator* ( a,
const MultiArrayView< 2, T, C > &  b 
)

multiply scalar a with matrix b. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator*() [4/6]

template<class T , class A , int N, class DATA , class DERIVED >
TinyVector< T, N > operator* ( const Matrix< T, A > &  a,
const TinyVectorBase< T, N, DATA, DERIVED > &  b 
)

multiply matrix a with TinyVector b. a must be of size N x N. Vector b and the result vector are interpreted as column vectors.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator*() [5/6]

template<class T , int N, class DATA , class DERIVED , class A >
TinyVector< T, N > operator* ( const TinyVectorBase< T, N, DATA, DERIVED > &  a,
const Matrix< T, A > &  b 
)

multiply TinyVector a with matrix b. b must be of size N x N. Vector a and the result vector are interpreted as row vectors.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator*() [6/6]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > operator* ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

perform matrix multiplication of matrices a and b. a and b must have matching shapes. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ sdiv()

template<class T , class C1 , class C2 >
void sdiv ( const MultiArrayView< 2, T, C1 > &  a,
b,
MultiArrayView< 2, T, C2 > &  r 
)

divide matrix a by scalar b. The result is written into r. a and r must have the same shape.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ pdiv() [1/2]

template<class T , class C1 , class C2 , class C3 >
void pdiv ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b,
MultiArrayView< 2, T, C3 > &  r 
)

divide two matrices a and b pointwise. The result is written into r. All three matrices must have the same shape.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ pdiv() [2/2]

template<class T , class C1 , class C2 >
TemporaryMatrix< T > pdiv ( const MultiArrayView< 2, T, C1 > &  a,
const MultiArrayView< 2, T, C2 > &  b 
)

divide matrices a and b pointwise. a and b must have matching shapes. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator/() [1/3]

template<class T , class C , class U >
TemporaryMatrix< T > operator/ ( const MultiArrayView< 2, T, C > &  a,
PointWise< U b 
)

divide matrices a and b pointwise. a and b must have matching shapes. The result is returned as a temporary matrix.

Usage:

Matrix<double> a(m,n), b(m,n);
Matrix<double> c = a / pointWise(b);
// is equivalent to
// Matrix<double> c = pdiv(a, b);

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator/() [2/3]

template<class T , class C >
TemporaryMatrix< T > operator/ ( const MultiArrayView< 2, T, C > &  a,
b 
)

divide matrix a by scalar b. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ operator/() [3/3]

template<class T , class C >
TemporaryMatrix< T > operator/ ( a,
const MultiArrayView< 2, T, C > &  b 
)

Create a matrix whose elements are the quotients between scalar a and matrix b. The result is returned as a temporary matrix.

#include <vigra/matrix.hxx> or
#include <vigra/linear_algebra.hxx>
Namespace: vigra::linalg

◆ argMin()

template<class T , class C >
int argMin ( MultiArrayView< 2, T, C > const a)

Find the index of the minimum element in a matrix.

The function returns the index in column-major scan-order sense, i.e. according to the order used by MultiArrayView::operator[]. If the matrix is actually a vector, this is just the row or columns index. In case of a truly 2-dimensional matrix, the index can be converted to an index pair by calling MultiArrayView::scanOrderIndexToCoordinate()

Required Interface:

bool f = a[0] < NumericTraits<T>::max();

#include <vigra/matrix.hxx>
Namespace: vigra

◆ argMax()

template<class T , class C >
int argMax ( MultiArrayView< 2, T, C > const a)

Find the index of the maximum element in a matrix.

The function returns the index in column-major scan-order sense, i.e. according to the order used by MultiArrayView::operator[]. If the matrix is actually a vector, this is just the row or columns index. In case of a truly 2-dimensional matrix, the index can be converted to an index pair by calling MultiArrayView::scanOrderIndexToCoordinate()

Required Interface:

bool f = NumericTraits<T>::min() < a[0];

#include <vigra/matrix.hxx>
Namespace: vigra

◆ argMinIf()

template<class T , class C , class UnaryFunctor >
int argMinIf ( MultiArrayView< 2, T, C > const a,
UnaryFunctor  condition 
)

Find the index of the minimum element in a matrix subject to a condition.

The function returns -1 if no element conforms to condition. Otherwise, the index of the maximum element is returned in column-major scan-order sense, i.e. according to the order used by MultiArrayView::operator[]. If the matrix is actually a vector, this is just the row or columns index. In case of a truly 2-dimensional matrix, the index can be converted to an index pair by calling MultiArrayView::scanOrderIndexToCoordinate()

Required Interface:

bool c = condition(a[0]);
bool f = a[0] < NumericTraits<T>::max();

#include <vigra/matrix.hxx>
Namespace: vigra

◆ argMaxIf()

template<class T , class C , class UnaryFunctor >
int argMaxIf ( MultiArrayView< 2, T, C > const a,
UnaryFunctor  condition 
)

Find the index of the maximum element in a matrix subject to a condition.

The function returns -1 if no element conforms to condition. Otherwise, the index of the maximum element is returned in column-major scan-order sense, i.e. according to the order used by MultiArrayView::operator[]. If the matrix is actually a vector, this is just the row or columns index. In case of a truly 2-dimensional matrix, the index can be converted to an index pair by calling MultiArrayView::scanOrderIndexToCoordinate()

Required Interface:

bool c = condition(a[0]);
bool f = NumericTraits<T>::min() < a[0];

#include <vigra/matrix.hxx>
Namespace: vigra

◆ pow()

template<class T , class C >
linalg::TemporaryMatrix< T > pow ( MultiArrayView< 2, T, C > const v,
exponent 
)

Matrix point-wise power.

◆ sqrt()

template<class T , class C >
linalg::TemporaryMatrix< T > sqrt ( MultiArrayView< 2, T, C > const v)

Matrix point-wise sqrt.

◆ exp()

template<class T , class C >
linalg::TemporaryMatrix< T > exp ( MultiArrayView< 2, T, C > const v)

Matrix point-wise exp.

◆ log()

template<class T , class C >
linalg::TemporaryMatrix< T > log ( MultiArrayView< 2, T, C > const v)

Matrix point-wise log.

◆ log10()

template<class T , class C >
linalg::TemporaryMatrix< T > log10 ( MultiArrayView< 2, T, C > const v)

Matrix point-wise log10.

◆ sin()

template<class T , class C >
linalg::TemporaryMatrix< T > sin ( MultiArrayView< 2, T, C > const v)

Matrix point-wise sin.

◆ asin()

template<class T , class C >
linalg::TemporaryMatrix< T > asin ( MultiArrayView< 2, T, C > const v)

Matrix point-wise asin.

◆ cos()

template<class T , class C >
linalg::TemporaryMatrix< T > cos ( MultiArrayView< 2, T, C > const v)

Matrix point-wise cos.

◆ acos()

template<class T , class C >
linalg::TemporaryMatrix< T > acos ( MultiArrayView< 2, T, C > const v)

Matrix point-wise acos.

◆ tan()

template<class T , class C >
linalg::TemporaryMatrix< T > tan ( MultiArrayView< 2, T, C > const v)

Matrix point-wise tan.

◆ atan()

template<class T , class C >
linalg::TemporaryMatrix< T > atan ( MultiArrayView< 2, T, C > const v)

Matrix point-wise atan.

◆ round()

template<class T , class C >
linalg::TemporaryMatrix< T > round ( MultiArrayView< 2, T, C > const v)

Matrix point-wise round.

◆ floor()

template<class T , class C >
linalg::TemporaryMatrix< T > floor ( MultiArrayView< 2, T, C > const v)

Matrix point-wise floor.

◆ ceil()

template<class T , class C >
linalg::TemporaryMatrix< T > ceil ( MultiArrayView< 2, T, C > const v)

Matrix point-wise ceil.

◆ abs()

template<class T , class C >
linalg::TemporaryMatrix< T > abs ( MultiArrayView< 2, T, C > const v)

Matrix point-wise abs.

◆ sq()

template<class T , class C >
linalg::TemporaryMatrix< T > sq ( MultiArrayView< 2, T, C > const v)

Matrix point-wise square.

◆ sign()

template<class T , class C >
linalg::TemporaryMatrix< T > sign ( MultiArrayView< 2, T, C > const v)

Matrix point-wise sign.

◆ columnStatistics()

template<... >
void columnStatistics (   ...)

Compute statistics of every column of matrix A.

The result matrices must be row vectors with as many columns as A.

Declarations:

compute only the mean:

namespace vigra { namespace linalg {
template <class T1, class C1, class T2, class C2>
void
} }
void columnStatistics(...)

compute mean and standard deviation:

namespace vigra { namespace linalg {
template <class T1, class C1, class T2, class C2, class T3, class C3>
void
} }

compute mean, standard deviation, and norm:

namespace vigra { namespace linalg {
template <class T1, class C1, class T2, class C2, class T3, class C3, class T4, class C4>
void
} }

Usage:

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

◆ rowStatistics()

template<... >
void rowStatistics (   ...)

Compute statistics of every row of matrix A.

The result matrices must be column vectors with as many rows as A.

Declarations:

compute only the mean:

namespace vigra { namespace linalg {
template <class T1, class C1, class T2, class C2>
void
} }
void rowStatistics(...)

compute mean and standard deviation:

namespace vigra { namespace linalg {
template <class T1, class C1, class T2, class C2, class T3, class C3>
void
} }

compute mean, standard deviation, and norm:

namespace vigra { namespace linalg {
template <class T1, class C1, class T2, class C2, class T3, class C3, class T4, class C4>
void
} }

Usage:

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

◆ covarianceMatrixOfColumns() [1/2]

template<class T1 , class C1 , class T2 , class C2 >
void covarianceMatrixOfColumns ( MultiArrayView< 2, T1, C1 > const features,
MultiArrayView< 2, T2, C2 > &  covariance 
)

Compute the covariance matrix between the columns of a matrix features.

The result matrix covariance must by a square matrix with as many rows and columns as the number of columns in matrix features.

#include <vigra/matrix.hxx>
Namespace: vigra

◆ covarianceMatrixOfColumns() [2/2]

template<class T , class C >
TemporaryMatrix< T > covarianceMatrixOfColumns ( MultiArrayView< 2, T, C > const features)

Compute the covariance matrix between the columns of a matrix features.

The result is returned as a square temporary matrix with as many rows and columns as the number of columns in matrix features.

#include <vigra/matrix.hxx>
Namespace: vigra

◆ covarianceMatrixOfRows() [1/2]

template<class T1 , class C1 , class T2 , class C2 >
void covarianceMatrixOfRows ( MultiArrayView< 2, T1, C1 > const features,
MultiArrayView< 2, T2, C2 > &  covariance 
)

Compute the covariance matrix between the rows of a matrix features.

The result matrix covariance must by a square matrix with as many rows and columns as the number of rows in matrix features.

#include <vigra/matrix.hxx>
Namespace: vigra

◆ covarianceMatrixOfRows() [2/2]

template<class T , class C >
TemporaryMatrix< T > covarianceMatrixOfRows ( MultiArrayView< 2, T, C > const features)

Compute the covariance matrix between the rows of a matrix features.

The result is returned as a square temporary matrix with as many rows and columns as the number of rows in matrix features.

#include <vigra/matrix.hxx>
Namespace: vigra

◆ prepareColumns()

template<... >
void prepareColumns (   ...)

Standardize the columns of a matrix according to given DataPreparationGoals.

For every column of the matrix A, this function computes mean, standard deviation, and norm. It then applies a linear transformation to the values of the column according to these statistics and the given DataPreparationGoals. The result is returned in matrix res which must have the same size as A. Optionally, the transformation applied can also be returned in the matrices offset and scaling (see below for an example how these matrices can be used to standardize more data according to the same transformation).

The following DataPreparationGoals are supported:

ZeroMean
Subtract the column mean form every column if the values in the column are not constant. Do nothing in a constant column.
UnitSum
Scale the columns so that the their sum is one if the sum was initially non-zero. Do nothing in a zero-sum column.
UnitVariance
Divide by the column standard deviation if the values in the column are not constant. Do nothing in a constant column.
UnitNorm
Divide by the column norm if it is non-zero.
ZeroMean | UnitVariance
First subtract the mean and then divide by the standard deviation, unless the column is constant (in which case the column remains unchanged).
ZeroMean | UnitNorm
If the column is non-constant, subtract the mean. Then divide by the norm of the result if the norm is non-zero.

Declarations:

Standardize the matrix and return the parameters of the linear transformation. The matrices offset and scaling must be row vectors with as many columns as A.

namespace vigra { namespace linalg {
template <class T, class C1, class C2, class C3, class C4>
void
DataPreparationGoals goals = ZeroMean | UnitVariance);
} }
void prepareColumns(...)
Standardize the columns of a matrix according to given DataPreparationGoals.

Only standardize the matrix.

namespace vigra { namespace linalg {
template <class T, class C1, class C2>
void
DataPreparationGoals goals = ZeroMean | UnitVariance);
} }

Usage:

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

.. // fill A
prepareColumns(A, standardizedA, offset, scaling, ZeroMean | UnitNorm);
// use offset and scaling to prepare additional data according to the same transformation
void repeatMatrix(MultiArrayView< 2, T, C1 > const &v, MultiArrayView< 2, T, C2 > &r, unsigned int verticalCount, unsigned int horizontalCount)
Definition matrix.hxx:1063

◆ prepareRows()

template<... >
void prepareRows (   ...)

Standardize the rows of a matrix according to given DataPreparationGoals.

This algorithm works in the same way as prepareColumns() (see there for detailed documentation), but is applied to the rows of the matrix A instead. Accordingly, the matrices holding the parameters of the linear transformation must be column vectors with as many rows as A.

Declarations:

Standardize the matrix and return the parameters of the linear transformation. The matrices offset and scaling must be column vectors with as many rows as A.

namespace vigra { namespace linalg {
template <class T, class C1, class C2, class C3, class C4>
void
DataPreparationGoals goals = ZeroMean | UnitVariance);
} }
void prepareRows(...)
Standardize the rows of a matrix according to given DataPreparationGoals.

Only standardize the matrix.

namespace vigra { namespace linalg {
template <class T, class C1, class C2>
void
DataPreparationGoals goals = ZeroMean | UnitVariance);
} }

Usage:

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

.. // fill A
prepareRows(A, standardizedA, offset, scaling, ZeroMean | UnitNorm);
// use offset and scaling to prepare additional data according to the same transformation

◆ leastSquares()

template<class T , class C1 , class C2 , class C3 >
bool leastSquares ( MultiArrayView< 2, T, C1 > const A,
MultiArrayView< 2, T, C2 > const b,
MultiArrayView< 2, T, C3 > &  x,
std::string  method = "QR" 
)

Ordinary Least Squares Regression.

Given a matrix A with m rows and n columns (with m >= n), and a column vector b of length m rows, this function computes the column vector x of length n rows that solves the optimization problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
     \left|\left|\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right|\right|_2^2
 \]

When b is a matrix with k columns, x must also have k columns, which will contain the solutions for the corresponding columns of b. Note that all matrices must already have the correct shape.

This function is just another name for linearSolve(), perhaps leading to more readable code when A is a rectangular matrix. It returns false when the rank of A is less than n. See linearSolve() for more documentation.

#include <vigra/regression.hxx>
Namespaces: vigra and vigra::linalg

◆ weightedLeastSquares()

template<class T , class C1 , class C2 , class C3 , class C4 >
bool weightedLeastSquares ( MultiArrayView< 2, T, C1 > const A,
MultiArrayView< 2, T, C2 > const b,
MultiArrayView< 2, T, C3 > const weights,
MultiArrayView< 2, T, C4 > &  x,
std::string  method = "QR" 
)

Weighted Least Squares Regression.

Given a matrix A with m rows and n columns (with m >= n), a vector b of length m, and a weight vector weights of length m with non-negative entries, this function computes the vector x of length n that solves the optimization problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
     \left(\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right)^T
      \textrm{diag}(\textrm{\bf weights})
      \left(\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right)
 \]

where diag(weights) creates a diagonal matrix from weights. The algorithm calls leastSquares() on the equivalent problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
      \left|\left|\textrm{diag}(\textrm{\bf weights})^{1/2}\textrm{\bf A} \textrm{\bf x} -
           \textrm{diag}(\textrm{\bf weights})^{1/2} \textrm{\bf b}\right|\right|_2^2
 \]

where the square root of weights is just taken element-wise.

When b is a matrix with k columns, x must also have k columns, which will contain the solutions for the corresponding columns of b. Note that all matrices must already have the correct shape.

The function returns false when the rank of the weighted matrix A is less than n.

#include <vigra/regression.hxx>
Namespaces: vigra and vigra::linalg

◆ ridgeRegression()

template<class T , class C1 , class C2 , class C3 >
bool ridgeRegression ( MultiArrayView< 2, T, C1 > const A,
MultiArrayView< 2, T, C2 > const b,
MultiArrayView< 2, T, C3 > &  x,
double  lambda 
)

Ridge Regression.

Given a matrix A with m rows and n columns (with m >= n), a vector b of length m, and a regularization parameter lambda >= 0.0, this function computes the vector x of length n that solves the optimization problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
     \left|\left|\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right|\right|_2^2 +
     \lambda \textrm{\bf x}^T\textrm{\bf x}
 \]

This is implemented by means of singularValueDecomposition().

When b is a matrix with k columns, x must also have k columns, which will contain the solutions for the corresponding columns of b. Note that all matrices must already have the correct shape.

The function returns false if the rank of A is less than n and lambda == 0.0.

#include <vigra/regression.hxx>
Namespaces: vigra and vigra::linalg

◆ weightedRidgeRegression()

template<class T , class C1 , class C2 , class C3 , class C4 >
bool weightedRidgeRegression ( MultiArrayView< 2, T, C1 > const A,
MultiArrayView< 2, T, C2 > const b,
MultiArrayView< 2, T, C3 > const weights,
MultiArrayView< 2, T, C4 > &  x,
double  lambda 
)

Weighted ridge Regression.

Given a matrix A with m rows and n columns (with m >= n), a vector b of length m, a weight vector weights of length m with non-negative entries, and a regularization parameter lambda >= 0.0 this function computes the vector x of length n that solves the optimization problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
     \left(\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right)^T
      \textrm{diag}(\textrm{\bf weights})
      \left(\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right) +
      \lambda \textrm{\bf x}^T\textrm{\bf x}
 \]

where diag(weights) creates a diagonal matrix from weights. The algorithm calls ridgeRegression() on the equivalent problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
     \left|\left|\textrm{diag}(\textrm{\bf weights})^{1/2}\textrm{\bf A} \textrm{\bf x} -
           \textrm{diag}(\textrm{\bf weights})^{1/2} \textrm{\bf b}\right|\right|_2^2 +
      \lambda \textrm{\bf x}^T\textrm{\bf x}
 \]

where the square root of weights is just taken element-wise. This solution is computed by means of singularValueDecomposition().

When b is a matrix with k columns, x must also have k columns, which will contain the solutions for the corresponding columns of b. Note that all matrices must already have the correct shape.

The function returns false if the rank of A is less than n and lambda == 0.0.

#include <vigra/regression.hxx>
Namespaces: vigra and vigra::linalg

◆ ridgeRegressionSeries()

template<class T , class C1 , class C2 , class C3 , class Array >
bool ridgeRegressionSeries ( MultiArrayView< 2, T, C1 > const A,
MultiArrayView< 2, T, C2 > const b,
MultiArrayView< 2, T, C3 > &  x,
Array const lambda 
)

Ridge Regression with many lambdas.

This executes ridgeRegression() for a sequence of regularization parameters. This is implemented so that the singularValueDecomposition() has to be executed only once. lambda must be an array conforming to the std::vector interface, i.e. must support lambda.size() and lambda[k]. The columns of the matrix x will contain the solutions for the corresponding lambda, so the number of columns of the matrix x must be equal to lambda.size(), and b must be a columns vector, i.e. cannot contain several right hand sides at once.

The function returns false when the matrix A is rank deficient. If this happens, and one of the lambdas is zero, the corresponding column of x will be skipped.

#include <vigra/regression.hxx>
Namespaces: vigra and vigra::linalg

◆ leastAngleRegression()

template<... >
unsigned int leastAngleRegression (   ...)

Least Angle Regression.

#include <vigra/regression.hxx>
Namespaces: vigra and vigra::linalg

Declarations:

namespace vigra {
namespace linalg {
// compute either LASSO or least squares solutions
template <class T, class C1, class C2, class Array1, class Array2>
unsigned int
// compute LASSO and least squares solutions
template <class T, class C1, class C2, class Array1, class Array2>
unsigned int
}
using linalg::leastAngleRegression;
}
Pass options to leastAngleRegression().
Definition regression.hxx:345
unsigned int leastAngleRegression(...)

This function implements Least Angle Regression (LARS) as described in

        B.Efron, T.Hastie, I.Johnstone, and R.Tibshirani: "Least Angle Regression", Annals of Statistics 32(2):407-499, 2004.

It is an efficient algorithm to solve the L1-regularized least squares (LASSO) problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
         \left|\left|\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right|\right|_2^2
       \textrm{ subject to } \left|\left|\textrm{\bf x}\right|\right|_1\le s
    \]

and the L1-regularized non-negative least squares (NN-LASSO) problem

\[ \tilde \textrm{\bf x} = \textrm{argmin} \left|\left|\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right|\right|_2^2
       \textrm{ subject to } \left|\left|\textrm{\bf x}\right|\right|_1\le s \textrm{ and } \textrm{\bf x}\ge \textrm{\bf 0}
    \]

where A is a matrix with m rows and n columns (often with m < n), b a vector of length m, and a regularization parameter s >= 0.0. L1-regularization has the desirable effect that it causes the solution x to be sparse, i.e. only the most important elements in x (called the active set) have non-zero values. The key insight of the LARS algorithm is the following: When the solution vector x is considered as a function of the regularization parameter s, then x(s) is a piecewise linear function, i.e. a polyline in n-dimensional space. The knots of the polyline x(s) are located precisely at those values of s where one variable enters or leaves the active set and can be efficiently computed.

Therefore, leastAngleRegression() returns the entire solution path as a sequence of knot points, starting at $\textrm{\bf x}(s=0)$ (where the only feasible solution is obviously x = 0) and ending at $\textrm{\bf x}(s=\infty)$ (where the solution becomes the ordinary least squares solution). Actually, the initial null solution is not explicitly returned, i.e. the sequence starts at the first non-zero solution with one variable in the active set. The function leastAngleRegression() returns the number of solutions (i.e. knot points) computed.

The sequences of active sets and corresponding variable weights are returned in activeSets and solutions respectively. That is, activeSets[i] is an ArrayVector<int> containing the indices of the variables that are active at the i-th knot, and solutions is a Matrix<T> containing the weights of those variables, in the same order (see example below). Variables not contained in activeSets[i] are zero at this solution.

The behavior of the algorithm can be adapted by LeastAngleRegressionOptions:

options.lasso() (active by default)
Compute the LASSO solution as described above.
options.nnlasso() (inactive by default)
Compute non-negative LASSO solutions, i.e. use the additional constraint that x >= 0 in all solutions.
options.lars() (inactive by default)
Compute a solution path according to the plain LARS rule, i.e. never remove a variable from the active set once it entered.
options.leastSquaresSolutions(bool) (default: true)
Use the algorithm mode selected above to determine the sequence of active sets, but then compute and return an ordinary (unconstrained) least squares solution for every active set.
Note: The second form of leastAngleRegression() ignores this option and does always compute both constrained and unconstrained solutions (returned in lasso_solutions and lsq_solutions respectively).
maxSolutionCount(unsigned int n) (default: n = 0, i.e. compute all solutions)
Compute at most n solutions.

Usage:

int m = ..., n = ...;
Matrix<double> A(m, n), b(m, 1);
... // fill A and b
// normalize the input
prepareColumns(A, A, offset, scaling, DataPreparationGoals(ZeroMean|UnitVariance));
prepareColumns(b, b, DataPreparationGoals(ZeroMean));
// arrays to hold the output
// run leastAngleRegression() in non-negative LASSO mode
// print results
for (MultiArrayIndex k = 0; k < numSolutions; ++k)
{
// transform the sparse solution into a dense vector
denseSolution.init(0.0); // ensure that inactive variables are zero
for (unsigned int i = 0; i < activeSets[k].size(); ++i)
{
// set the values of the active variables;
// activeSets[k][i] is the true index of the i-th variable in the active set
}
// invert the input normalization
// output the solution
std::cout << "solution " << k << ":\n" << denseSolution << std::endl;
}
void init(Iterator i, Iterator end)
Definition tinyvector.hxx:708
size_type size() const
Definition tinyvector.hxx:913
std::ptrdiff_t MultiArrayIndex
Definition multi_fwd.hxx:60

Required Interface:

  • T must be numeric type (compatible to double)
  • Array1 a1;
    a1.push_back(ArrayVector<int>());
  • Array2 a2;
    a2.push_back(Matrix<T>());

◆ nonnegativeLeastSquares()

template<... >
unsigned int nonnegativeLeastSquares (   ...)

Non-negative Least Squares Regression.

Given a matrix A with m rows and n columns (with m >= n), and a column vector b of length m rows, this function computes a column vector x of length n with non-negative entries that solves the optimization problem

\[ \tilde \textrm{\bf x} = \textrm{argmin}
     \left|\left|\textrm{\bf A} \textrm{\bf x} - \textrm{\bf b}\right|\right|_2^2
     \textrm{ subject to } \textrm{\bf x} \ge \textrm{\bf 0}
 \]

Both b and x must be column vectors (i.e. matrices with 1 column). Note that all matrices must already have the correct shape. The solution is computed by means of leastAngleRegression() with non-negativity constraint.

#include <vigra/regression.hxx>
Namespaces: vigra and vigra::linalg

Declarations:

namespace vigra {
namespace linalg {
template <class T, class C1, class C2, class C3>
void
}
using linalg::nonnegativeLeastSquares;
}
unsigned int nonnegativeLeastSquares(...)

© 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.12.2