Linear algebra utilities. More...
Functions | |
Vector * | AddExpert (double alpha, const Vector *const u, Vector *const v) |
Sets vector v to v + alpha * u (![]() | |
Matrix * | AddExpert (double alpha, const Matrix *const A, Matrix *const B) |
Sets matrix B to B + alpha * A (![]() | |
Vector * | AddTo (const Vector *const u, Vector *const v) |
Sets vector v to v + u (![]() | |
Matrix * | AddTo (const Matrix *const A, Matrix *const B) |
Sets matrix B to B + A (![]() | |
double | ArgMinus (double x, double arg) |
Returns ![]() | |
void | Center (Matrix X, Matrix *X_centered) |
Sets a matrix to a centered matrix, where centering is done by subtracting the sum over the columns (a column vector) from each column of the matrix. | |
Matrix * | ColVector (index_t n, double value, Matrix *col_vector) |
Inits a n-dimensional column vector and sets all entries to value. | |
Matrix * | DiagMatrixInit (index_t n, double value, Matrix *diag_matrix) |
Inits a n by n diagonal matrix and sets the diagonal entries to value. | |
Vector * | DiagToVector (const Matrix *const diag_matrix, Vector *diag_vector) |
Inits the components of a vector to the diagonal entries of a square matrix. | |
Vector * | DotMultiplyInit (const Vector *const u, const Vector *const v, Vector *w) |
Multiplies u and v entry-wise and Inits a vector to the result. | |
Matrix * | DotMultiplyInit (const Matrix *const A, const Matrix *const B, Matrix *C) |
Multiplies A and B entry-wise and Inits a matrix to the result. | |
Vector * | DotMultiplyOverwrite (const Vector *const u, Vector *const v) |
Multiplies u and v entry-wise and overwrites vector v with the result. | |
Matrix * | DotMultiplyOverwrite (const Matrix *const A, Matrix *const B) |
Multiplies A and B entry-wise and overwrites matrix B with the result. | |
Matrix * | DotMultiplySum (const Matrix *const A, const Matrix *const B, Matrix *sum_vector) |
Multiplies A and B (N by M matrices) entry-wise and Inits a 1 by N matrix to the sum over the transformed rows of the result (![]() ![]() | |
double | ExpArg (double x, double arg) |
Returns ![]() | |
double | Inv (double x, double arg) |
Returns ![]() | |
void | MakeSubMatrixByColumns (Vector column_indices, Matrix A, Matrix *A_sub) |
Inits a matrix to the columns of A specified in column_indices. | |
Vector * | MapInit (double(*function)(double, double), double arg, const Vector *const u, Vector *v) |
Inits a vector to the result of applying function with argument arg to a vector (![]() | |
Matrix * | MapInit (double(*function)(double, double), double arg, const Matrix *const A, Matrix *B) |
Inits a matrix to the result of applying function with argument arg to a matrix (![]() | |
Vector * | MapOverwrite (double(*function)(double, double), double arg, Vector *const v) |
Applies function with argument arg to vector v and overwrites v with the result (![]() | |
Matrix * | MapOverwrite (double(*function)(double, double), double arg, Matrix *A) |
Applies function with argument arg to matrix A and overwrites A with the result (![]() | |
Matrix * | MatrixMapSum (double(*function)(double, double), double arg, const Matrix *const A, Matrix *sum_vector) |
Applies function with argument arg to a M by N Matrix and Inits a 1 by N matrix to the sum over the transformed rows (![]() ![]() | |
double | MinusArg (double x, double arg) |
Returns ![]() | |
Vector * | MulInit (const Vector *const u, const Matrix *const A, Vector *const v) |
Inits a vector to u A or A' u (![]() ![]() | |
Vector * | MulInit (const Matrix *const A, const Vector *const u, Vector *const v) |
Inits a vector to A * u (![]() | |
Matrix * | MulInit (const Matrix *const A, const Matrix *const B, Matrix *const C) |
Inits a matrix to A * B (![]() | |
Matrix * | MulOverwrite (const Matrix *const A, const Matrix *const B, Matrix *const C) |
Overwrites a matrix with A * B (![]() | |
Matrix * | MulTransAInit (const Matrix *const A, const Matrix *const B, Matrix *C) |
Inits a matrix to A' * B (![]() | |
Matrix * | MulTransAOverwrite (const Matrix *const A, const Matrix *const B, Matrix *const C) |
Overwrites a matrix with A' * B (![]() | |
Matrix * | MulTransBInit (const Matrix *const A, const Matrix *const B, Matrix *C) |
Inits a matrix to A * B' (![]() | |
Matrix * | MulTransBOverwrite (const Matrix *const A, Matrix *const B, Matrix *const C) |
Overwrites a matrix with A * B' (![]() | |
void | Orthogonalize (const Matrix W_old, Matrix *W) |
Orthogonalize W and return the result in W, using Eigen Decomposition. | |
double | Plus (double x, double arg) |
Returns ![]() | |
void | RandMatrix (index_t n_rows, index_t n_cols, Matrix *A) |
Inits a matrix to uniform random entries in [0,1]. | |
Matrix * | RandNormalInit (index_t d, index_t n, Matrix *A) |
Inits a matrix to random normally distributed entries from N(0,1). | |
void | RandVector (Vector &v) |
Overwrites a dimension-N vector to a random vector on the unit sphere in R^N. | |
Matrix * | RepeatMatrix (index_t num_row_reps, index_t num_col_reps, Matrix base_matrix, Matrix *new_matrix) |
Inits a matrix to a num_row_reps by num_col_reps block matrix where each block is base_matrix. | |
void | SaveCorrectly (const char *filename, Matrix a) |
Save the matrix to a file so that rows in the matrix correspond to rows in the file: This just means call data::Save() on the transpose of the matrix. | |
Vector * | Scale (double alpha, Vector *v) |
Sets v to alpha * v (![]() | |
Matrix * | Scale (double alpha, Matrix *A) |
Sets A to alpha * A (![]() | |
Vector * | ScaleInit (double alpha, const Vector *const u, Vector *v) |
Inits a vector to alpha * u (![]() | |
Matrix * | ScaleInit (double alpha, const Matrix *const A, Matrix *B) |
Inits a matrix to alpha * A (![]() | |
double | Square (double x, double arg) |
Returns ![]() | |
double | SquareArg (double x, double arg) |
Returns ![]() | |
Vector * | SubFrom (const Vector *const u, Vector *const v) |
Sets vector v to v - u (![]() | |
Matrix * | SubFrom (const Matrix *const A, Matrix *const B) |
Sets matrix B to B - A (![]() | |
Vector * | SubInit (const Vector *const u, const Vector *const v, Vector *w) |
Inits a vector to u - v (![]() | |
Matrix * | SubInit (const Matrix *const A, const Matrix *const B, Matrix *C) |
Inits a matrix to A - B (![]() | |
Matrix * | SubOverwrite (const Matrix *const A, const Matrix *const B, Matrix *const C) |
Overwrites a matrix with A - B (![]() | |
double | Sum (Vector *v) |
Returns the sum of the components of vector v (returns ![]() | |
Matrix * | Sum (const Matrix *const A, Matrix *sum_vector) |
Sums over the rows of a M by N matrix and Inits a 1 by N matrix storing the sum (sum_vector ![]() | |
double | TanhArg (double x, double arg) |
Returns ![]() | |
double | Times (double x, double arg) |
Returns ![]() | |
double | VectorMapSum (double(*function)(double, double), double arg, const Vector *const v) |
Applies function with argument arg to vector v and returns the sum of the transformed components (sum ![]() | |
Matrix * | VectorToDiag (const Vector *const diag_vector, Matrix *diag_matrix) |
Inits the diagonal entries of a N by N diagonal matrix to the entries of a N-dimensional vector. | |
Matrix * | VectorToDiag (const Matrix *const diag_vector, Matrix *diag_matrix) |
Inits the diagonal entries of a N by N diagonal matrix to the entries of a 1 by N matrix. | |
void | WhitenUsingEig (Matrix X, Matrix *X_whitened, Matrix *whitening_matrix) |
Whitens a matrix using the eigen decomposition of the covariance matrix. | |
void | WhitenUsingSVD (Matrix X, Matrix *X_whitened, Matrix *whitening_matrix) |
Whitens a matrix using the singular value decomposition of the covariance matrix. |
Linear algebra utilities.
This includes, among other things, Map, Sum, Addition, Subtraction, Multiplication, Hadamard product (entry-wise multiplication), Whitening, Random vectors on the unit sphere, Random uniform matrices, Random normal matrices, creating a Submatrix that is a slice of selected columns of a matrix, Block matrix construction from a base matrix Note that the __private is temporary until this code is merged into a larger namespace of linear algebra utilities
Sets vector v to v + alpha * u ().
Definition at line 591 of file lin_alg.h.
References AddExpert().
Matrix* linalg__private::AddExpert | ( | double | alpha, | |
const Matrix *const | A, | |||
Matrix *const | B | |||
) |
Sets matrix B to B + alpha * A ().
Definition at line 581 of file lin_alg.h.
Referenced by AddExpert(), FastICA::DeflationFixedPointICA(), MoGEM::ExpectationMaximization(), and MoGL2E::L2Error().
Matrix* linalg__private::AddTo | ( | const Matrix *const | A, | |
Matrix *const | B | |||
) |
Sets matrix B to B + A ().
Definition at line 563 of file lin_alg.h.
Referenced by AddTo(), Center(), DoSvmNormalize(), InfomaxICA::evaluateICA(), MoGL2E::GoodnessOfFitTerm_(), MoGEM::KMeans(), MoGL2E::KMeans_(), MoGL2E::L2Error(), and DatasetScaler::StandardizeData().
double linalg__private::ArgMinus | ( | double | x, | |
double | arg | |||
) |
void linalg__private::Center | ( | Matrix | X, | |
Matrix * | X_centered | |||
) |
Sets a matrix to a centered matrix, where centering is done by subtracting the sum over the columns (a column vector) from each column of the matrix.
Definition at line 717 of file lin_alg.h.
References AddTo(), GenVector< T >::Init(), Scale(), GenVector< T >::SetZero(), and SubFrom().
Referenced by FastICA::DoFastICA().
Matrix* linalg__private::ColVector | ( | index_t | n, | |
double | value, | |||
Matrix * | col_vector | |||
) |
Matrix* linalg__private::DiagMatrixInit | ( | index_t | n, | |
double | value, | |||
Matrix * | diag_matrix | |||
) |
Matrix* linalg__private::DotMultiplyInit | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix * | C | |||
) |
Matrix* linalg__private::DotMultiplyOverwrite | ( | const Matrix *const | A, | |
Matrix *const | B | |||
) |
Matrix* linalg__private::DotMultiplySum | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix * | sum_vector | |||
) |
double linalg__private::ExpArg | ( | double | x, | |
double | arg | |||
) |
double linalg__private::Inv | ( | double | x, | |
double | arg | |||
) |
void linalg__private::MakeSubMatrixByColumns | ( | Vector | column_indices, | |
Matrix | A, | |||
Matrix * | A_sub | |||
) |
Inits a matrix to the columns of A specified in column_indices.
Definition at line 698 of file lin_alg.h.
References GenVector< T >::CopyValues(), and GenVector< T >::length().
Referenced by FastICA::RandomSubMatrix().
Matrix* linalg__private::MapInit | ( | double(*)(double, double) | function, | |
double | arg, | |||
const Matrix *const | A, | |||
Matrix * | B | |||
) |
Matrix* linalg__private::MapOverwrite | ( | double(*)(double, double) | function, | |
double | arg, | |||
Matrix * | A | |||
) |
Matrix* linalg__private::MatrixMapSum | ( | double(*)(double, double) | function, | |
double | arg, | |||
const Matrix *const | A, | |||
Matrix * | sum_vector | |||
) |
double linalg__private::MinusArg | ( | double | x, | |
double | arg | |||
) |
Matrix* linalg__private::MulInit | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix *const | C | |||
) |
Inits a matrix to A * B ().
Definition at line 437 of file lin_alg.h.
Referenced by FastICA::DoFastICA(), DoSvmNormalize(), MoGL2E::GoodnessOfFitTerm_(), KalmanFiltTimeInvariantMstUpdate(), KalmanFiltTimeInvariantTimeUpdate(), la::LeastSquareFit(), la::LeastSquareFitTrans(), MoGL2E::MakeModelWithGradients(), MulInit(), Orthogonalize(), propagate_one_step(), RandVector(), MoGL2E::RegularizationTerm_(), schur(), WhitenUsingEig(), and WhitenUsingSVD().
Matrix* linalg__private::MulOverwrite | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix *const | C | |||
) |
Overwrites a matrix with A * B ().
Definition at line 467 of file lin_alg.h.
Referenced by FastICA::DeflationFixedPointICA(), MoGEM::ExpectationMaximization(), KalmanFiltTimeInvariantMstUpdate(), KalmanFiltTimeInvariantTimeUpdate(), MoGL2E::MakeModel(), MoGL2E::MakeModelWithGradients(), and Orthogonalize().
Matrix* linalg__private::MulTransAInit | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix * | C | |||
) |
Inits a matrix to A' * B ().
Definition at line 477 of file lin_alg.h.
Referenced by la::LeastSquareFit(), Orthogonalize(), FastICA::SymmetricFixedPointICA(), and WhitenUsingSVD().
Matrix* linalg__private::MulTransAOverwrite | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix *const | C | |||
) |
Overwrites a matrix with A' * B ().
Definition at line 487 of file lin_alg.h.
Referenced by FastICA::SymmetricFixedPointICA().
Matrix* linalg__private::MulTransBInit | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix * | C | |||
) |
Inits a matrix to A * B' ().
Definition at line 497 of file lin_alg.h.
Referenced by DoSvmNormalize(), la::LeastSquareFitTrans(), Orthogonalize(), WhitenUsingEig(), and WhitenUsingSVD().
Matrix* linalg__private::MulTransBOverwrite | ( | const Matrix *const | A, | |
Matrix *const | B, | |||
Matrix *const | C | |||
) |
Overwrites a matrix with A * B' ().
Definition at line 507 of file lin_alg.h.
Referenced by KalmanFiltTimeInvariantMstUpdate(), and KalmanFiltTimeInvariantTimeUpdate().
void linalg__private::Orthogonalize | ( | const Matrix | W_old, | |
Matrix * | W | |||
) |
Orthogonalize W and return the result in W, using Eigen Decomposition.
Definition at line 890 of file lin_alg.h.
References MulInit(), MulOverwrite(), MulTransAInit(), and MulTransBInit().
Referenced by FastICA::SymmetricFixedPointICA().
double linalg__private::Plus | ( | double | x, | |
double | arg | |||
) |
void linalg__private::RandMatrix | ( | index_t | n_rows, | |
index_t | n_cols, | |||
Matrix * | A | |||
) |
Matrix* linalg__private::RandNormalInit | ( | index_t | d, | |
index_t | n, | |||
Matrix * | A | |||
) |
void linalg__private::RandVector | ( | Vector & | v | ) |
Overwrites a dimension-N vector to a random vector on the unit sphere in R^N.
Returns vector realization of zero-mean multi-variate Gaussian with unit covariance; vector needs to be a-priori initialized and passed by ref.
Definition at line 811 of file lin_alg.h.
Referenced by FastICA::DeflationFixedPointICA(), and FastICA::SymmetricFixedPointICA().
Matrix* linalg__private::RepeatMatrix | ( | index_t | num_row_reps, | |
index_t | num_col_reps, | |||
Matrix | base_matrix, | |||
Matrix * | new_matrix | |||
) |
void linalg__private::SaveCorrectly | ( | const char * | filename, | |
Matrix | a | |||
) |
Save the matrix to a file so that rows in the matrix correspond to rows in the file: This just means call data::Save() on the transpose of the matrix.
Definition at line 66 of file lin_alg.h.
References data::Save(), and la::TransposeInit().
Matrix* linalg__private::Scale | ( | double | alpha, | |
Matrix * | A | |||
) |
Sets A to alpha * A ().
Definition at line 401 of file lin_alg.h.
Referenced by Center(), FastICA::DeflationFixedPointICA(), DoSvmNormalize(), InfomaxICA::evaluateICA(), MoGEM::ExpectationMaximization(), MoGL2E::GoodnessOfFitTerm_(), GaussianHMM::InitGaussParameter(), MoGEM::KMeans(), MoGL2E::KMeans_(), MoGL2E::MakeModel(), MoGL2E::MakeModelWithGradients(), RandVector(), MoGL2E::RegularizationTerm_(), Scale(), DatasetScaler::StandardizeData(), WhitenUsingEig(), and WhitenUsingSVD().
Matrix* linalg__private::ScaleInit | ( | double | alpha, | |
const Matrix *const | A, | |||
Matrix * | B | |||
) |
Inits a matrix to alpha * A ().
Definition at line 419 of file lin_alg.h.
Referenced by MoGL2E::RegularizationTerm_(), and ScaleInit().
double linalg__private::Square | ( | double | x, | |
double | arg | |||
) |
double linalg__private::SquareArg | ( | double | x, | |
double | arg | |||
) |
Matrix* linalg__private::SubFrom | ( | const Matrix *const | A, | |
Matrix *const | B | |||
) |
Sets matrix B to B - A ().
Definition at line 545 of file lin_alg.h.
Referenced by Center(), MoGEM::ExpectationMaximization(), and SubFrom().
Matrix* linalg__private::SubInit | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix * | C | |||
) |
Inits a matrix to A - B ().
Definition at line 517 of file lin_alg.h.
Referenced by FastICA::DeflationFixedPointICA(), GaussianHMM::InitGaussParameter(), and SubInit().
Matrix* linalg__private::SubOverwrite | ( | const Matrix *const | A, | |
const Matrix *const | B, | |||
Matrix *const | C | |||
) |
Overwrites a matrix with A - B ().
Definition at line 535 of file lin_alg.h.
Referenced by MoGEM::KMeans(), and MoGL2E::KMeans_().
double linalg__private::Sum | ( | Vector * | v | ) |
Matrix* linalg__private::Sum | ( | const Matrix *const | A, | |
Matrix * | sum_vector | |||
) |
double linalg__private::TanhArg | ( | double | x, | |
double | arg | |||
) |
double linalg__private::Times | ( | double | x, | |
double | arg | |||
) |
double linalg__private::VectorMapSum | ( | double(*)(double, double) | function, | |
double | arg, | |||
const Vector *const | v | |||
) |
Matrix* linalg__private::VectorToDiag | ( | const Vector *const | diag_vector, | |
Matrix * | diag_matrix | |||
) |
Matrix* linalg__private::VectorToDiag | ( | const Matrix *const | diag_vector, | |
Matrix * | diag_matrix | |||
) |
void linalg__private::WhitenUsingEig | ( | Matrix | X, | |
Matrix * | X_whitened, | |||
Matrix * | whitening_matrix | |||
) |
Whitens a matrix using the eigen decomposition of the covariance matrix.
Whitening means the covariance matrix of the result is the identity matrix
Definition at line 778 of file lin_alg.h.
References GenVector< T >::length(), MulInit(), MulTransBInit(), and Scale().
Referenced by FastICA::DoFastICA().
void linalg__private::WhitenUsingSVD | ( | Matrix | X, | |
Matrix * | X_whitened, | |||
Matrix * | whitening_matrix | |||
) |
Whitens a matrix using the singular value decomposition of the covariance matrix.
Whitening means the covariance matrix of the result is the identity matrix
Definition at line 747 of file lin_alg.h.
References GenVector< T >::length(), MulInit(), MulTransAInit(), MulTransBInit(), and Scale().