#include "Array/Array2D.h"
Go to the source code of this file.
Functions | |
| void | eigensort (Array2D< double > &vmatA, Array< double > &dvecA) |
| Sorts the eigenvalues in vector "dvecA" in descending order and the corresponding eigenvectors in matrix "vmatA". | |
| void | eigensymmJacobi (Array2D< double > &amatA, Array2D< double > &vmatA, Array< double > &dvecA) |
| Calculates the eigenvalues and the normalized eigenvectors of the symmetric matrix "amatA" using the Jacobi method. | |
| void | eigensymmJacobi2 (Array2D< double > &amatA, Array2D< double > &vmatA, Array< double > &dvecA) |
| Calculates the eigenvalues and the normalized eigenvectors of the symmetric matrix "amatA" using a modified Jacobi method. | |
| void | eigensymm_intermediate (const Array2D< double > &amatA, Array2D< double > &hmatA, Array2D< double > &vmatA, Array< double > &dvecA) |
| Calculates the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction, however, "hmatA" contains intermediate results after application. | |
| void | eigensymm (const Array2D< double > &amatA, Array2D< double > &vmatA, Array< double > &dvecA) |
| Used as frontend for eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA,Array<double> &odvecA) for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "amatA" during application. | |
| void | eigensymm (const Array< double > &A, Array< double > &G, Array< double > &l) |
| Used as another frontend for eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA) for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "A" during application. | |
| void | eigensymm (const Array2D< double > &amatA, Array2D< double > &vmatA, Array< double > &dvecA, Array< double > &odvecA) |
| Calculates the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction. | |
| void | eigensymm (const Array< double > &A, Array< double > &G, Array< double > &l, Array< double > &od) |
| Used as frontend for eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA,Array<double> &odvecA) for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "A" during application. | |
| void | eigen (Array< double > A, Array< double > &vr, Array< double > &vi) |
| Calculates the eigenvalues of an arbitrary matrix "amatA" by balancing the elements of the matrix, then reducing it to an upper Hessenberg matrix and finally calculating the eigenvalues ot the reduced form. | |
| void | CholeskyDecomposition (const Array2D< double > &M, Array2D< double > &C) |
| lower triangular Cholesky decomposition | |
| double | eigenerr (const Array2D< double > &amatA, const Array2D< double > &vmatA, const Array< double > &dvecA, unsigned c) |
| Calculates the relative error of eigenvalue no. "c". | |
| unsigned | rank (const Array2D< double > &amatA, const Array2D< double > &vmatA, const Array< double > &dvecA) |
| Determines the rank of the symmetric matrix "amatA". | |
| double | detsymm (Array2D< double > &amatA, Array2D< double > &vmatA, Array< double > &dvecA) |
| Calculates the determinant of the symmetric matrix "amatA". | |
| double | logdetsymm (Array2D< double > &amatA, Array2D< double > &vmatA, Array< double > &dvecA) |
| Calculates the log of the determinant of the symmetric matrix "amatA". | |
| unsigned | rankDecomp (Array2D< double > &amatA, Array2D< double > &hmatA, Array2D< double > &vmatA, Array< double > &dvecA) |
| Calculates the rank of the symmetric matrix "amatA", its eigenvalues and eigenvectors. | |
| void | discrimAnalysis (Array2D< double > &betweenCovarA, Array2D< double > &withinCovarA, Array2D< double > &transMatA, Array< double > &dvecA, unsigned &m) |
| Given "m" classes of data, the covariances between the values within one class and the covariances between all the classes, this method calculates the transformation matrix that will project the data in a way, that maximum separation of the different classes is given. | |
| void | linearRegress (Array2D< double > &cxxMatA, Array2D< double > &cxyMatA, Array< double > &mxVecA, Array< double > &myVecA, Array2D< double > &amatA, Array< double > &bvecA, Array< double > &dvecA) |
| Given the correlations of the n-dimensional data vector "x" and the m-dimensional data vector "y" and also given their mean values, this function summarizes the data by finding a linear mapping that will approximate the data. | |
| unsigned | svdrank (const Array2D< double > &amatA, Array2D< double > &umatA, Array2D< double > &vmatA, Array< double > &wvecA) |
| Determines the numerical rank of a rectangular matrix "amatA", when a singular value decomposition for "amatA" has taken place before. | |
| void | svd (const Array2D< double > &amatA, Array2D< double > &umatA, Array2D< double > &vmatA, Array< double > &wvecA, unsigned maxIterations=200, bool ignoreThreshold=true) |
| Determines the singular value decomposition of a rectangular matrix "amatA". | |
| void | svdsort (Array2D< double > &umatA, Array2D< double > &vmatA, Array< double > &wvecA) |
| Sorts the singular values in vector "wvecA" by descending order. | |
| template<class T > | |
| Array< T > | transpose (const Array< T > &v) |
| template<class T > | |
| Array< T > | diagonal (const Array< T > &v) |
| template<class T > | |
| T | trace (const Array< T > &v) |
| Array< double > | mean (const Array< double > &x) |
| Calculates the mean vector of array "x". | |
| Array< double > | variance (const Array< double > &x) |
| Calculates the variance vector of array "x". | |
| double | angle (const Array< double > &x, const Array< double > &y) |
| Calculates the angle between the vectors "x" and "y". | |
| double | corrcoef (const Array< double > &x, const Array< double > &y) |
| Calculates the coefficient of correlation of the data vectors "x" and "y". | |
| Array< double > | corrcoef (const Array< double > &x) |
| Calculates the coefficient of correlation matrix of the data vectors stored in matrix "x". | |
| void | meanvar (const Array< double > &x, Array< double > &, Array< double > &) |
| Calculates the mean and variance values of matrix "x". | |
| void | meanvar (const Array< double > &pxA, const Array< double > &xA, double &mA, double &vA, const int startA=-1, const int endA=-1) |
| Calculates the mean and variance values of 1d-arrays p(x). | |
| double | covariance (const Array< double > &x, const Array< double > &y) |
| Calculates the covariance between the data vectors "x" and "y". | |
| Array< double > | covariance (const Array< double > &x) |
| Calculates the covariance matrix of the data vectors stored in matrix "x". | |
| Array< double > | invert (const Array< double > &) |
| Returns the generalized inverse matrix of input matrix "A" by using singular value decomposition. | |
| void | matMat (Array2D< double > &A, const Array2D< double > &B, const Array2D< double > &C) |
| Multiplies two 2D matrices. | |
| void | matColVec (Array< double > &A, const Array2D< double > &B, const Array< double > &C) |
| Returns A = BC, where C is viewed as a column vector. | |
| void | matColVec (ArrayReference< double > A, const Array2D< double > &B, const ArrayReference< double > C) |
| Returns A = BC, where C is viewed as a column vector. | |
| void | matColVec (Array< double > &A, const Array2D< double > &B, const Array< double > &C, unsigned int index) |
Returns , where is a column of the matrix C. | |
| double | vecMatVec (const Array< double > &A, const Array2D< double > &B, const Array< double > &C) |
| Returns the scalar ABC. | |
| double | vecMatVec (const Array< double > &A, unsigned int i, const Array2D< double > &B, const Array< double > &C, unsigned int j) |
Returns the scalar . | |
| void | invertSymm (Array2D< double > &I, const Array2D< double > &A) |
| Inverts a symmetric matrix. | |
| void | invertSymmPositiveDefinite (Array2D< double > &I, const Array2D< double > &ArrSymm) |
| Inverts a symmetric positive definite matrix. | |
| unsigned | g_inverse (const Array2D< double > &amatA, Array2D< double > &bmatA, unsigned maxIterations=200, double tolerance=1e-10, bool ignoreThreshold=true) |
| Calculates the generalized inverse matrix of input matrix "amatA". | |
| void | g_inverseCholesky (const Array2D< double > &A, Array2D< double > &outA, double thresholdFactor=1e-9) |
| Returns the generalized inverse matrix of input matrix using Cholesky decomposition. | |
| void | g_inverseMoorePenrose (const Array2D< double > &A, Array2D< double > &outA) |
Returns the generalized inverse matrix of input matrix using Cholesky decomposition assuming that has full rank. | |
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Definition in file LinAlg.h.
| double angle | ( | const Array< double > & | x, | |
| const Array< double > & | y | |||
| ) |
Calculates the angle between the vectors "x" and "y".
Given the two one-dimensional vectors "x" and "y" with the same no. N of elements, the function calculates:
| x | one-dimensional vector no. 1 | |
| y | one-dimensional vector no. 2 |
| SharkException | the type of the exception will be "size mismatch" and indicates that x is not one-dimensional or that x has not the same size than y |
Definition at line 216 of file LinAlg.cpp.
| void CholeskyDecomposition | ( | const Array2D< double > & | M, | |
| Array2D< double > & | C | |||
| ) |
lower triangular Cholesky decomposition
Given an
symmetric positive definite matrix
, compute the lower triangular matrix
such that 
| M | matrix, which must be symmetric and positive definite | |
| C | matrix, which stores the Cholesky factor |
Definition at line 868 of file LinAlg.cpp.
Referenced by invertSymmPositiveDefinite().
| Array< double > corrcoef | ( | const Array< double > & | x | ) |
Calculates the coefficient of correlation matrix of the data vectors stored in matrix "x".
Calculates the coefficient of correlation matrix of the data vectors stored in matrix "x".
Given a matrix
of
vectors with length
, the function calculates the coefficient of correlation matrix given as

