LinAlg.h File Reference

Some operations for matrices. More...

#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 >
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 $ A = B C_i $ , where $ C_i $ 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 $ A_i B C_j $.
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 $ A $ using Cholesky decomposition assuming that $ A^T A $ has full rank.


Detailed Description

Some operations for matrices.

Author:
M. Kreutz
Date:
1995-01-01
Copyright (c) 1999-2001:
Institut für Neuroinformatik
Ruhr-Universität Bochum
D-44780 Bochum, Germany
Phone: +49-234-32-25558
Fax: +49-234-32-14209
eMail: Shark-admin@neuroinformatik.ruhr-uni-bochum.de
www: http://www.neuroinformatik.ruhr-uni-bochum.de

Project:
LinAlg
This file is part of LinAlg. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

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.


Function Documentation

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:

\[ angle = \frac{\sum_{i=1}^{N} (x_i * y_i)}{\sum_{i=1}^{N} x_i * \sum_{i=1}^{N} y_i} \]

Parameters:
x one-dimensional vector no. 1
y one-dimensional vector no. 2
Returns:
the angle between x and y
Exceptions:
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
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg. <
Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable

Definition at line 216 of file LinAlg.cpp.

void CholeskyDecomposition ( const Array2D< double > &  M,
Array2D< double > &  C 
)

lower triangular Cholesky decomposition

Given an $ m \times m $ symmetric positive definite matrix $M$, compute the lower triangular matrix $C$ such that $ M=CC^T $

Parameters:
M $ m \times m $ matrix, which must be symmetric and positive definite
C $ m \times m $ matrix, which stores the Cholesky factor
Returns:
none
Author:
T. Suttorp and C. Igel
Date:
2008
Status
stable

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 $X = (x_{ij})$ of $n$ vectors with length $N$, the function calculates the coefficient of correlation matrix given as

$ r := (r_{kl}) \mbox{,\ } r_{kl} = \frac{c_{kl}}{\Delta x_k \Delta x_l}\mbox{,\ } k,l = 1, \dots, N $

where $c_{kl}$ is the entry of the covariance matrix of $x$ and $y$ (see covariance(const Array<double>& x)) and $\Delta x_k$ and $\Delta x_l$ are the standard deviations of $x_k$ and $x_l$ respectively.

Parameters:
x The $n \times N$ input matrix.
Returns:
The $N \times N$ coefficient of correlation matrix.
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that x is only one- or non-dimensional
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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 $x$ and $y$ of length $n$, the function calculates the coefficient of correlation given as

$ r := \frac{cov(x, y)}{\Delta x \Delta y} $

where $cov(x, y)$ is the covariance between the two vectors (see also covariance(const Array< double >&, const Array< double >&)) and $\Delta x$ and $\Delta y$ are the standard deviations of $x$ and $y$ respectively.
The coefficient of correlation is used to show the dependence between $x$ and $y$. It always holds $-1 \leq r \leq 1$ and the greater the value of $r^2$ is, the greater is the dependence between $x$ and $y$.

Parameters:
x first data vector.
y second data vector.
Returns:
the coefficient of correlation.
Exceptions:
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
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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 $X = (x_{ij})$ of $n$ vectors with length $N$, the function calculates the covariance matrix given as

$ Cov = (c_{kl}) \mbox{,\ } c_{kl} = \frac{1}{n - 1} \sum_{i=1}^n (x_{ik} - \overline{x_k})(x_{il} - \overline{x_l})\mbox{,\ } k,l = 1, \dots, N $

where $\overline{x_j} = \frac{1}{n} \sum_{i = 1}^n x_{ij}$ is the mean value of $x_j \mbox{,\ }j = 1, \dots, N$.

Parameters:
x The $n \times N$ input matrix.
Returns:
$N \times N$ matrix of covariance values.
Exceptions:
SharkException the type of the exception will be "type mismatch" and indicates that x is not 2-dimensional
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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 $x$ and $y$ with length $n$, interpreted as $n$ points $(x_i, y_i)$ with $i = 1, \dots, n$, the function calculates the covariance given as

$ cov = \frac{1}{n - 1} \sum_{i = 1}^n (x_i - \overline{x}) (y_i - \overline{y}) $

where $\overline{x}$ and $\overline{y}$ are the mean values of $x$ and $y$ respectively.

Parameters:
x first data vector.
y second data vector.
Returns:
the covariance matrix.
Exceptions:
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
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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 $ x_j $ that first will be calculated. The determinate is then given as:

