LOOS  v2.3.2
loos::Math Namespace Reference

Namespace for math and math-related things in loos. More...

Classes

class  ColMajor
 Class for storing a matrix in column-major order. More...
 
class  Matrix
 Simple matrix template class using policy classes to determine behavior. More...
 
class  RowMajor
 Class for storing a matrix in row-major order... More...
 
class  SharedArray
 Storage policy for a block of memory wrapped in a boost::shared_array pointer. More...
 
class  SparseArray
 Storage policy for a sparse matrix (see important note in the detailed documentation). More...
 
class  Triangular
 Class for storing a symmetric triangular matrix. More...
 

Typedefs

typedef std::pair< uint, uint > Range
 Specify a range for columns/rows [first,second)
 

Functions

greal angle (const GCoord &, const GCoord &, const GCoord &, const GCoord *=NULL)
 Compute the angle in degrees assuming the middle is the vertex. More...
 
greal angle (const pAtom &a, const pAtom &b, const pAtom &c, const GCoord *=NULL)
 Compute the angle in degrees assuming the middle is the vertex. More...
 
greal torsion (const GCoord &a, const GCoord &b, const GCoord &c, const GCoord &d, const GCoord *=NULL)
 Compute the torsion in degrees. More...
 
greal torsion (const pAtom &a, const pAtom &b, const pAtom &c, const pAtom &d, const GCoord *=NULL)
 Compute the torsion in degrees. More...
 
template<typename T , template< typename > class S>
Matrix< T, RowMajor, S > reinterpretOrder (const Matrix< T, ColMajor, S > &)
 
template<typename T , template< typename > class S>
Matrix< T, ColMajor, S > reinterpretOrder (const Matrix< T, RowMajor, S > &)
 
template<typename T , class P , template< typename > class S>
std::ostream & operator<< (std::ostream &os, const Matrix< T, P, S > &M)
 
DoubleMatrix eigenDecomp (DoubleMatrix &M)
 Compute eigendecomposition of M. More...
 
boost::tuple< RealMatrix, RealMatrix, RealMatrixsvd (RealMatrix &M)
 Compute the SVD of a single precision matrix. More...
 
RealMatrix MMMultiply (const RealMatrix &A, const RealMatrix &B, const bool transa=false, const bool transb=false)
 Matrix-matrix multiply (using BLAS)
 
RealMatrix invert (RealMatrix &A, const float eps=1e-5)
 Pseudo-inverse of a matrix using the SVD.
 
DoubleMatrix invert (DoubleMatrix &A, const double eps)
 
void operator+= (RealMatrix &A, const RealMatrix &B)
 Overloaded operators for RealMatrix matrices (see important note below)
 
RealMatrix operator+ (const RealMatrix &A, const RealMatrix &B)
 
void operator-= (RealMatrix &A, const RealMatrix &B)
 
RealMatrix operator- (const RealMatrix &A, const RealMatrix &B)
 
void operator*= (RealMatrix &A, const float d)
 
RealMatrix operator* (const RealMatrix &A, const float d)
 
void operator*= (RealMatrix &A, const RealMatrix &B)
 
RealMatrix operator* (const RealMatrix &A, const RealMatrix &B)
 
void operator*= (DoubleMatrix &A, const double d)
 
DoubleMatrix operator* (const DoubleMatrix &A, const double d)
 
RealMatrix operator- (RealMatrix &A)
 
void normalizeColumns (loos::DoubleMatrix &A)
 Normalizes each column as a column-vector.
 
DoubleMatrix deye (const uint n)
 
template<typename T >
eye (const uint n)
 An identity matrix of size n.
 
template<typename T >
submatrix (const T &M, const Range &rows, const Range &cols)
 Extracts a submatrix.
 
template<typename T >
permuteColumns (const T &A, const std::vector< uint > &indices)
 Returns a copy of the matrix with the columns permuted by the indices.
 
template<typename T >
permuteRows (const T &A, const std::vector< uint > &indices)
 Returns a copy of the matrix with the rows permuted by the indices.
 
template<typename T >
transpose (const T &A)
 Transposes a matrix.
 
template<typename T >
shuffleColumns (const T &A)
 Randomly shuffle the columns of a matrix.
 
template<typename T >
shuffleColumnVector (const T &v)
 ! Randomly shuffle the rows of a single column vector
 
template<typename T >
void reverseColumns (T &A)
 
template<typename T >
void reverseRows (T &A)
 
template<typename T >
double subspaceOverlap (const T &A, const T &B, uint nmodes=0)
 
template<typename T >
double covarianceOverlap (const T &lamA, const T &UA, const T &lamB, const T &UB)
 Computes the covariance overlap between two subspaces. More...
 
template<typename T >
boost::tuple< double, double, double > zCovarianceOverlap (const T &lamA, const T &UA, const T &lamB, const T &UB, const uint tries)
 
template<class T1 , class P1 , template< typename > class S1, class T2 , class P2 , template< typename > class S2>
void copyMatrix (Matrix< T1, P1, S1 > &A, const Matrix< T2, P2, S2 > &M)
 Copy one matrix into another, converting order/storage along the way. More...
 