where
is the entry of the covariance matrix of
and
(see covariance(const Array<double>& x)) and
and
are the standard deviations of
and
respectively.
| x | The input matrix. |
coefficient of correlation matrix. | SharkException | the type of the exception will be "size mismatch" and indicates that x is only one- or non-dimensional |
Definition at line 483 of file LinAlg.cpp.
References covariance().
| double corrcoef | ( | const Array< double > & | x, | |
| const Array< double > & | y | |||
| ) |
Calculates the coefficient of correlation of the data vectors "x" and "y".
Calculates the coefficient of correlation of the data vectors "x" and "y".
Given two data vectors
and
of length
, the function calculates the coefficient of correlation given as

where
is the covariance between the two vectors (see also covariance(const Array< double >&, const Array< double >&)) and
and
are the standard deviations of
and
respectively.
The coefficient of correlation is used to show the dependence between
and
. It always holds
and the greater the value of
is, the greater is the dependence between
and
.
| x | first data vector. | |
| y | second data vector. |
| SharkException | the type of the exception will be "size mismatch" and indicates that x is not one-dimensional or x has not the same size than y |
Definition at line 408 of file LinAlg.cpp.
| Array< double > covariance | ( | const Array< double > & | x | ) |
Calculates the covariance matrix of the data vectors stored in matrix "x".
Calculates the covariance matrix of the data vectors stored in matrix "x".
Given a matrix
of
vectors with length
, the function calculates the covariance matrix given as

