queso-0.57.1
|
Class for matrix operations using GSL library. More...
#include <GslMatrix.h>
Public Member Functions | |
Constructor/Destructor methods | |
GslMatrix (const BaseEnvironment &env, const Map &map, unsigned int numCols) | |
Shaped Constructor: creates a shaped matrix with numCols columns. More... | |
GslMatrix (const BaseEnvironment &env, const Map &map, double diagValue) | |
Shaped Constructor: creates a square matrix with size map.NumGlobalElements() and diagonal values all equal to diagValue . More... | |
GslMatrix (const GslVector &v, double diagValue) | |
Shaped Constructor: creates a square matrix with size v.sizeLocal() and diagonal values all equal to diagValue . More... | |
GslMatrix (const GslVector &v) | |
Shaped Constructor: creates a square matrix with size v.sizeLocal() . More... | |
GslMatrix (const GslMatrix &B) | |
Shaped Constructor: creates a matrix with B.numCols() columns and B.numRowsLocal() rows. More... | |
~GslMatrix () | |
Destructor. More... | |
Set methods | |
GslMatrix & | operator= (const GslMatrix &rhs) |
Copies values from matrix rhs to this . More... | |
GslMatrix & | operator*= (double a) |
Stores in this the coordinate-wise multiplication of this and a . More... | |
GslMatrix & | operator/= (double a) |
Stores in this the coordinate-wise division of this by a . More... | |
GslMatrix & | operator+= (const GslMatrix &rhs) |
Stores in this the coordinate-wise addition of this and rhs . More... | |
GslMatrix & | operator-= (const GslMatrix &rhs) |
Stores in this the coordinate-wise subtraction of this by rhs . More... | |
Accessor methods | |
double & | operator() (unsigned int i, unsigned int j) |
Element access method (non-const). More... | |
const double & | operator() (unsigned int i, unsigned int j) const |
Element access method (const). More... | |
Attribute methods | |
unsigned int | numRowsLocal () const |
Returns the local row dimension of this matrix. More... | |
unsigned int | numRowsGlobal () const |
Returns the global row dimension of this matrix. More... | |
unsigned int | numCols () const |
Returns the column dimension of this matrix. More... | |
double | max () const |
Returns the maximum element value of the matrix. More... | |
unsigned int | rank (double absoluteZeroThreshold, double relativeZeroThreshold) const |
This function returns the number of singular values of this matrix (rank). More... | |
GslMatrix | transpose () const |
This function calculated the transpose of this matrix (square). More... | |
GslMatrix | inverse () const |
This function calculated the inverse of this matrix (square). More... | |
double | determinant () const |
Calculates the determinant of this matrix. More... | |
double | lnDeterminant () const |
Calculates the ln(determinant) of this matrix. More... | |
Norm methods | |
double | normFrob () const |
Returns the Frobenius norm of this matrix. More... | |
double | normMax () const |
Returns the Frobenius norm of this matrix. More... | |
Mathematical methods | |
int | chol () |
Computes Cholesky factorization of a real symmetric positive definite matrix this . More... | |
int | svd (GslMatrix &matU, GslVector &vecS, GslMatrix &matVt) const |
Checks for the dimension of this matrix, matU , VecS and matVt , and calls the protected routine internalSvd to compute the singular values of this . More... | |
const GslMatrix & | svdMatU () const |
This function calls private member GslMatrix::internalSvd() to set a M-by-N orthogonal matrix U of the singular value decomposition (svd) of a general rectangular M-by-N matrix A. More... | |
const GslMatrix & | svdMatV () const |
This function calls private member GslMatrix::internalSvd() to set a N-by-N orthogonal square matrix V of the singular value decomposition (svd) of a general rectangular M-by-N matrix A. More... | |
int | svdSolve (const GslVector &rhsVec, GslVector &solVec) const |
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with GslMatrix::svd (x=solVec, b=rhsVec). More... | |
int | svdSolve (const GslMatrix &rhsMat, GslMatrix &solMat) const |
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with GslMatrix::svd (x=solMat, b=rhsMat). More... | |
GslVector | multiply (const GslVector &x) const |
This function multiplies this matrix by vector x and returns the resulting vector. More... | |
void | multiply (const GslVector &x, GslVector &y) const |
This function multiplies this matrix by vector x and fills. More... | |
GslMatrix | multiply (const GslMatrix &X) const |
This function multiplies this matrix by matrix X and returns the resulting matrix. More... | |
void | multiply (const GslMatrix &X, GslMatrix &Y) const |
This function multiplies this matrix by matrix X and fills. More... | |
GslVector | invertMultiply (const GslVector &b) const |
This function calculates the inverse of this matrix and multiplies it with vector b . More... | |
void | invertMultiply (const GslVector &b, GslVector &x) const |
This function calculates the inverse of this matrix, multiplies it with vector b and stores the result in vector x . More... | |
GslMatrix | invertMultiply (const GslMatrix &B) const |
This function calculates the inverse of this matrix and multiplies it with matrix B . More... | |
void | invertMultiply (const GslMatrix &B, GslMatrix &X) const |
This function calculates the inverse of this matrix, multiplies it with matrix B and stores the result in matrix X . More... | |
GslVector | invertMultiplyForceLU (const GslVector &b) const |
This function calculates the inverse of this matrix and multiplies it with vector b . More... | |
void | invertMultiplyForceLU (const GslVector &b, GslVector &x) const |
This function calculates the inverse of this matrix, multiplies it with vector b and stores the result in vector x . More... | |
void | getColumn (const unsigned int column_num, GslVector &column) const |
This function gets the column_num-th column of this matrix and stores it into vector column . More... | |
GslVector | getColumn (const unsigned int column_num) const |
This function gets the column_num-th column of this matrix. More... | |
void | setColumn (const unsigned int column_num, const GslVector &column) |
This function copies vector column into the column_num-th column of this matrix. More... | |
void | getRow (const unsigned int row_num, GslVector &row) const |
This function gets the row_num-th column of this matrix and stores it into vector row . More... | |
GslVector | getRow (const unsigned int row_num) const |
This function gets the row_num-th column of this matrix. More... | |
void | setRow (const unsigned int row_num, const GslVector &row) |
This function copies vector row into the row_num-th column of this matrix. More... | |
void | eigen (GslVector &eigenValues, GslMatrix *eigenVectors) const |
This function computes the eigenvalues of a real symmetric matrix. More... | |
void | largestEigen (double &eigenValue, GslVector &eigenVector) const |
This function finds largest eigenvalue, namely eigenValue , of this matrix and its corresponding eigenvector, namely eigenVector . More... | |
void | smallestEigen (double &eigenValue, GslVector &eigenVector) const |
This function finds smallest eigenvalue, namely eigenValue , of this matrix and its corresponding eigenvector, namely eigenVector . More... | |
Get/Set methods | |
void | cwSet (double value) |
Component-wise set all values to this with value. More... | |
void | cwSet (unsigned int rowId, unsigned int colId, const GslMatrix &mat) |
Set the components of which positions are greater than (rowId,colId) with the value of mat(rowId,colId). More... | |
void | cwExtract (unsigned int rowId, unsigned int colId, GslMatrix &mat) const |
void | zeroLower (bool includeDiagonal=false) |
This function sets all the entries bellow the main diagonal of this matrix to zero. More... | |
void | zeroUpper (bool includeDiagonal=false) |
This function sets all the entries above the main diagonal of this matrix to zero. More... | |
void | filterSmallValues (double thresholdValue) |
This function sets to zero (filters) all entries of this matrix which are smaller than thresholdValue . More... | |
void | filterLargeValues (double thresholdValue) |
This function sets to zero (filters) all entries of this matrix which are greater than thresholdValue . More... | |
void | fillWithTranspose (unsigned int rowId, unsigned int colId, const GslMatrix &mat, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function stores the transpose of this matrix into this matrix. More... | |
void | fillWithBlocksDiagonally (unsigned int rowId, unsigned int colId, const std::vector< const GslMatrix * > &matrices, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function fills this matrix diagonally with const block matrices. More... | |
void | fillWithBlocksDiagonally (unsigned int rowId, unsigned int colId, const std::vector< GslMatrix * > &matrices, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function fills this matrix diagonally with block matrices. More... | |
void | fillWithBlocksHorizontally (unsigned int rowId, unsigned int colId, const std::vector< const GslMatrix * > &matrices, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function fills this matrix horizontally with const block matrices. More... | |
void | fillWithBlocksHorizontally (unsigned int rowId, unsigned int colId, const std::vector< GslMatrix * > &matrices, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function fills this matrix horizontally with const block. More... | |
void | fillWithBlocksVertically (unsigned int rowId, unsigned int colId, const std::vector< const GslMatrix * > &matrices, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function fills this matrix vertically with const block matrices. More... | |
void | fillWithBlocksVertically (unsigned int rowId, unsigned int colId, const std::vector< GslMatrix * > &matrices, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function fills this matrix vertically with block matrices. More... | |
void | fillWithTensorProduct (unsigned int rowId, unsigned int colId, const GslMatrix &mat1, const GslMatrix &mat2, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function calculates the tensor product of matrices mat1 and mat2 and stores it in this matrix. More... | |
void | fillWithTensorProduct (unsigned int rowId, unsigned int colId, const GslMatrix &mat1, const GslVector &vec2, bool checkForExactNumRowsMatching, bool checkForExactNumColsMatching) |
This function calculates the tensor product of matrix mat1 and vector vec2 and stores it in this matrix. More... | |
Miscellaneous methods | |
gsl_matrix * | data () |
Returns this matrix. More... | |
void | mpiSum (const MpiComm &comm, GslMatrix &M_global) const |
void | matlabLinearInterpExtrap (const GslVector &x1Vec, const GslMatrix &y1Mat, const GslVector &x2Vec) |
I/O methods | |
void | print (std::ostream &os) const |
Print method. Defines the behavior of the ostream << operator inherited from the Object class. More... | |
void | subWriteContents (const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const |
Write contents of subenvironment in file fileName . More... | |
void | subReadContents (const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) |
Read contents of subenvironment from file fileName . More... | |
Public Member Functions inherited from QUESO::Matrix | |
Matrix (const BaseEnvironment &env, const Map &map) | |
Shaped constructor. More... | |
virtual | ~Matrix () |
Virtual Destructor. More... | |
const BaseEnvironment & | env () const |
const Map & | map () const |
unsigned int | numOfProcsForStorage () const |
void | setPrintHorizontally (bool value) const |
Determines whether the matrix should be printed horizontally. More... | |
bool | getPrintHorizontally () const |
Checks if matrix will be is printed horizontally. More... | |
void | setInDebugMode (bool value) const |
Determines whether QUESO will run through this class in debug mode. More... | |
bool | getInDebugMode () const |
Checks if QUESO will run through this class in debug mode. More... | |
Private Member Functions | |
GslMatrix () | |
Default Constructor. More... | |
void | copy (const GslMatrix &src) |
In this function this matrix receives a copy of matrix src . More... | |
void | resetLU () |
In this function resets the LU decomposition of this matrix, as well as deletes the private member pointers, if existing. More... | |
int | internalSvd () const |
This function factorizes the M-by-N matrix A into the singular value decomposition A = U S V^T for M >= N. On output the matrix A is replaced by U. More... | |
Private Attributes | |
gsl_matrix * | m_mat |
GSL matrix, also referred to as this matrix. More... | |
gsl_matrix * | m_LU |
GSL matrix for the LU decomposition of m_mat. More... | |
GslMatrix * | m_inverse |
Inverse matrix of this . More... | |
Map * | m_svdColMap |
Mapping for matrices involved in the singular value decomposition (svd) routine. More... | |
GslMatrix * | m_svdUmat |
m_svdUmat stores the M-by-N orthogonal matrix U after the singular value decomposition of a matrix. More... | |
GslVector * | m_svdSvec |
m_svdSvec stores the diagonal of the N-by-N diagonal matrix of singular values S after the singular value decomposition of a matrix. More... | |
GslMatrix * | m_svdVmat |
m_svdVmat stores the N-by-N orthogonal square matrix V after the singular value decomposition of a matrix. More... | |
GslMatrix * | m_svdVTmat |
m_svdVmatT stores the transpose of N-by-N orthogonal square matrix V, namely V^T, after the singular value decomposition of a matrix. More... | |
double | m_determinant |
The determinant of this matrix. More... | |
double | m_lnDeterminant |
The natural logarithm of the determinant of this matrix. More... | |
gsl_permutation * | m_permutation |
The permutation matrix of a LU decomposition. More... | |
int | m_signum |
m_signum stores the sign of the permutation of the LU decomposition PA = LU. More... | |
bool | m_isSingular |
Indicates whether or not this matrix is singular. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from QUESO::Matrix | |
virtual void | base_copy (const Matrix &src) |
Copies base data from matrix src to this matrix. More... | |
Protected Attributes inherited from QUESO::Matrix | |
const BaseEnvironment & | m_env |
QUESO environment variable. More... | |
const Map | m_map |
Mapping variable. More... | |
const Map & | m_map |
Mapping variable. More... | |
bool | m_printHorizontally |
Flag for either or not print this matrix. More... | |
bool | m_inDebugMode |
Flag for either or not QUESO is in debug mode. More... | |
Class for matrix operations using GSL library.
This class creates and provides basic support for matrices of templated type as a specialization of Matrix using GSL matrices, which are defined by an encapsulated gsl_matrix structure.
Definition at line 49 of file GslMatrix.h.
QUESO::GslMatrix::GslMatrix | ( | const BaseEnvironment & | env, |
const Map & | map, | ||
unsigned int | numCols | ||
) |
Shaped Constructor: creates a shaped matrix with numCols
columns.
Definition at line 35 of file GslMatrix.C.
References m_mat.
QUESO::GslMatrix::GslMatrix | ( | const BaseEnvironment & | env, |
const Map & | map, | ||
double | diagValue | ||
) |
Shaped Constructor: creates a square matrix with size map.NumGlobalElements()
and diagonal values all equal to diagValue
.
Definition at line 59 of file GslMatrix.C.
References m_mat.
QUESO::GslMatrix::GslMatrix | ( | const GslVector & | v, |
double | diagValue | ||
) |
Shaped Constructor: creates a square matrix with size v.sizeLocal()
and diagonal values all equal to diagValue
.
Definition at line 86 of file GslMatrix.C.
References m_mat.
QUESO::GslMatrix::GslMatrix | ( | const GslVector & | v | ) |
Shaped Constructor: creates a square matrix with size v.sizeLocal()
.
The diagonal values of this matrix are the elements in vector v
.
Definition at line 112 of file GslMatrix.C.
References dim, m_mat, and QUESO::GslVector::sizeLocal().
QUESO::GslMatrix::GslMatrix | ( | const GslMatrix & | B | ) |
Shaped Constructor: creates a matrix with B.numCols()
columns and B.numRowsLocal()
rows.
This
matrix is a copy of matrix B
.
Definition at line 138 of file GslMatrix.C.
References QUESO::Matrix::base_copy(), copy(), and m_mat.
QUESO::GslMatrix::~GslMatrix | ( | ) |
Destructor.
Definition at line 161 of file GslMatrix.C.
References m_mat, and resetLU().
|
private |
Default Constructor.
Creates an empty matrix vector of no dimension. It should not be used by user.
Referenced by internalSvd(), and inverse().
|
virtual |
Computes Cholesky factorization of a real symmetric positive definite matrix this
.
In case fails to be symmetric and positive definite, an error will be returned.
Implements QUESO::Matrix.
Definition at line 408 of file GslMatrix.C.
References QUESO::Matrix::m_env, m_mat, QUESO::UQ_MATRIX_IS_NOT_POS_DEFINITE_RC, and QUESO::BaseEnvironment::worldRank().
|
private |
In this function this
matrix receives a copy of matrix src
.
Definition at line 220 of file GslMatrix.C.
References m_mat, and resetLU().
Referenced by GslMatrix(), and operator=().
void QUESO::GslMatrix::cwExtract | ( | unsigned int | rowId, |
unsigned int | colId, | ||
GslMatrix & | mat | ||
) | const |
Definition at line 385 of file GslMatrix.C.
References numCols(), and numRowsLocal().
void QUESO::GslMatrix::cwSet | ( | double | value | ) |
Component-wise set all values to this
with value.
Definition at line 347 of file GslMatrix.C.
References m_mat, numCols(), and numRowsLocal().
void QUESO::GslMatrix::cwSet | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const GslMatrix & | mat | ||
) |
Set the components of which
positions are greater than (rowId,colId) with the value of mat(rowId,colId).
Definition at line 362 of file GslMatrix.C.
References numCols(), and numRowsLocal().
gsl_matrix * QUESO::GslMatrix::data | ( | ) |
Returns this
matrix.
Definition at line 1766 of file GslMatrix.C.
References m_mat.
Referenced by internalSvd(), and svdSolve().
double QUESO::GslMatrix::determinant | ( | ) | const |
Calculates the determinant of this
matrix.
Definition at line 1038 of file GslMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), invertMultiply(), m_determinant, QUESO::Matrix::m_env, m_lnDeterminant, m_LU, QUESO::Matrix::m_map, m_signum, and QUESO::BaseEnvironment::subDisplayFile().
This function computes the eigenvalues of a real symmetric matrix.
Definition at line 1420 of file GslMatrix.C.
References QUESO::GslVector::data(), m_mat, numRowsLocal(), QUESO::queso_require_equal_to_msg, QUESO::queso_require_not_equal_to_msg, and QUESO::GslVector::sizeLocal().
void QUESO::GslMatrix::fillWithBlocksDiagonally | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const std::vector< const GslMatrix * > & | matrices, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function fills this
matrix diagonally with const block matrices.
Definition at line 753 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::fillWithBlocksDiagonally | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const std::vector< GslMatrix * > & | matrices, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function fills this
matrix diagonally with block matrices.
Definition at line 789 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::fillWithBlocksHorizontally | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const std::vector< const GslMatrix * > & | matrices, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function fills this
matrix horizontally with const block matrices.
Definition at line 825 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::fillWithBlocksHorizontally | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const std::vector< GslMatrix * > & | matrices, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function fills this
matrix horizontally with const block.
Definition at line 857 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::fillWithBlocksVertically | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const std::vector< const GslMatrix * > & | matrices, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function fills this
matrix vertically with const block matrices.
Definition at line 889 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::fillWithBlocksVertically | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const std::vector< GslMatrix * > & | matrices, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function fills this
matrix vertically with block matrices.
Definition at line 921 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::fillWithTensorProduct | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const GslMatrix & | mat1, | ||
const GslMatrix & | mat2, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function calculates the tensor product of matrices mat1
and mat2
and stores it in this
matrix.
Definition at line 953 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::fillWithTensorProduct | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const GslMatrix & | mat1, | ||
const GslVector & | vec2, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function calculates the tensor product of matrix mat1
and vector vec2
and stores it in this
matrix.
Definition at line 983 of file GslMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
void QUESO::GslMatrix::fillWithTranspose | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const GslMatrix & | mat, | ||
bool | checkForExactNumRowsMatching, | ||
bool | checkForExactNumColsMatching | ||
) |
This function stores the transpose of this
matrix into this
matrix.
Definition at line 1014 of file GslMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::GslMatrix::filterLargeValues | ( | double | thresholdValue | ) |
This function sets to zero (filters) all entries of this
matrix which are greater than thresholdValue
.
If thresholdValue
< 0 then no values will be filtered.
Definition at line 670 of file GslMatrix.C.
References numCols(), and numRowsLocal().
void QUESO::GslMatrix::filterSmallValues | ( | double | thresholdValue | ) |
This function sets to zero (filters) all entries of this
matrix which are smaller than thresholdValue
.
If thresholdValue
< 0 then no values will be filtered.
Definition at line 647 of file GslMatrix.C.
References numCols(), and numRowsLocal().
void QUESO::GslMatrix::getColumn | ( | const unsigned int | column_num, |
GslVector & | column | ||
) | const |
This function gets the column_num-th column of this
matrix and stores it into vector column
.
Definition at line 1586 of file GslMatrix.C.
References m_mat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
Referenced by getColumn(), invertMultiply(), matlabLinearInterpExtrap(), and svdSolve().
GslVector QUESO::GslMatrix::getColumn | ( | const unsigned int | column_num | ) | const |
This function gets the column_num-th column of this
matrix.
Definition at line 1651 of file GslMatrix.C.
References getColumn(), QUESO::Matrix::m_env, and QUESO::Matrix::m_map.
void QUESO::GslMatrix::getRow | ( | const unsigned int | row_num, |
GslVector & | row | ||
) | const |
This function gets the row_num-th column of this
matrix and stores it into vector row
.
Definition at line 1612 of file GslMatrix.C.
References m_mat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
Referenced by getRow().
GslVector QUESO::GslMatrix::getRow | ( | const unsigned int | row_num | ) | const |
This function gets the row_num-th column of this
matrix.
Definition at line 1638 of file GslMatrix.C.
References getRow(), QUESO::Matrix::m_env, and QUESO::Matrix::m_map.
|
private |
This function factorizes the M-by-N matrix A into the singular value decomposition A = U S V^T for M >= N. On output the matrix A is replaced by U.
Definition at line 532 of file GslMatrix.C.
References QUESO::GslVector::data(), data(), GslMatrix(), QUESO::Matrix::m_env, m_svdColMap, m_svdSvec, m_svdUmat, m_svdVmat, m_svdVTmat, QUESO::Matrix::map(), numCols(), numRowsLocal(), transpose(), QUESO::UQ_MATRIX_SVD_FAILED_RC, and QUESO::BaseEnvironment::worldRank().
Referenced by rank(), svd(), svdMatU(), svdMatV(), and svdSolve().
GslMatrix QUESO::GslMatrix::inverse | ( | ) | const |
This function calculated the inverse of this
matrix (square).
Definition at line 713 of file GslMatrix.C.
References QUESO::BaseEnvironment::checkingLevel(), QUESO::GslVector::cwSet(), QUESO::BaseEnvironment::displayVerbosity(), GslMatrix(), invertMultiply(), lnDeterminant(), QUESO::Matrix::m_env, m_inverse, QUESO::Matrix::m_map, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::BaseEnvironment::subDisplayFile().
This function calculates the inverse of this
matrix and multiplies it with vector b
.
It calls void GslMatrix::invertMultiply(const GslVector& b, GslVector& x) internally.
Definition at line 1222 of file GslMatrix.C.
References QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
Referenced by determinant(), inverse(), invertMultiply(), and lnDeterminant().
This function calculates the inverse of this
matrix, multiplies it with vector b
and stores the result in vector x
.
It checks for a previous LU decomposition of this
matrix and does not recompute it if m_MU != NULL .
Definition at line 1234 of file GslMatrix.C.
References QUESO::GslVector::data(), QUESO::BaseEnvironment::displayVerbosity(), QUESO::Matrix::m_env, QUESO::Matrix::m_inDebugMode, m_isSingular, m_LU, m_mat, m_permutation, m_signum, QUESO::GslVector::norm2(), numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, QUESO::GslVector::sizeLocal(), and QUESO::BaseEnvironment::subDisplayFile().
This function calculates the inverse of this
matrix and multiplies it with matrix B
.
It calls void GslMatrix::invertMultiply(const GslMatrix& B, GslMatrix& X) const internally.
Definition at line 1335 of file GslMatrix.C.
References invertMultiply(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, and numCols().
This function calculates the inverse of this
matrix, multiplies it with matrix B
and stores the result in matrix X
.
It checks for a previous LU decomposition of this
matrix and does not recompute it if m_MU != NULL .
Definition at line 1344 of file GslMatrix.C.
References getColumn(), invertMultiply(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and setColumn().
This function calculates the inverse of this
matrix and multiplies it with vector b
.
It calls void GslMatrix::InvertMultiplyForceLU(const GslVector& b, GslVector& x) const;(const GslVector& b,
GslVector& x) internally.
Definition at line 1373 of file GslMatrix.C.
References QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
This function calculates the inverse of this
matrix, multiplies it with vector b
and stores the result in vector x
.
It recalculates the LU decomposition of this
matrix.
Definition at line 1385 of file GslMatrix.C.
References QUESO::GslVector::data(), m_isSingular, m_LU, m_mat, m_permutation, m_signum, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
void QUESO::GslMatrix::largestEigen | ( | double & | eigenValue, |
GslVector & | eigenVector | ||
) | const |
This function finds largest eigenvalue, namely eigenValue
, of this
matrix and its corresponding eigenvector, namely eigenVector
.
Definition at line 1446 of file GslMatrix.C.
References QUESO::GslVector::abs(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, QUESO::queso_require_not_equal_to_msg, and QUESO::GslVector::sizeLocal().
double QUESO::GslMatrix::lnDeterminant | ( | ) | const |
Calculates the ln(determinant) of this
matrix.
Definition at line 1079 of file GslMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), invertMultiply(), m_determinant, QUESO::Matrix::m_env, m_lnDeterminant, m_LU, QUESO::Matrix::m_map, m_signum, and QUESO::BaseEnvironment::subDisplayFile().
Referenced by inverse().
void QUESO::GslMatrix::matlabLinearInterpExtrap | ( | const GslVector & | x1Vec, |
const GslMatrix & | y1Mat, | ||
const GslVector & | x2Vec | ||
) |
Definition at line 1741 of file GslMatrix.C.
References getColumn(), QUESO::GslVector::matlabLinearInterpExtrap(), numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, setColumn(), and QUESO::GslVector::sizeLocal().
double QUESO::GslMatrix::max | ( | ) | const |
Returns the maximum element value of the matrix.
Definition at line 329 of file GslMatrix.C.
References numCols(), and numRowsLocal().
Definition at line 1698 of file GslMatrix.C.
References QUESO::MpiComm::Allreduce(), QUESO::Matrix::env(), QUESO::BaseEnvironment::fullRank(), numCols(), numRowsLocal(), and QUESO::size.
This function multiplies this
matrix by vector x
and returns the resulting vector.
Definition at line 1155 of file GslMatrix.C.
References QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
Referenced by multiply(), and QUESO::operator*().
This function multiplies this
matrix by vector x
and fills.
Definition at line 1167 of file GslMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
This function multiplies this
matrix by matrix X
and returns the resulting matrix.
Definition at line 1189 of file GslMatrix.C.
References QUESO::Matrix::m_env, QUESO::Matrix::m_map, multiply(), and numCols().
This function multiplies this
matrix by matrix X
and fills.
Definition at line 1201 of file GslMatrix.C.
References numCols(), numRowsGlobal(), and QUESO::queso_require_equal_to_msg.
double QUESO::GslMatrix::normFrob | ( | ) | const |
Returns the Frobenius norm of this
matrix.
Definition at line 293 of file GslMatrix.C.
References numCols(), and numRowsLocal().
double QUESO::GslMatrix::normMax | ( | ) | const |
Returns the Frobenius norm of this
matrix.
Definition at line 311 of file GslMatrix.C.
References numCols(), and numRowsLocal().
|
virtual |
Returns the column dimension of this
matrix.
Implements QUESO::Matrix.
Definition at line 287 of file GslMatrix.C.
References m_mat.
Referenced by cwExtract(), cwSet(), fillWithBlocksDiagonally(), fillWithBlocksHorizontally(), fillWithBlocksVertically(), fillWithTensorProduct(), fillWithTranspose(), filterLargeValues(), filterSmallValues(), getColumn(), getRow(), internalSvd(), inverse(), invertMultiply(), invertMultiplyForceLU(), QUESO::leftDiagScaling(), matlabLinearInterpExtrap(), max(), mpiSum(), multiply(), normFrob(), normMax(), QUESO::operator*(), print(), rank(), QUESO::rightDiagScaling(), setColumn(), setRow(), subReadContents(), subWriteContents(), svd(), svdSolve(), transpose(), zeroLower(), and zeroUpper().
|
virtual |
Returns the global row dimension of this
matrix.
Implements QUESO::Matrix.
Definition at line 281 of file GslMatrix.C.
References m_mat.
Referenced by multiply(), and transpose().
|
virtual |
Returns the local row dimension of this
matrix.
Implements QUESO::Matrix.
Definition at line 275 of file GslMatrix.C.
References m_mat.
Referenced by cwExtract(), cwSet(), eigen(), fillWithBlocksDiagonally(), fillWithBlocksHorizontally(), fillWithBlocksVertically(), fillWithTensorProduct(), fillWithTranspose(), filterLargeValues(), filterSmallValues(), QUESO::GaussianLikelihoodBlockDiagonalCovariance< V, M >::GaussianLikelihoodBlockDiagonalCovariance(), QUESO::GaussianLikelihoodBlockDiagonalCovarianceRandomCoefficients< V, M >::GaussianLikelihoodBlockDiagonalCovarianceRandomCoefficients(), getColumn(), getRow(), internalSvd(), inverse(), invertMultiply(), invertMultiplyForceLU(), QUESO::leftDiagScaling(), matlabLinearInterpExtrap(), max(), mpiSum(), multiply(), normFrob(), normMax(), QUESO::operator*(), print(), rank(), QUESO::rightDiagScaling(), setColumn(), setRow(), subReadContents(), subWriteContents(), svd(), svdSolve(), zeroLower(), and zeroUpper().
|
inline |
Element access method (non-const).
Definition at line 104 of file GslMatrix.h.
|
inline |
Element access method (const).
Definition at line 115 of file GslMatrix.h.
References m_mat.
GslMatrix & QUESO::GslMatrix::operator*= | ( | double | a | ) |
Stores in this
the coordinate-wise multiplication of this
and a
.
Definition at line 177 of file GslMatrix.C.
References m_mat, and resetLU().
Stores in this
the coordinate-wise addition of this
and rhs
.
Definition at line 196 of file GslMatrix.C.
References m_mat, and resetLU().
Stores in this
the coordinate-wise subtraction of this
by rhs
.
Definition at line 207 of file GslMatrix.C.
References m_mat, and resetLU().
GslMatrix & QUESO::GslMatrix::operator/= | ( | double | a | ) |
Stores in this
the coordinate-wise division of this
by a
.
Definition at line 187 of file GslMatrix.C.
References resetLU().
Copies values from matrix rhs
to this
.
Definition at line 169 of file GslMatrix.C.
References copy(), and resetLU().
|
virtual |
Print method. Defines the behavior of the ostream << operator inherited from the Object class.
Implements QUESO::Matrix.
Definition at line 1772 of file GslMatrix.C.
References QUESO::Matrix::m_printHorizontally, numCols(), and numRowsLocal().
Referenced by QUESO::operator<<(), and QUESO::GslBlockMatrix::print().
unsigned int QUESO::GslMatrix::rank | ( | double | absoluteZeroThreshold, |
double | relativeZeroThreshold | ||
) | const |
This function returns the number of singular values of this
matrix (rank).
The rank function provides an estimate of the number of linearly independent rows or columns of a full matrix.
Definition at line 1120 of file GslMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), internalSvd(), QUESO::Matrix::m_env, m_svdSvec, numCols(), numRowsLocal(), QUESO::GslVector::sizeLocal(), and QUESO::BaseEnvironment::subDisplayFile().
|
private |
In this function resets the LU decomposition of this
matrix, as well as deletes the private member pointers, if existing.
Definition at line 232 of file GslMatrix.C.
References m_determinant, m_inverse, m_isSingular, m_lnDeterminant, m_LU, m_permutation, m_signum, m_svdColMap, m_svdSvec, m_svdUmat, m_svdVmat, and m_svdVTmat.
Referenced by copy(), operator*=(), operator+=(), operator-=(), operator/=(), operator=(), setColumn(), setRow(), zeroLower(), zeroUpper(), and ~GslMatrix().
void QUESO::GslMatrix::setColumn | ( | const unsigned int | column_num, |
const GslVector & | column | ||
) |
This function copies vector column
into the column_num-th column of this
matrix.
Definition at line 1681 of file GslMatrix.C.
References QUESO::GslVector::data(), m_mat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, resetLU(), and QUESO::GslVector::sizeLocal().
Referenced by invertMultiply(), matlabLinearInterpExtrap(), and svdSolve().
void QUESO::GslMatrix::setRow | ( | const unsigned int | row_num, |
const GslVector & | row | ||
) |
This function copies vector row
into the row_num-th column of this
matrix.
Definition at line 1664 of file GslMatrix.C.
References QUESO::GslVector::data(), m_mat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, resetLU(), and QUESO::GslVector::sizeLocal().
void QUESO::GslMatrix::smallestEigen | ( | double & | eigenValue, |
GslVector & | eigenVector | ||
) | const |
This function finds smallest eigenvalue, namely eigenValue
, of this
matrix and its corresponding eigenvector, namely eigenVector
.
Definition at line 1515 of file GslMatrix.C.
References QUESO::GslVector::abs(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, QUESO::queso_require_not_equal_to_msg, and QUESO::GslVector::sizeLocal().
void QUESO::GslMatrix::subReadContents | ( | const std::string & | fileName, |
const std::string & | fileType, | ||
const std::set< unsigned int > & | allowedSubEnvIds | ||
) |
Read contents of subenvironment from file fileName
.
Definition at line 1841 of file GslMatrix.C.
References QUESO::BaseEnvironment::closeFile(), QUESO::BaseEnvironment::fullRank(), QUESO::FilePtrSetStruct::ifsVar, QUESO::Matrix::m_env, numCols(), QUESO::Matrix::numOfProcsForStorage(), numRowsLocal(), QUESO::BaseEnvironment::openInputFile(), QUESO::queso_require_equal_to_msg, QUESO::BaseEnvironment::subDisplayFile(), and QUESO::BaseEnvironment::subRank().
void QUESO::GslMatrix::subWriteContents | ( | const std::string & | varNamePrefix, |
const std::string & | fileName, | ||
const std::string & | fileType, | ||
const std::set< unsigned int > & | allowedSubEnvIds | ||
) | const |
Write contents of subenvironment in file fileName
.
Definition at line 1801 of file GslMatrix.C.
References QUESO::BaseEnvironment::closeFile(), QUESO::Matrix::m_env, numCols(), QUESO::Matrix::numOfProcsForStorage(), numRowsLocal(), QUESO::FilePtrSetStruct::ofsVar, QUESO::BaseEnvironment::openOutputFile(), QUESO::BaseEnvironment::subIdString(), and QUESO::BaseEnvironment::subRank().
Checks for the dimension of this
matrix, matU
, VecS
and matVt
, and calls the protected routine internalSvd
to compute the singular values of this
.
Definition at line 435 of file GslMatrix.C.
References internalSvd(), m_svdSvec, m_svdUmat, m_svdVTmat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::GslVector::sizeLocal().
const GslMatrix & QUESO::GslMatrix::svdMatU | ( | ) | const |
This function calls private member GslMatrix::internalSvd() to set a M-by-N orthogonal matrix U of the singular value decomposition (svd) of a general rectangular M-by-N matrix A.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 512 of file GslMatrix.C.
References internalSvd(), and m_svdUmat.
const GslMatrix & QUESO::GslMatrix::svdMatV | ( | ) | const |
This function calls private member GslMatrix::internalSvd() to set a N-by-N orthogonal square matrix V of the singular value decomposition (svd) of a general rectangular M-by-N matrix A.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 522 of file GslMatrix.C.
References internalSvd(), and m_svdVmat.
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with GslMatrix::svd (x=solVec, b=rhsVec).
Definition at line 456 of file GslMatrix.C.
References QUESO::GslVector::data(), data(), QUESO::BaseEnvironment::displayVerbosity(), internalSvd(), QUESO::Matrix::m_env, m_svdSvec, m_svdUmat, m_svdVmat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, QUESO::GslVector::sizeLocal(), and QUESO::BaseEnvironment::subDisplayFile().
Referenced by svdSolve().
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with GslMatrix::svd (x=solMat, b=rhsMat).
Definition at line 487 of file GslMatrix.C.
References getColumn(), QUESO::Matrix::m_env, QUESO::Matrix::map(), numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, setColumn(), and svdSolve().
GslMatrix QUESO::GslMatrix::transpose | ( | ) | const |
This function calculated the transpose of this
matrix (square).
Definition at line 693 of file GslMatrix.C.
References QUESO::Map::Comm(), QUESO::Matrix::m_env, QUESO::Matrix::map(), numCols(), and numRowsGlobal().
Referenced by internalSvd().
|
virtual |
This function sets all the entries bellow the main diagonal of this
matrix to zero.
If \c includeDiagonal = false, then only the entries bellow the main diagonal are set to zero;
if includeDiagonal
= true, then the elements of the matrix diagonal are also set to zero.
Implements QUESO::Matrix.
Definition at line 591 of file GslMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and resetLU().
|
virtual |
This function sets all the entries above the main diagonal of this
matrix to zero.
If \c includeDiagonal = false, then only the entries above the main diagonal are set to zero;
if includeDiagonal
= true, then the elements of the matrix diagonal are also set to zero.
Implements QUESO::Matrix.
Definition at line 619 of file GslMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and resetLU().
|
mutableprivate |
The determinant of this
matrix.
Definition at line 446 of file GslMatrix.h.
Referenced by determinant(), lnDeterminant(), and resetLU().
|
mutableprivate |
Inverse matrix of this
.
Definition at line 415 of file GslMatrix.h.
|
mutableprivate |
Indicates whether or not this
matrix is singular.
Definition at line 464 of file GslMatrix.h.
Referenced by invertMultiply(), invertMultiplyForceLU(), and resetLU().
|
mutableprivate |
The natural logarithm of the determinant of this
matrix.
Definition at line 449 of file GslMatrix.h.
Referenced by determinant(), lnDeterminant(), and resetLU().
|
mutableprivate |
GSL matrix for the LU decomposition of m_mat.
Definition at line 412 of file GslMatrix.h.
Referenced by determinant(), invertMultiply(), invertMultiplyForceLU(), lnDeterminant(), and resetLU().
|
private |
GSL matrix, also referred to as this
matrix.
Definition at line 409 of file GslMatrix.h.
Referenced by chol(), copy(), cwSet(), data(), eigen(), getColumn(), getRow(), GslMatrix(), invertMultiply(), invertMultiplyForceLU(), numCols(), numRowsGlobal(), numRowsLocal(), operator()(), operator*=(), operator+=(), operator-=(), setColumn(), setRow(), and ~GslMatrix().
|
mutableprivate |
The permutation matrix of a LU decomposition.
In the LU decomposition PA = LU, the j-th column of the matrix P is given by the k-th column of the identity matrix, where k = p_j the j-th element of the permutation vector. A is the square matrix of interest and P is the permutation matrix.
Definition at line 455 of file GslMatrix.h.
Referenced by invertMultiply(), invertMultiplyForceLU(), and resetLU().
|
mutableprivate |
m_signum stores the sign of the permutation of the LU decomposition PA = LU.
In the LU decomposition PA = LU, where A is the square matrix of interest and P is the permutation matrix, m_signum has the value (-1)^n, where n is the number of interchanges in the permutation.
Definition at line 461 of file GslMatrix.h.
Referenced by determinant(), invertMultiply(), invertMultiplyForceLU(), lnDeterminant(), and resetLU().
|
mutableprivate |
Mapping for matrices involved in the singular value decomposition (svd) routine.
Definition at line 418 of file GslMatrix.h.
Referenced by internalSvd(), and resetLU().
|
mutableprivate |
m_svdSvec stores the diagonal of the N-by-N diagonal matrix of singular values S after the singular value decomposition of a matrix.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 431 of file GslMatrix.h.
Referenced by internalSvd(), rank(), resetLU(), svd(), and svdSolve().
|
mutableprivate |
m_svdUmat stores the M-by-N orthogonal matrix U after the singular value decomposition of a matrix.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 424 of file GslMatrix.h.
Referenced by internalSvd(), resetLU(), svd(), svdMatU(), and svdSolve().
|
mutableprivate |
m_svdVmat stores the N-by-N orthogonal square matrix V after the singular value decomposition of a matrix.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 437 of file GslMatrix.h.
Referenced by internalSvd(), resetLU(), svdMatV(), and svdSolve().
|
mutableprivate |
m_svdVmatT stores the transpose of N-by-N orthogonal square matrix V, namely V^T, after the singular value decomposition of a matrix.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 443 of file GslMatrix.h.
Referenced by internalSvd(), resetLU(), and svd().