$ \prod_{j=1}^n x_j $

Parameters:
amatA $ n \times n $ 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 $ n \times n $ 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.
Returns:
The determinate of matrix amatA.
Exceptions:
SharkException the type of the eception will be "size mismatch" and indicates that amatA is not a square matrix
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
2003/10/02 by S. Wiegand due to name change of 'eigensymm';
Status
stable

Definition at line 94 of file detsymm.cpp.

References eigensymm_intermediate().

Referenced by Matrix::detSymm().

template<class T >
Array< T > diagonal ( const Array< T > &  v  )  [inline]

Examples:
linalg_simple_test.cpp.

Definition at line 406 of file LinAlg.h.

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 $ n \times n $ matrix A, this function calculates the eigenvalues $ \lambda $ defined as (x is the corresponding but not calculated eigenvector)

$ Ax = \lambda x $

where x is a one-column matrix and the matrix multiplication is used for A and x.

Parameters:
amatA $ n \times n $ matrix.
vr real parts of eigenvalues
vi imaginary parts of eigenvalues
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that amatA is not a square matrix
Changes
previously 'eigensymm', renamed by S. Wiegand 2003/10/01
Status
stable

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 $ n \times n $ 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 $ n \times n $ matrix A, a matrix x of eigenvectors and a vector $ \lambda $ of corresponding eigenvalues, the relative error of eigenvalue no. c is calculated as

$ \sqrt{\sum_{i=0}^n \left(\sum_{j=0}^n A(i,j) \ast x(j,c) - x(i,c) \ast \lambda(c) \right)^2} $

Parameters:
amatA $ n \times n $ matrix, which has to be symmetric, so only the lower triangular matrix must contain values. The matrix is not changed by the function.
vmatA $ n \times n $ matrix with normalized eigenvectors, each column contains an eigenvector.
dvecA n-dimensional vector with eigenvalues in descending order.
c No. of the considered eigenvalue.
Returns:
the relative error.
Exceptions:
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
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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:

$ \begin{array}{*{3}{r}} v_{11} & v_{21} & v_{31}\\ v_{12} & v_{22} & v_{32}\\ v_{13} & v_{23} & v_{33}\\ & & \\ v_1 & v_2 & v_3\\ \end{array} $

then eigenvalue $ v_1 $ has the corresponding eigenvector $ ( v_{11}\ v_{12}\ v_{13} ) $ and $ v_1 > v_2 > v_3 $.

Parameters:
vmatA $ n \times n $ 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.
Returns:
none.
Exceptions:
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
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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.

Parameters:
A $ n \times n $ matrix, which must be symmetric, so only the bottom triangular matrix must contain values.
G $ n \times n $ matrix with the calculated normalized eigenvectors, each column will contain one eigenvector.
l n-dimensional vector with the calculated eigenvalues in descending order.
Returns:
none.
Exceptions:
SharkException 
Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable
Calculates the eigenvalues and the normalized eigenvectors of a symmetric matrix "amatA" using the Givens and Householder reduction without corrupting "amatA" during application. Given a symmetric $ n \times n $ matrix A, this function calculates the eigenvalues $ \lambda $ and the eigenvectors x, defined as

$ Ax = \lambda x $

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.

Parameters:
amatA $ n \times n $ matrix, which must be symmetric, so only the bottom triangular matrix must contain values.
vmatA $ n \times n $ 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.
Returns:
none.
Exceptions:
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.
Author:
M. Kreutz
Date:
1998
Changes
2003/09/19 18:55:22 S. Wiegand lower triangular part of 'amatA' will not corrupted anymore
Status
stable

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.

Parameters:
A $ n \times n $ 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 $ n \times n $ matrix, that is used to store intermediate results (other methods like detsymm use these for further calculations)
G $ n \times n $ matrix with the calculated normalized eigenvectors, each column will contain one eigenvector.
l n-dimensional vector with the calculated eigenvalues in descending order.
Returns:
none.
Exceptions:
SharkException 
Author:
M. Kreutz
Date:
1998
Changes
previously 'eigensymm', renamed by S. Wiegand 2003/10/01
Status
stable
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. Each time this frontend is called additional memory is allocated for intermediate results. Frontend for function eigensymm(const Array2D<double> &amatA,Array2D<double> &vmatA,Array<double> &dvecA,Array<double> &odvecA), when memory for 'odvecA' should be allocated by the call of this frontend.