where
is the mean value of
.
| x | The input matrix. |
matrix of covariance values. | SharkException | the type of the exception will be "type mismatch" and indicates that x is not 2-dimensional |
Definition at line 602 of file LinAlg.cpp.
References mean().
| double covariance | ( | const Array< double > & | x, | |
| const Array< double > & | y | |||
| ) |
Calculates the covariance between the data vectors "x" and "y".
Given two data vectors
and
with length
, interpreted as
points
with
, the function calculates the covariance given as

where
and
are the mean values of
and
respectively.
| x | first data vector. | |
| y | second data vector. |
| SharkException | the type of the exception will be "type mismatch" and indicates that x is not one-dimensional or x has not the same size than y |
Definition at line 542 of file LinAlg.cpp.
Referenced by corrcoef().
| double detsymm | ( | Array2D< double > & | amatA, | |
| Array2D< double > & | vmatA, | |||
| Array< double > & | dvecA | |||
| ) |
Calculates the determinant of the symmetric matrix "amatA".
Calculates the determinant of the symmetric matrix "amatA".
Calculates the determinate of matrix amatA by using its n eigenvalues
that first will be calculated. The determinate is then given as:

| amatA | matrix, which is symmetric, so only the bottom triangular matrix must contain values. At the end of the function amatA always contains the full matrix. | |
| vmatA | matrix, that will contain the scaled eigenvectors at the end of the function. | |
| dvecA | n-dimensional vector that will contain the eigenvalues at the end of the function. |
| SharkException | the type of the eception will be "size mismatch" and indicates that amatA is not a square matrix |
Definition at line 94 of file detsymm.cpp.
References eigensymm_intermediate().
Referenced by Matrix::detSymm().
| Array< T > diagonal | ( | const Array< T > & | v | ) | [inline] |
| void discrimAnalysis | ( | Array2D< double > & | betweenCovarA, | |
| Array2D< double > & | withinCovarA, | |||
| Array2D< double > & | transMatA, | |||
| Array< double > & | dvecA, | |||
| unsigned & | m | |||
| ) |
Given "m" classes of data, the covariances between the values within one class and the covariances between all the classes, this method calculates the transformation matrix that will project the data in a way, that maximum separation of the different classes is given.
| void eigen | ( | Array< double > | amatA, | |
| Array< double > & | vr, | |||
| Array< double > & | vi | |||
| ) |
Calculates the eigenvalues of an arbitrary matrix "amatA" by balancing the elements of the matrix, then reducing it to an upper Hessenberg matrix and finally calculating the eigenvalues ot the reduced form.
Given a
matrix A, this function calculates the eigenvalues
defined as (x is the corresponding but not calculated eigenvector)

where x is a one-column matrix and the matrix multiplication is used for A and x.
| amatA | matrix. | |
| vr | real parts of eigenvalues | |
| vi | imaginary parts of eigenvalues |
| SharkException | the type of the exception will be "size mismatch" and indicates that amatA is not a square matrix |
Definition at line 576 of file eigen.cpp.
References Balanc(), and ElmHes().
Referenced by Matrix::eigenvalues().
| double eigenerr | ( | const Array2D< double > & | amatA, | |
| const Array2D< double > & | vmatA, | |||
| const Array< double > & | dvecA, | |||
| unsigned | c | |||
| ) |
Calculates the relative error of eigenvalue no. "c".
Calculates the relative error of eigenvalue no. "c".
Given a symmetric
matrix amatA, the matrix vmatA of its eigenvectors and the vector dvecA of the corresponding eigenvalues, this function calculates the relative error of one eigenvalue, denoted by the no. c. If we have a
matrix A, a matrix x of eigenvectors and a vector
of corresponding eigenvalues, the relative error of eigenvalue no. c is calculated as