template<class T1 , class P1 , class T2 , class P2 >
void copyMatrix (Matrix< T1, P1, SparseArray > &A, const Matrix< T2, P2, SparseArray > &M)
 Overload for copying a sparse matrix that preserves the original. More...
 
template<typename T , class P , template< typename > class S>
std::vector< T > getRow (const Matrix< T, P, S > &M, const uint j)
 Extract a row from a matrix as a vector of T.
 
template<typename T , class P , template< typename > class S>
std::vector< T > getCol (const Matrix< T, P, S > &M, const uint i)
 Extract a column from a matrix as a vector of T.
 

Variables

const double DEGREES = 180 / M_PI
 

Detailed Description

Namespace for math and math-related things in loos.

Note: the operator overloads presented for DoubleMatrix are not going to be efficient. They are only provided as a convenience for working with matrices in LOOS. If you need to perform more serious linear algebra operations, you are encouraged to use a 3rd party library for your tool.

Function Documentation

greal loos::Math::angle ( const GCoord a,
const GCoord b,
const GCoord c,
const GCoord box = NULL 
)

Compute the angle in degrees assuming the middle is the vertex.

If you pass a pointer to a GCoord specifying the box size, this function will correctly handle periodicity

Definition at line 36 of file Geometry.cpp.

greal loos::Math::angle ( const pAtom &  a,
const pAtom &  b,
const pAtom &  c,
const GCoord box = NULL 
)

Compute the angle in degrees assuming the middle is the vertex.

If you pass a pointer to a GCoord specifying the box size, this function will correctly handle periodicity

Definition at line 52 of file Geometry.cpp.

template<class T1 , class P1 , template< typename > class S1, class T2 , class P2 , template< typename > class S2>
void loos::Math::copyMatrix ( Matrix< T1, P1, S1 > &  A,
const Matrix< T2, P2, S2 > &  M 
)

Copy one matrix into another, converting order/storage along the way.

Scans over all elements of a matrix. This may not behave as intended with sparse matrices...

Definition at line 52 of file MatrixUtils.hpp.

template<class T1 , class P1 , class T2 , class P2 >
void loos::Math::copyMatrix ( Matrix< T1, P1, SparseArray > &  A,
const Matrix< T2, P2, SparseArray > &  M 
)

Overload for copying a sparse matrix that preserves the original.

Note: static null_value SHOULD match what's in MatrixStorage, but this probably isn't guaranteed Note: Overloading templated functions is dangerous. If this needs to be expanded, better to use an Impl class...

Definition at line 73 of file MatrixUtils.hpp.

template<typename T >
double loos::Math::covarianceOverlap ( const T &  lamA,
const T &  UA,
const T &  lamB,
const T &  UB 
)

Computes the covariance overlap between two subspaces.

This function expects a set of eigenpairs for comparison. The eigenvalues are stored in a Matrix-vector (i.e. an nx1 matrix). The eigenvectors are stored in the columns of the respective matrices.

Note: Be sure that the eigenvalues are scaled appropriately. For example, when comparing PCA and ENM, the ENM eigenvalues are inversely proportional to the PCA eigenvalues while the PCA "eigenvalues" are actually the singular values (and hence the square-root of the eigenvalues of AA'

Note: It is possible for double sum to be slightly greater than 2x the sum of the eigenvalues, which results in trying to take the square root of a negative number. To prevent this, we actually use the absolute value of the difference.

Note: Due to rounding errors in single precision, it is possible that the covariance overlap of a set of eigenpairs against itself will not come out to be exactly 1, but will be close (i.e. to within 1e-3).

Definition at line 303 of file MatrixOps.hpp.

RealMatrix loos::Math::eigenDecomp ( DoubleMatrix M)

Compute eigendecomposition of M.

Internally, this function uses dsyev from ATLAS/LAPACK. The passed matrix, M, will be overwritten by the eigenvectors. The ordering of eigenpairs is from smallest magnitude to largest.

Definition at line 36 of file MatrixOps.cpp.

boost::tuple< DoubleMatrix, DoubleMatrix, DoubleMatrix > loos::Math::svd ( DoubleMatrix M)

Compute the SVD of a single precision matrix.

Compute the SVD of a double precision matrix.

The SVD functions will overwrite the source matrix

  • M

Definition at line 94 of file MatrixOps.cpp.

greal loos::Math::torsion ( const GCoord a,
const GCoord b,
const GCoord c,
const GCoord d,
const GCoord box = NULL 
)

Compute the torsion in degrees.

If you pass a pointer to a GCoord specifying the box size, this function will correctly handle periodicity

Definition at line 61 of file Geometry.cpp.

greal loos::Math::torsion ( const pAtom &  a,
const pAtom &  b,
const pAtom &  c,
const pAtom &  d,
const GCoord box = NULL 
)

Compute the torsion in degrees.

If you pass a pointer to a GCoord specifying the box size, this function will correctly handle periodicity

Definition at line 81 of file Geometry.cpp.