Parameters:
A $ n \times n $ matrix, which must be symmetric, so only the bottom triangular matrix must contain values.
G $ n \times n $ matrix with the calculated normalized eigenvectors, each column will contain one eigenvector.
l n-dimensional vector with the calculated eigenvalues in descending order.
Returns:
none.
Exceptions:
SharkException 
Author:
S. Wiegand
Date:
2003
Changes
none
Status
stable

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 $ n \times n $ matrix A, this function calculates the eigenvalues $ \lambda $ and the eigenvectors x, defined as

$ Ax = \lambda x $

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.

Parameters:
amatA $ n \times n $ 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 $ n \times n $ matrix, that is used to store intermediate results (other methods like detsymm use these for further calculations)
vmatA $ n \times n $ matrix with the calculated normalized eigenvectors, each column will contain an eigenvector.
dvecA n-dimensional vector with the calculated eigenvalues in descending order.
Returns:
none.
Exceptions:
SharkException 
Author:
M. Kreutz
Date:
1998
Changes
previously 'eigensymm', renamed by S. Wiegand 2003/10/01
Status
stable

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 $ n \times n $ matrix A, this function calculates the eigenvalues $ \lambda $ and the eigenvectors x, defined as

$ Ax = \lambda x $

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

$ P_{pq} = \left( \begin{array}{*{7}{c}} 1 \\ & \dots \\ & & c & \dots & s \\ & & \vdots & 1 & \vdots \\ & & -s & \dots & c \\ & & & & & \dots \\ & & & & & & 1 \\ \end{array} \right) $

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 $ \Phi $, so $ c^2 + s^2 = 1$. 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.

Parameters:
amatA $ n \times n $ matrix, which must be symmetric, so only the upper triangular matrix must contain values. Values above the diagonal will be destroyed.
vmatA $ n \times n $ matrix with the calculated normalized eigenvectors, each column will contain an eigenvector.
dvecA n-dimensional vector with the calculated eigenvalues in descending order.
Returns:
none.
Exceptions:
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.
Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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 $ n \times n $ matrix A, this function calculates the eigenvalues $ \lambda $ and the eigenvectors x, defined as

$ Ax = \lambda x $

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.

Parameters:
amatA $ n \times n $ matrix, which must be symmetric, so only the bottom triangular matrix must contain values. Values below the diagonal will be destroyed.
vmatA $ n \times n $ matrix with the calculated normalized eigenvectors, each column will contain one eigenvector.
dvecA n-dimensional vector with the calculated eigenvalues in descending order.
Returns:
none.
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that amatA is not a square matrix
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable

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 $ X $ this function uses singular value decomposition to determine the generalized inverse matrix $ X' $, so that

$ XX'X = X $

If $ X $ is singular, i.e. $ det(X) = 0 $ or $ X $ is non-square then $ X' $ is not unique.

Parameters:
amatA $ m \times n $ input matrix.
bmatA $ n \times m $ 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.
Returns:
none.
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable
See also:
svd.cpp

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.

Parameters:
A The input matrix.
Returns:
The generalized inverse matrix.
Exceptions:
check_exception the type of the exception will be "size mismatch" and indicates that A is not a square matrix
Author:
T. Suttorp
Date:
2008
Changes
none
Status
stable

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 $ A $ using Cholesky decomposition assuming that $ A^T A $ has full rank.

Returns the generalized inverse matrix of input matrix $ A $ using Cholesky decomposition assuming that $ A^T A $ has full rank.

Parameters:
A The input matrix.
Returns:
The generalized inverse matrix.
Exceptions:
check_exception the type of the exception will be "size mismatch" and indicates that A is not a square matrix
Author:
T. Suttorp
Date:
2008
Changes
none
Status
stable

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.

Parameters:
A The input matrix.
Returns:
The generalized inverse matrix.
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that A is not a square matrix
Author:
M. Kreutz
Date:
1998
Changes
none
Status
stable
See also:
g_inverse.cpp, svd.cpp

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.

Author:
C. Igel
Date:
2007
Changes
none

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 $ x_j $ that first will be calculated. The determinate is then given as:

$ \prod_{j=1}^n x_j $

Parameters:
amatA $ n \times n $ 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 $ n \times n $ 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.
Returns:
The logarithm of the determinate of matrix amatA.
Exceptions:
SharkException the type of the eception will be "size mismatch" and indicates that amatA is not a square matrix
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
C.Igel
Date:
2007
Status
stable

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 $ A = B C_i $ , where $ C_i $ is a column of the matrix C.