| amatA | matrix, which has to be symmetric, so only the lower triangular matrix must contain values. The matrix is not changed by the function. | |
| vmatA | matrix with normalized eigenvectors, each column contains an eigenvector. | |
| dvecA | n-dimensional vector with eigenvalues in descending order. | |
| c | No. of the considered eigenvalue. |
| SharkException | the type of the exception will be "size mismatch" and indicates that dvecA is not one-dimensional or that amatA or vmatA don't have the same number of rows or columns as dvecA contains number of values |
Definition at line 94 of file eigenerr.cpp.
Referenced by rank().
| void eigensort | ( | Array2D< double > & | vmatA, | |
| Array< double > & | dvecA | |||
| ) |
Sorts the eigenvalues in vector "dvecA" in descending order and the corresponding eigenvectors in matrix "vmatA".
Sorts the eigenvalues in vector "dvecA" in descending order and the corresponding eigenvectors in matrix "vmatA".
Given the matrix vmatA of eigenvectors and the vector dvecA of corresponding eigenvalues, the values in dvecA will be sorted by descending order and the eigenvectors in vmatA will change their places in a way, that at the end of the function an eigenvalue at position j of vector dvecA will belong to the eigenvector at column j of matrix vmatA. If we've got for example the following result after calling the function:

then eigenvalue
has the corresponding eigenvector
and
.
| vmatA | matrix with eigenvectors (each column contains an eigenvector, corresponding to one eigenvalue). | |
| dvecA | n-dimensional vector with eigenvalues, will contain the eigenvalues in descending order when returning from the function. |
| SharkException | the type of the exception will be "size mismatch" and indicates that dvecA is not one-dimensional or that the number of rows or the number of columns in vmatA is different from the number of values in dvecA |
Definition at line 100 of file eigensort.cpp.
Referenced by eigensymm(), eigensymm_intermediate(), eigensymmJacobi(), and eigensymmJacobi2().
| void eigensymm | ( | const Array< double > & | A, | |
| Array< double > & | G, | |||
| Array< double > & | l, | |||
| Array< double > & | od | |||
| ) |
Used as frontend for eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA,Array<double> &odvecA) for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "A" during application.
| void eigensymm | ( | const Array2D< double > & | amatA, | |
| Array2D< double > & | vmatA, | |||
| Array< double > & | dvecA, | |||
| Array< double > & | odvecA | |||
| ) |
Calculates the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction.
This method works without corrupting "amatA" during application by demanding another Array 'odvecA' as an algorithmic buffer instead of using the last row of 'amatA' to store intermediate algorithmic results.
Calculates the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction.
Frontend for function eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA), when using type Array instead of type Array2D. Each time this frontend is called additional memory is allocated for intermediate results.
| A | matrix, which must be symmetric, so only the bottom triangular matrix must contain values. | |
| G | matrix with the calculated normalized eigenvectors, each column will contain one eigenvector. | |
| l | n-dimensional vector with the calculated eigenvalues in descending order. |
| SharkException |
matrix A, this function calculates the eigenvalues
and the eigenvectors x, defined as

where x is a one-column matrix and the matrix multiplication is used for A and x. Here, the Givens reduction as a modification of the Jacobi method (s.a. eigensymmJacobi) is used. Instead of trying to reduce the matrix all the way to diagonal form, we are content to stop when the matrix is tridiagonal. This allows the function to be carried out in a finite number of steps, unlike the Jacobi method, which requires iteration to convergence. So in comparison to the Jacobi method, this function is faster for matrices with an order greater than 10.
| amatA | matrix, which must be symmetric, so only the bottom triangular matrix must contain values. | |
| vmatA | matrix with the calculated normalized eigenvectors, each column will contain an eigenvector. | |
| dvecA | n-dimensional vector with the calculated eigenvalues in descending order. | |
| odvecA | n-dimensional vector with the calculated offdiagonal of the Householder transformation. |
| SharkException | Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg. |
Definition at line 556 of file eigensymm.cpp.
References eigensort().
| void eigensymm | ( | const Array< double > & | A, | |
| Array< double > & | G, | |||
| Array< double > & | l | |||
| ) |
Used as another frontend for eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA) for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "A" during application.
Each time this frontend is called additional memory is allocated for intermediate results.
| void eigensymm | ( | const Array2D< double > & | A, | |
| Array2D< double > & | G, | |||
| Array< double > & | l | |||
| ) |
Used as frontend for eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA,Array<double> &odvecA) for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "amatA" during application.
Each time this frontend is called additional memory is allocated for intermediate results.
Used as frontend for eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA,Array<double> &odvecA) for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "amatA" during application.
Frontend for function eigensymm_intermediate(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA), when using type Array instead of type Array2D.
| A | matrix, which must be symmetric, so only the bottom triangular matrix must contain values. Values below the diagonal will be destroyed.The method uses this matrix as a buffer for intermediate results. | |
| hmatA | matrix, that is used to store intermediate results (other methods like detsymm use these for further calculations) | |
| G | matrix with the calculated normalized eigenvectors, each column will contain one eigenvector. | |
| l | n-dimensional vector with the calculated eigenvalues in descending order. |
| SharkException |
| A | matrix, which must be symmetric, so only the bottom triangular matrix must contain values. | |
| G | matrix with the calculated normalized eigenvectors, each column will contain one eigenvector. | |
| l | n-dimensional vector with the calculated eigenvalues in descending order. |
| SharkException |
Definition at line 426 of file eigensymm.cpp.
References eigensymm().
Referenced by eigensymm(), and invertSymm().
| void eigensymm_intermediate | ( | const Array2D< double > & | amatA, | |
| Array2D< double > & | hmatA, | |||
| Array2D< double > & | vmatA, | |||
| Array< double > & | dvecA | |||
| ) |
Calculates the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction, however, "hmatA" contains intermediate results after application.
Calculates the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction, however, "hmatA" contains intermediate results after application.
Given a symmetric
matrix A, this function calculates the eigenvalues
and the eigenvectors x, defined as

