Some operations for matrices. More...
#include <cstdio>#include <cstdlib>#include <cmath>#include <SharkDefs.h>#include <Array/ArrayOp.h>#include <LinAlg/LinAlg.h>Go to the source code of this file.
Functions | |
| 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". | |
| void | meanvar (const Array< double > &x, Array< double > &m, Array< double > &v) |
| 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, const int endA) |
| Calculates the mean and variance values of 1d-arrays p(x). | |
| 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". | |
| 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". | |
| void | matMat (Array2D< double > &A, const Array2D< double > &B, const Array2D< double > &C) |
Computes A = BC , where B and C are an and a matrix, respectively. | |
| void | matColVec (Array< double > &A, const Array2D< double > &B, const Array< double > &C) |
Computes A = BC , where B is an matrix and the -dimensional Array C is viewed as a column vector. | |
| void | matColVec (ArrayReference< double > A, const Array2D< double > &B, const ArrayReference< double > C) |
Computes A = BC , where B is an matrix and the -dimensional Array C is viewed as a column vector. | |
| void | matColVec (Array< double > &A, const Array2D< double > &B, const Array< double > &C, unsigned int index) |
Computes , where is a column of the matrix C. | |
| double | vecMatVec (const Array< double > &A, const Array2D< double > &B, const Array< double > &C) |
Computes s = ABC , where A and C are vectors of length and B is an matrix. | |
| double | vecMatVec (const Array< double > &A, unsigned int i, const Array2D< double > &B, const Array< double > &C, unsigned int j) |
Computes s = , where and are vectors of length and , and is an matrix. | |
| void | invertSymm (Array2D< double > &I, const Array2D< double > &A) |
| Computes I = A^T for a square symmetric matrix A. | |
| void | CholeskyDecomposition (const Array2D< double > &M, Array2D< double > &C) |
| lower triangular Cholesky decomposition | |
Some operations for matrices.
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.cpp.
| 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 |
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 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".
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 |
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 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".
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 |
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 408 of file LinAlg.cpp.
| Array< double > covariance | ( | const Array< double > & | 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 |
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 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 |
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 542 of file LinAlg.cpp.
Referenced by corrcoef().
| void invertSymm | ( | Array2D< double > & | I, | |
| const Array2D< double > & | A | |||
| ) |
Computes I = A^T for a square symmetric matrix A.
Inverts a symmetric matrix.
Definition at line 824 of file LinAlg.cpp.
References eigensymm(), and transpose().
Referenced by g_inverseCholesky(), and Matrix::inverseSymm().
| void matColVec | ( | Array< double > & | A, | |
| const Array2D< double > & | B, | |||
| const Array< double > & | C, | |||
| unsigned int | index | |||
| ) |
Computes
, 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 | |||
| ) |
Computes A = BC , where B is an
matrix and the
-dimensional Array 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 | |||
| ) |
Computes A = BC , where B is an
matrix and the
-dimensional Array 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 | |||
| ) |
Computes A = BC , where B and C are an
and a
matrix, respectively.
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 |
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 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, | |||
| const int | endA | |||
| ) |
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 |
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 271 of file LinAlg.cpp.
| 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 |
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 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 | |||
| ) |
Computes s =
, where
and
are vectors of length
and
, and
is an
matrix.
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 | |||
| ) |
Computes s = ABC , where A and C are vectors of length
and B is an
matrix.
Returns the scalar ABC.
Definition at line 755 of file LinAlg.cpp.