Returns $ A = B C_i $ , where $ C_i $ is a column of the matrix C.

Author:
T. Glasmachers
Date:
2007
Changes
none

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.

Author:
T. Glasmachers
Date:
2008

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.

Author:
C. Igel
Date:
2007

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.

Author:
C. Igel
Date:
2007
Changes
none

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:

\[ mean_j = \frac{1}{N1} \sum_{i=1}^{N1} x_{i,j} \]

Example:

\[ \left( \begin{array}{*{4}{c}} 1 & 2 & 3 & 4\\ 5 & 6 & 7 & 8\\ 9 & 10 & 11 & 12\\ \end{array} \right) \longrightarrow \frac{1}{3} \left( \begin{array}{*{4}{c}} 1+5+9 & 2+6+10 & 3+7+11 & 4+8+12\\ \end{array} \right) \longrightarrow \left( \begin{array}{*{4}{c}} 5 & 6 & 7 & 8\\ \end{array} \right) \]

Parameters:
x multidimensional array, from which the mean value will be calculated
Returns:
the mean vector of x
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that x is only one-dimensional or has no dimensions
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable

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.

Parameters:
x The input matrix.
m Vector of mean values.
v Vector of variances.
Returns:
none.
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that x is only one- or non-dimensional
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable
See also:
mean, variance

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 $ n \times n $ 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).

Parameters:
amatA $ n \times n $ matrix, which is symmetric and is not changed by the function.
vmatA $ n \times n $ 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.
Returns:
The rank of matrix amatA.
Exceptions:
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
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable

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 $ x_j $ is scaled by multiplying it with the scalar value $ \frac{1}{\sqrt{\lambda_j}} $.

Parameters:
amatA $ n \times n $ 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 $ n \times n $ matrix, which will contain the scaled eigenvectors.
dvecA n-dimensional vector with the calculated eigenvalues in descending order.
Returns:
The rank of matrix amatA.
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that amatA is not a square matrix
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1998
Changes
2003/10/02 by S. Wiegand due to name change of 'eigensymm';
Status
stable

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".

Determines the singular value decomposition of a rectangular matrix "amatA".
See also: Wikipedia
Given a $ m \times n $ matrix amatA, this routine computes its singular value decomposition, defined as

$ A = UWV^T $

where W is an $ n \times n $ 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.

$ UU^T = VV^T = V^TV = 1 $

Parameters:
amatA The input matrix A, with size $ m \times n $ and $ m \geq n $.
umatA The $ m \times n $ column-orthogonal matrix U determined by the function.
vmatA The $ n \times n $ 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.
Exceptions:
convergence exception, if the solution has not converged after maxIterations iterations.
Returns:
none
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable

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

$ A = UWV^T $

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.

Parameters:
amatA The $ m \times n $ input matrix A, with $ m \geq n $.
umatA The $ m \times n $ column-orthogonal matrix U.
vmatA The $ n \times n $ orthogonal matrix V.
wvecA n-dimensional vector containing the singular values in descending order.
Returns:
none.
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable
See also:
svd.cpp

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

$ A = UWV^T $

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.

Parameters:
umatA The $ m \times n $ matrix U.
vmatA The $ n \times n $ matrix V.
wvecA n-dimensional vector containing the singular values.
Returns:
none.
Exceptions:
SharkException the type of the exception will be "size mismatch" and indicates that wvecA is not one-dimensional
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable
See also:
svd.cpp

Definition at line 91 of file svdsort.cpp.

Referenced by g_inverse().

template<class T >
T trace ( const Array< T > &  v  )  [inline]

Examples:
linalg_simple_test.cpp.

Definition at line 458 of file LinAlg.h.

template<class T >
Array< T > transpose ( const Array< T > &  v  )  [inline]

Examples:
linalg_simple_test.cpp.

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:

\[ variance = \frac{1}{N1} \sum_{i=1}^{N1} (x_i - m_i)^2 \]

Parameters:
x multidimensional array, from which the variance will be calculated
Returns:
the variance vector of x
Exceptions:
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
Please follow the link to view the source code of the example. The example can be executed in the example directory of package LinAlg.

Author:
M. Kreutz
Date:
1995
Changes
none
Status
stable

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 $ A_i B C_j $.

Returns the scalar $ A_i B C_j $.

Author:
C. Igel
Date:
2007
Changes
none

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.

Author:
C. Igel
Date:
2007
Changes
none

Definition at line 755 of file LinAlg.cpp.