where x is a one-column matrix and the matrix multiplication is used for A and x. Here, the Givens reduction as a modification of the Jacobi method (s.a. eigensymmJacobi) is used. Instead of trying to reduce the matrix all the way to diagonal form, we are content to stop when the matrix is tridiagonal. This allows the function to be carried out in a finite number of steps, unlike the Jacobi method, which requires iteration to convergence. So in comparison to the Jacobi method, this function is faster for matrices with an order greater than 10.
| amatA | matrix, which must be symmetric, so only the bottom triangular matrix must contain values. Values below the diagonal will be destroyed. The method uses this matrix as a buffer for intermediate results. | |
| hmatA | matrix, that is used to store intermediate results (other methods like detsymm use these for further calculations) | |
| vmatA | matrix with the calculated normalized eigenvectors, each column will contain an eigenvector. | |
| dvecA | n-dimensional vector with the calculated eigenvalues in descending order. |
| SharkException |
Definition at line 98 of file eigensymm.cpp.
References eigensort().
Referenced by detsymm(), logdetsymm(), and rankDecomp().
| void eigensymmJacobi | ( | Array2D< double > & | amatA, | |
| Array2D< double > & | vmatA, | |||
| Array< double > & | dvecA | |||
| ) |
Calculates the eigenvalues and the normalized eigenvectors of the symmetric matrix "amatA" using the Jacobi method.
Calculates the eigenvalues and the normalized eigenvectors of the symmetric matrix "amatA" using the Jacobi method.
Given a symmetric
matrix A, this function calculates the eigenvalues
and the eigenvectors x, defined as

where x is a one-column matrix and the matrix multiplication is used for A and x. For the calculation of the eigenvectors and eigenvalues the so called Jacobi rotation is used to annihilate one of the off-diagonal elements with the basic Jacobi rotation given as matrix of the form

In this matrix all the diagonal elements are unity except for the two elemnts c in rows (and columns) p and q. All off-diagonal elements are zero except the two elements s and - s. The numbers c and s are the cosine of a rotation angle
, so
. Successive rotations lead to the off-diagonal elements getting smaller and smaller, until the matrix is diagonal to machine precision. Accumulating the product of the transformations as you go gives the matrix of eigenvectors, while the elements of the final diagonal matrix are the eigenvalues. Use this function for the calculation of the eigenvalues and eigenvectors for matrices amatA with moderate order not greater than 10.
| amatA | matrix, which must be symmetric, so only the upper triangular matrix must contain values. Values above the diagonal will be destroyed. | |
| vmatA | matrix with the calculated normalized eigenvectors, each column will contain an eigenvector. | |
| dvecA | n-dimensional vector with the calculated eigenvalues in descending order. |
| SharkException | Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg. |
Definition at line 125 of file eigensymmJacobi.cpp.
References eigensort().
| void eigensymmJacobi2 | ( | Array2D< double > & | amatA, | |
| Array2D< double > & | vmatA, | |||
| Array< double > & | dvecA | |||
| ) |
Calculates the eigenvalues and the normalized eigenvectors of the symmetric matrix "amatA" using a modified Jacobi method.
Calculates the eigenvalues and the normalized eigenvectors of the symmetric matrix "amatA" using a modified Jacobi method.
Given a symmetric
matrix A, this function calculates the eigenvalues
and the eigenvectors x, defined as

where x is a one-column matrix and the matrix multiplication is used for A and x. This function uses the Jacobi method as in eigensymmJacobi, but the method is modificated after J. von Neumann to avoid convergence problems when dealing with low machine precision.
| amatA | matrix, which must be symmetric, so only the bottom triangular matrix must contain values. Values below the diagonal will be destroyed. | |
| vmatA | matrix with the calculated normalized eigenvectors, each column will contain one eigenvector. | |
| dvecA | n-dimensional vector with the calculated eigenvalues in descending order. |
| SharkException | the type of the exception will be "size mismatch" and indicates that amatA is not a square matrix |
Definition at line 98 of file eigensymmJacobi2.cpp.
References eigensort().
| unsigned g_inverse | ( | const Array2D< double > & | amatA, | |
| Array2D< double > & | bmatA, | |||
| unsigned | maxIterations, | |||
| double | tolerance, | |||
| bool | ignoreThreshold | |||
| ) |
Calculates the generalized inverse matrix of input matrix "amatA".
Given an input matrix
this function uses singular value decomposition to determine the generalized inverse matrix
, so that

If
is singular, i.e.
or
is non-square then
is not unique.
| amatA | input matrix. | |
| bmatA | generalized inverse matrix. | |
| maxIterations | Number of iterations after which the SVD calculation algorithm gives up, if the solution has still not converged. Default ist 200 Iterations. | |
| tolerance | singular values less than this value will be considered zero. Default is 1e-10. | |
| ignoreThreshold | If set to false, the method throws an exception if the threshold maxIterations is exceeded. Otherwise it uses the approximate intermediate results in the further calculations. The default is true. |
Definition at line 91 of file g_inverse.cpp.
References svd(), svdrank(), and svdsort().
Referenced by Matrix::inverse(), and invert().
| void g_inverseCholesky | ( | const Array2D< double > & | A, | |
| Array2D< double > & | outA, | |||
| double | thresholdFactor | |||
| ) |
Returns the generalized inverse matrix of input matrix using Cholesky decomposition.
Returns the generalized inverse matrix of input matrix using Cholesky decomposition.
| A | The input matrix. |
| check_exception | the type of the exception will be "size mismatch" and indicates that A is not a square matrix |
Definition at line 254 of file g_inverse.cpp.
References invertSymm(), invertSymmPositiveDefinite(), matMat(), and transpose().
Referenced by Matrix::inverseCholesky().
| void g_inverseMoorePenrose | ( | const Array2D< double > & | A, | |
| Array2D< double > & | outA | |||
| ) |
Returns the generalized inverse matrix of input matrix
using Cholesky decomposition assuming that
has full rank.
Returns the generalized inverse matrix of input matrix
using Cholesky decomposition assuming that
has full rank.
| A | The input matrix. |
| check_exception | the type of the exception will be "size mismatch" and indicates that A is not a square matrix |
Definition at line 364 of file g_inverse.cpp.
References invertSymmPositiveDefinite(), matMat(), and transpose().
Referenced by Matrix::inverseMoorePenrose().
| Array< double > invert | ( | const Array< double > & | A | ) |
Returns the generalized inverse matrix of input matrix "A" by using singular value decomposition.
Used as frontend for metod g_inverse when using type "Array" instead of "Array2D".
Returns the generalized inverse matrix of input matrix "A" by using singular value decomposition.
For a more exact description see documentation of method g_inverse. Here not only the usage of variable type "Array< double >" instead of "Array2D< double >" as storage for matrices is different, but also the resulting generalized inverse matrix is returned directly and not given back by assigning it to a second parameter.
| A | The input matrix. |
| SharkException | the type of the exception will be "size mismatch" and indicates that A is not a square matrix |
Definition at line 78 of file invert.cpp.
References g_inverse().
| void invertSymm | ( | Array2D< double > & | I, | |
| const Array2D< double > & | A | |||
| ) |
Inverts a symmetric matrix.
Inverts a symmetric matrix.
Definition at line 824 of file LinAlg.cpp.
References eigensymm(), and transpose().
Referenced by g_inverseCholesky(), and Matrix::inverseSymm().
| void invertSymmPositiveDefinite | ( | Array2D< double > & | I, | |
| const Array2D< double > & | ArrSymm | |||
| ) |
Inverts a symmetric positive definite matrix.
Definition at line 198 of file g_inverse.cpp.
References CholeskyDecomposition(), and matMat().
Referenced by g_inverseCholesky(), g_inverseMoorePenrose(), and Matrix::inverseSymmPositiveDefinite().
| void linearRegress | ( | Array2D< double > & | cxxMatA, | |
| Array2D< double > & | cxyMatA, | |||
| Array< double > & | mxVecA, | |||
| Array< double > & | myVecA, | |||
| Array2D< double > & | amatA, | |||
| Array< double > & | bvecA, | |||
| Array< double > & | dvecA | |||
| ) |
Given the correlations of the n-dimensional data vector "x" and the m-dimensional data vector "y" and also given their mean values, this function summarizes the data by finding a linear mapping that will approximate the data.
| double logdetsymm | ( | Array2D< double > & | amatA, | |
| Array2D< double > & | vmatA, | |||
| Array< double > & | dvecA | |||
| ) |
Calculates the log of the determinant of the symmetric matrix "amatA".
Calculates the log of the determinant of the symmetric matrix "amatA".
Calculates the logarithm of the determinate of matrix amatA by using its n eigenvalues
that first will be calculated. The determinate is then given as:

| amatA | matrix, which is symmetric, so only the bottom triangular matrix must contain values. At the end of the function amatA always contains the full matrix. | |
| vmatA | matrix, that will contain the scaled eigenvectors at the end of the function. | |
| dvecA | n-dimensional vector that will contain the eigenvalues at the end of the function. |
| SharkException | the type of the eception will be "size mismatch" and indicates that amatA is not a square matrix |
Definition at line 176 of file detsymm.cpp.
References eigensymm_intermediate().
Referenced by Matrix::logDetSymm().
| void matColVec | ( | Array< double > & | A, | |
| const Array2D< double > & | B, | |||
| const Array< double > & | C, | |||
| unsigned int | index | |||
| ) |
Returns
, where
is a column of the matrix C.
Returns
, where
is a column of the matrix C.
Definition at line 723 of file LinAlg.cpp.
| void matColVec | ( | ArrayReference< double > | A, | |
| const Array2D< double > & | B, | |||
| const ArrayReference< double > | C | |||
| ) |
Returns A = BC, where C is viewed as a column vector.
Returns A = BC, where C is viewed as a column vector.
Definition at line 692 of file LinAlg.cpp.
| void matColVec | ( | Array< double > & | A, | |
| const Array2D< double > & | B, | |||
| const Array< double > & | C | |||
| ) |
Returns A = BC, where C is viewed as a column vector.
Returns A = BC, where C is viewed as a column vector.
Definition at line 665 of file LinAlg.cpp.
| void matMat | ( | Array2D< double > & | A, | |
| const Array2D< double > & | B, | |||
| const Array2D< double > & | C | |||
| ) |
Multiplies two 2D matrices.
Multiplies two 2D matrices.
Definition at line 641 of file LinAlg.cpp.
Referenced by g_inverseCholesky(), g_inverseMoorePenrose(), and invertSymmPositiveDefinite().
| Array< double > mean | ( | const Array< double > & | x | ) |
Calculates the mean vector of array "x".
Given a d -dimensional array x with size N1 x ... x Nd, this function calculates the mean vector given as:
Example:
| x | multidimensional array, from which the mean value will be calculated |
| SharkException | the type of the exception will be "size mismatch" and indicates that x is only one-dimensional or has no dimensions |
Definition at line 103 of file LinAlg.cpp.
Referenced by covariance().
| void meanvar | ( | const Array< double > & | pxA, | |
| const Array< double > & | xA, | |||
| double & | mA, | |||
| double & | vA, | |||
| const int | startA = -1, |
|||
| const int | endA = -1 | |||
| ) |
Calculates the mean and variance values of 1d-arrays p(x).
Definition at line 322 of file LinAlg.cpp.
| void meanvar | ( | const Array< double > & | x, | |
| Array< double > & | m, | |||
| Array< double > & | v | |||
| ) |
Calculates the mean and variance values of matrix "x".
Given the input matrix x, the mean and variance values are calculated as in the functions mean and variance. The mean and variance values are stored in the vectors m and v.
| SharkException | the type of the exception will be "size mismatch" and indicates that x is only one- or non-dimensional |
Definition at line 271 of file LinAlg.cpp.
| unsigned rank | ( | const Array2D< double > & | amatA, | |
| const Array2D< double > & | vmatA, | |||
| const Array< double > & | dvecA | |||
| ) |
Determines the rank of the symmetric matrix "amatA".
Determines the rank of the symmetric matrix "amatA".
Given the
matrix amatA, this function uses the eigenvectors vmatA and the eigenvalues dvecA to calculate the rank of amatA. For the calculation of the eigenvectors and eigenvalues see also eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA).
| amatA | matrix, which is symmetric and is not changed by the function. | |
| vmatA | matrix with the normalized eigenvectors, each column contains one eigenvector. The matrix is not changed by the function. | |
| dvecA | n-dimensional vector of the eigenvalues, given in descending order. The vector is not changed by the function. |
| SharkException | the type of the exception will be "size mismatch" and indicates that dvecA is not one-dimensional or that amatA or vmatA has not the same number of rows or columns than dvecA contains values |
Definition at line 88 of file rank.cpp.
References eigenerr().
Referenced by rankDecomp().
| unsigned rankDecomp | ( | Array2D< double > & | amatA, | |
| Array2D< double > & | vmatA, | |||
| Array2D< double > & | hmatA, | |||
| Array< double > & | dvecA | |||
| ) |
Calculates the rank of the symmetric matrix "amatA", its eigenvalues and eigenvectors.
Calculates the rank of the symmetric matrix "amatA", its eigenvalues and eigenvectors.
Determines the rank of matrix amatA and additionally calculates the eigenvalues and eigenvectors of the matrix. Empty eigenvalues (i.e. eigenvalues equal to zero) are set to the greatest calculated eigenvalue and each eigenvector
is scaled by multiplying it with the scalar value
.
| amatA | matrix, which is symmetric, so only the bottom triangular matrix must contain values. At the end of the function amatA always contains the full matrix. | |
| vmatA | matrix, which will contain the scaled eigenvectors. | |
| dvecA | n-dimensional vector with the calculated eigenvalues in descending order. |
| SharkException | the type of the exception will be "size mismatch" and indicates that amatA is not a square matrix |
Definition at line 91 of file rankDecomp.cpp.
References eigensymm_intermediate(), and rank().
| void svd | ( | const Array2D< double > & | amatA, | |
| Array2D< double > & | umatA, | |||
| Array2D< double > & | vmatA, | |||
| Array< double > & | w, | |||
| unsigned | maxIterations, | |||
| bool | ignoreThreshold | |||
| ) |
Determines the singular value decomposition of a rectangular matrix "amatA".
matrix amatA, this routine computes its singular value decomposition, defined as

where W is an
diagonal matrix with positive or zero elements, the so-called singular values. The matrices U and V are each orthogonal in the sense that their columns are orthonormal, i.e.

| amatA | The input matrix A, with size and . | |
| umatA | The column-orthogonal matrix U determined by the function. | |
| vmatA | The orthogonal matrix V determined by the function. | |
| w | n-dimensional vector with the calculated singular values. | |
| maxIterations | Number of iterations after which the algorithm gives up, if the solution has still not converged. Default is 200 Iterations. | |
| ignoreThreshold | If set to false, the method throws an exception if the threshold maxIterations is exceeded. Otherwise it uses the approximate intermediate results in the further calculations. The default is true. |
| convergence | exception, if the solution has not converged after maxIterations iterations. |
Definition at line 110 of file svd.cpp.
References SIGN.
Referenced by g_inverse().
| unsigned svdrank | ( | const Array2D< double > & | amatA, | |
| Array2D< double > & | umatA, | |||
| Array2D< double > & | vmatA, | |||
| Array< double > & | wvecA | |||
| ) |
Determines the numerical rank of a rectangular matrix "amatA", when a singular value decomposition for "amatA" has taken place before.
Determines the numerical rank of a rectangular matrix "amatA", when a singular value decomposition for "amatA" has taken place before.
For a singular value decomposition defined as

the resulting orthogonal matrices U and V and the singular values in W sorted by descending order are used to determine the rank of input matrix A.
| amatA | The input matrix A, with . | |
| umatA | The column-orthogonal matrix U. | |
| vmatA | The orthogonal matrix V. | |
| wvecA | n-dimensional vector containing the singular values in descending order. |
Definition at line 96 of file svdrank.cpp.
Referenced by g_inverse().
| void svdsort | ( | Array2D< double > & | umatA, | |
| Array2D< double > & | vmatA, | |||
| Array< double > & | wvecA | |||
| ) |
Sorts the singular values in vector "wvecA" by descending order.
For a singular value decomposition defined as

the resulting orthogonal matrices U and V and the singular values in W can be sorted in a way, that the singular values are given in descending order, when leaving the function.
| umatA | The matrix U. | |
| vmatA | The matrix V. | |
| wvecA | n-dimensional vector containing the singular values. |
| SharkException | the type of the exception will be "size mismatch" and indicates that wvecA is not one-dimensional |
Definition at line 91 of file svdsort.cpp.
Referenced by g_inverse().
| T trace | ( | const Array< T > & | v | ) | [inline] |
| Array< T > transpose | ( | const Array< T > & | v | ) | [inline] |
Definition at line 341 of file LinAlg.h.
Referenced by g_inverseCholesky(), g_inverseMoorePenrose(), and invertSymm().
| Array< double > variance | ( | const Array< double > & | x | ) |
Calculates the variance vector of array "x".
Given a d -dimensional array x with size N1 x ... x Nd and mean value vector m, this function calculates the variance vector given as:
| x | multidimensional array, from which the variance will be calculated |
| SharkException | the type of the exception will be "size mismatch" and indicates that x is only one-dimensional or has no dimensions or has no values in its first dimension |
Definition at line 151 of file LinAlg.cpp.
| double vecMatVec | ( | const Array< double > & | A, | |
| unsigned int | i, | |||
| const Array2D< double > & | B, | |||
| const Array< double > & | C, | |||
| unsigned int | j | |||
| ) |
Returns the scalar
.
Returns the scalar
.
Definition at line 789 of file LinAlg.cpp.
| double vecMatVec | ( | const Array< double > & | A, | |
| const Array2D< double > & | B, | |||
| const Array< double > & | C | |||
| ) |
Returns the scalar ABC.
Returns the scalar ABC.
Definition at line 755 of file LinAlg.cpp.