Loading [MathJax]/jax/output/HTML-CSS/config.js
1.7.3
Geostatistics & Machine Learning toolbox | https://gstlearn.org
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MatrixSymmetric Class Reference

#include <MatrixSymmetric.hpp>

Inheritance diagram for MatrixSymmetric:
MatrixSquare MatrixDense AMatrix AStringable ICloneable

Detailed Description

Square Symmetric matrices

Public Member Functions

 MatrixSymmetric (int nrow=0)
 
 MatrixSymmetric (const MatrixSymmetric &m)
 
 MatrixSymmetric (const AMatrix &m)
 
MatrixSymmetricoperator= (const MatrixSymmetric &m)
 
virtual ~MatrixSymmetric ()
 
bool mustBeSymmetric () const final
 ICloneable interface.
 
bool isSymmetric (double eps=EPSILON10, bool printWhyNot=false) const final
 
void resetFromVVD (const VectorVectorDouble &tab, bool byCol=true) override
 Reset the matrix from an array of double values.
 
void normMatrix (const AMatrix &y, const MatrixSquare &x=MatrixSquare(), bool transpose=false)
 
int computeEigen (bool optionPositive=true)
 
int computeGeneralizedEigen (const MatrixSymmetric &b, bool optionPositive=true)
 
int computeGeneralizedInverse (MatrixSymmetric &tabout, double maxicond=1.e20, double eps=EPSILON20)
 
bool isDefinitePositive ()
 
int minimizeWithConstraintsInPlace (const VectorDouble &gmat, const MatrixDense &aemat, const VectorDouble &bemat, const MatrixDense &aimat, const VectorDouble &bimat, VectorDouble &xmat)
 
virtual bool _isPhysicallyPresent (int irow, int icol) const override
 
virtual void _setValues (const double *values, bool byCol=true) override
 
virtual int _invert () override
 
int _matrix_qo (const VectorDouble &gmat, VectorDouble &xmat)
 
int _matrix_qoc (bool flag_invert, const VectorDouble &gmat, int na, const MatrixDense &amat, const VectorDouble &bmat, VectorDouble &xmat, VectorDouble &lambda)
 
int _constraintsError (const VectorInt &active, const MatrixDense &aimat, const VectorDouble &bimat, const VectorDouble &xmat, VectorDouble &vmat, VectorInt &flag)
 
int _terminateEigen (const VectorDouble &eigenValues, const VectorDouble &eigenVectors, bool optionPositive=true, bool changeOrder=false)
 
MatrixSymmetric compress0MatLC (const MatrixDense &matLC)
 
- Public Member Functions inherited from MatrixSquare
 MatrixSquare (int nrow=0)
 
 MatrixSquare (const MatrixSquare &r)
 
 MatrixSquare (const AMatrix &m)
 
MatrixSquareoperator= (const MatrixSquare &r)
 
virtual ~MatrixSquare ()
 
virtual double determinant (void) const
 ICloneable interface.
 
bool isSquare (bool printWhyNot=false) const override
 
int getNSize () const
 
double trace () const
 
void innerMatrix (const MatrixSquare &x, const AMatrix &r1, const AMatrix &r2)
 
void prodDiagByVector (const VectorDouble &diag)
 
void divideDiagByVector (const VectorDouble &diag)
 
void prodByDiagInPlace (int mode, const VectorDouble &c)
 
double normVec (const VectorDouble &vec)
 
int decomposeLU (MatrixSquare &tls, MatrixSquare &tus, double eps=EPSILON20)
 
- Public Member Functions inherited from MatrixDense
 MatrixDense (int nrow=0, int ncol=0)
 
 MatrixDense (const MatrixDense &r)
 
 MatrixDense (const AMatrix &r)
 
MatrixDenseoperator= (const MatrixDense &r)
 
virtual ~MatrixDense ()
 
bool isDense () const override
 Cloneable interface.
 
bool isSparse () const override
 
void setValue (int irow, int icol, double value, bool flagCheck=false) override
 
virtual double getValue (int irow, int icol, bool flagCheck=false) const override
 
void updValue (int irow, int icol, const EOperator &oper, double value, bool flagCheck=false) override
 
virtual void setColumn (int icol, const VectorDouble &tab, bool flagCheck=false) override
 
virtual void setRow (int irow, const VectorDouble &tab, bool flagCheck=false) override
 
virtual void setDiagonal (const VectorDouble &tab, bool flagCheck=false) override
 
virtual void setDiagonalToConstant (double value=1.) override
 
virtual void addScalar (double v) override
 
virtual void addScalarDiag (double v) override
 
virtual void prodScalar (double v) override
 
virtual void fill (double value) override
 
virtual void multiplyRow (const VectorDouble &vec) override
 
virtual void multiplyColumn (const VectorDouble &vec) override
 
virtual void divideRow (const VectorDouble &vec) override
 
virtual void divideColumn (const VectorDouble &vec) override
 
virtual VectorDouble prodVecMat (const VectorDouble &x, bool transpose=false) const override
 
virtual VectorDouble prodMatVec (const VectorDouble &x, bool transpose=false) const override
 
virtual VectorDouble getRow (int irow) const override
 
virtual VectorDouble getColumn (int icol) const override
 
constvect getColumnPtr (int icol) const
 
virtual void prodMatMatInPlace (const AMatrix *x, const AMatrix *y, bool transposeX=false, bool transposeY=false) override
 
void addMatInPlace (const MatrixDense &y, double cx=1., double cy=1.)
 The next functions use specific definition of matrix (to avoid dynamic_cast) rather than manipulating AMatrix. They are not generic of AMatrix anymore. WARNING: output matrix should not match any of input matrices (speed up).
 
virtual void prodNormMatMatInPlace (const MatrixDense *a, const MatrixDense *m, bool transpose=false)
 
virtual void prodNormMatVecInPlace (const MatrixDense &a, const VectorDouble &vec=VectorDouble(), bool transpose=false)
 
VectorDouble getEigenValues () const
 
const MatrixSquaregetEigenVectors () const
 
int invert2 (MatrixDense &res) const
 
void unsample (const AMatrix *A, const VectorInt &rowFetch, const VectorInt &colFetch, bool flagInvertRow=false, bool flagInvertCol=false)
 Set the values contained in 'A' into the current matrix.
 
MatrixDense compressMatLC (const MatrixDense &matLC, bool transpose=false)
 Perform the compressing product, according to 'transpose'.
 
void addRow (int nrow_added=1)
 
void addColumn (int ncolumn_added=1)
 
constvect getViewOnColumn (int icol) const
 
vect getViewOnColumnModify (int icol)
 
Eigen::Map< const Eigen::MatrixXd > getEigenMat () const
 
Eigen::Map< Eigen::MatrixXd > getEigenMat ()
 
- Public Member Functions inherited from AMatrix
 AMatrix (int nrow=0, int ncol=0)
 
 AMatrix (const AMatrix &m)
 
AMatrixoperator= (const AMatrix &m)
 
virtual ~AMatrix ()
 
virtual void reset (int nrows, int ncols)
 
virtual void resetFromValue (int nrows, int ncols, double value)
 Reset the matrix to new dimensions and fill with a new value.
 
virtual void resetFromArray (int nrows, int ncols, const double *tab, bool byCol=true)
 Reset the matrix from an array of double values.
 
virtual void resetFromVD (int nrows, int ncols, const VectorDouble &tab, bool byCol=true)
 Reset the matrix from a vector of double values.
 
virtual String toString (const AStringFormat *strfmt=nullptr) const override
 Interface to AStringable.
 
void clear ()
 
virtual bool isValid (int irow, int icol, bool printWhyNot=false) const
 
virtual bool isIdentity (bool printWhyNot=false) const
 
virtual void transposeInPlace ()
 
virtual AMatrixtranspose () const
 
virtual NF_Triplet getMatrixToTriplet (int shiftRow=0, int shiftCol=0) const
 
void addMatInPlace (const AMatrix &y, double cx=1., double cy=1.)
 
void prodMatInPlace (const AMatrix *matY, bool transposeY=false)
 
void prodNormMatMatInPlace (const AMatrix *a, const AMatrix *m, bool transpose=false)
 
void prodNormMatVecInPlace (const AMatrix &a, const VectorDouble &vec=VectorDouble(), bool transpose=false)
 
void resize (int nrows, int ncols)
 Resize the matrix to new dimensions (this method doesn't change the storage type)
 
void addValue (int irow, int icol, double value)
 
bool isSame (const AMatrix &m, double eps=EPSILON4, bool printWhyNot=false)
 
bool isSameSize (const AMatrix &m) const
 
bool empty () const
 
double compare (const AMatrix &mat) const
 
int getNRows () const
 
int getNCols () const
 
int size () const
 
VectorDouble getValues (bool byCol=true) const
 
VectorDouble getDiagonal (int shift=0) const
 
bool isColumnDefined (int icol) const
 
bool isRowDefined (int irow) const
 
int getNColDefined () const
 
int getNRowDefined () const
 
VectorDouble getColumnByRowRange (int icol, int rowFrom, int rowTo) const
 
bool isNonNegative (bool verbose=false) const
 
void prodMatVecInPlace (const VectorDouble &x, VectorDouble &y, bool transpose=false) const
 
int prodMatVecInPlace (const constvect x, vect y, bool transpose=false) const
 
void prodMatVecInPlacePtr (const double *x, double *y, bool transpose=false) const
 
void prodVecMatInPlace (const VectorDouble &x, VectorDouble &y, bool transpose=false) const
 
void prodVecMatInPlacePtr (const double *x, double *y, bool transpose=false) const
 
double quadraticMatrix (const VectorDouble &x, const VectorDouble &y)
 
int invert ()
 
int solve (const VectorDouble &b, VectorDouble &x) const
 
void dumpElements (const String &title, int ifrom, int ito) const
 
void dumpStatistics (const String &title) const
 
void setIdentity (double value=1.)
 
void fillRandom (int seed=432432, double zeroPercent=0)
 
void setValues (const VectorDouble &values, bool byCol=true)
 
double getMeanByColumn (int icol) const
 
double getMinimum () const
 
double getMaximum () const
 
double getNormInf () const
 
void copyReduce (const AMatrix *x, const VectorInt &validRows, const VectorInt &validCols)
 
void copyElements (const AMatrix &m, double factor=1.)
 
void setFlagCheckAddress (bool flagCheckAddress)
 
void makePositiveColumn ()
 
void linearCombination (double val1, const AMatrix *mat1, double val2=1., const AMatrix *mat2=nullptr, double val3=1., const AMatrix *mat3=nullptr)
 Perfom the algebraic equation this = val1 * mat1 + val2 * mat2 + val3 * mat3.
 
virtual int addProdMatVecInPlace (const constvect x, vect y, bool transpose=false) const
 
double operator() (int row, int col) const
 
double & operator() (int row, int col)
 
virtual bool needToReset (int nrows, int ncols)
 
- Public Member Functions inherited from AStringable
 AStringable ()
 
 AStringable (const AStringable &r)
 
AStringableoperator= (const AStringable &r)
 
virtual ~AStringable ()
 
virtual void display (const AStringFormat *strfmt=nullptr) const final
 
virtual void display (int level) const final
 
- Public Member Functions inherited from ICloneable
 ICloneable ()
 
virtual ~ICloneable ()
 
virtual ICloneableclone () const =0
 

Static Public Member Functions

static MatrixSymmetriccreateFromVVD (const VectorVectorDouble &X)
 
static MatrixSymmetriccreateFromVD (const VectorDouble &X)
 
static MatrixSymmetriccreateFromTLTU (int neq, const VectorDouble &tl)
 
static MatrixSymmetriccreateFromTriangle (int mode, int neq, const VectorDouble &tl)
 
static MatrixSymmetriccreateRandomDefinitePositive (int neq, int seed=13242)
 
static MatrixSymmetricsample (const MatrixSymmetric *A, const VectorInt &rowKeep, bool flagInvert=false)
 Create an output Square Symmetric Matrix by selecting some rows (and columns) of the Input matrix 'A'.
 
static int _constraintsConcatenateMat (int nae, int nai, int neq, const VectorInt &active, const MatrixDense &tabemat, const MatrixDense &tabimat, MatrixDense &tabout)
 
static int _constraintsConcatenateVD (int nae, int nai, const VectorInt &active, const VectorDouble &tabemat, const VectorDouble &tabimat, VectorDouble &tabout)
 
static int _constraintsCount (int nai, VectorInt &active)
 
- Static Public Member Functions inherited from MatrixSquare
static MatrixSquarecreateFromVVD (const VectorVectorDouble &X)
 
static MatrixSquarecreateFromVD (const VectorDouble &X, int nrow, bool byCol=false, bool invertColumnOrder=false)
 
- Static Public Member Functions inherited from MatrixDense
static MatrixDensecreate (const MatrixDense *mat)
 
static MatrixDensecreate (int nrow, int ncol)
 
static MatrixDensecreateFromVVD (const VectorVectorDouble &X)
 
static MatrixDensecreateFromVD (const VectorDouble &X, int nrow, int ncol, bool byCol=false, bool invertColumnOrder=false)
 
static MatrixDenseglue (const AMatrix *A1, const AMatrix *A2, bool flagShiftRow, bool flagShiftCol)
 
static MatrixDensesample (const AMatrix *A, const VectorInt &rowKeep=VectorInt(), const VectorInt &colKeep=VectorInt(), bool flagInvertRow=false, bool flagInvertCol=false)
 Create an output Rectangular Matrix by selecting some rows and columns of the Input matrix 'A'.
 
static void sum (const MatrixDense *mat1, const MatrixDense *mat2, MatrixDense *mat3)
 

Public Attributes

 DECLARE_TOTL
 Has a specific implementation in the Target language.
 
- Public Attributes inherited from MatrixSquare
 DECLARE_TOTL
 Has a specific implementation in the Target language.
 
- Public Attributes inherited from MatrixDense
 DECLARE_TOTL
 Has a specific implementation in the Target language.
 

Constructor & Destructor Documentation

◆ MatrixSymmetric() [1/3]

MatrixSymmetric::MatrixSymmetric ( int  nrow = 0)

◆ MatrixSymmetric() [2/3]

MatrixSymmetric::MatrixSymmetric ( const MatrixSymmetric m)

◆ MatrixSymmetric() [3/3]

MatrixSymmetric::MatrixSymmetric ( const AMatrix m)

◆ ~MatrixSymmetric()

MatrixSymmetric::~MatrixSymmetric ( )
virtual

Member Function Documentation

◆ _constraintsConcatenateMat()

int MatrixSymmetric::_constraintsConcatenateMat ( int  nae,
int  nai,
int  neq,
const VectorInt active,
const MatrixDense tabemat,
const MatrixDense tabimat,
MatrixDense tabout 
)
static

Concatenate the equality and the active inequality material

Returns
The total number of constraints
Parameters
[in]naeNumber of equalities
[in]naiNumber of inequalities
[in]neqFirst dimension of the array
[in]activeArray of active/non active inequalities
[in]tabematEquality material (Dimension: neq * nai)
[in]tabimatInequality material
[out]taboutOutput array

◆ _constraintsConcatenateVD()

int MatrixSymmetric::_constraintsConcatenateVD ( int  nae,
int  nai,
const VectorInt active,
const VectorDouble tabemat,
const VectorDouble tabimat,
VectorDouble tabout 
)
static

Concatenate the equality and the active inequality material

Returns
The total number of constraints
Parameters
[in]naeNumber of equalities
[in]naiNumber of inequalities
[in]activeArray of active/non active inequalities
[in]tabematEquality material (Dimension: neq * nai)
[in]tabimatInequality material
[out]taboutOutput array

◆ _constraintsCount()

int MatrixSymmetric::_constraintsCount ( int  nai,
VectorInt active 
)
static

Count the number of active constraints

Returns
Number of active constraints
Parameters
[in]naiNumber of constraints
[in]activeArray of constraint status

◆ _constraintsError()

int MatrixSymmetric::_constraintsError ( const VectorInt active,
const MatrixDense aimat,
const VectorDouble bimat,
const VectorDouble xmat,
VectorDouble vmat,
VectorInt flag 
)

Calculate how constraints are fulfilled

Returns
Count of the constraints not fulfilled
Parameters
[in]activeArray of active/non active inequalities (optional)
[in]aimatInequality material (Dimension: neq * nai)
[in]bimatright-hand side for inequalities (Dimension: nai)
[out]xmatsolution of the linear system with no constraint (neq)
[out]vmatmatrix of errors (if not NULL)
[out]flagarray specifying if constraint is active (if not NULL)

◆ _invert()

int MatrixSymmetric::_invert ( )
overridevirtual

Reimplemented from MatrixDense.

◆ _isPhysicallyPresent()

bool MatrixSymmetric::_isPhysicallyPresent ( int  ,
int   
) const
overridevirtual

Say if (irow, icol) is stored physically or not

Reimplemented from AMatrix.

◆ _matrix_qo()

int MatrixSymmetric::_matrix_qo ( const VectorDouble gmat,
VectorDouble xmat 
)

Solve a linear system: H %*% g = x

Returns
Error return code
Parameters
[in]gmatright-hand side vector (Dimension: neq)
[out]xmatsolution vector (Dimension: neq)
Remarks
In output, 'this' contains the inverse matrix

◆ _matrix_qoc()

int MatrixSymmetric::_matrix_qoc ( bool  flag_invert,
const VectorDouble gmat,
int  na,
const MatrixDense amat,
const VectorDouble bmat,
VectorDouble xmat,
VectorDouble lambda 
)

Minimize 1/2 t(x) %*% H %*% x + t(g) %*% x under the constraints t(A) %*% x = b

Returns
Error return code
Parameters
[in]flag_invertTells if the inverse has already been calculated
[in]gmatright-hand side vector (Dimension: neq)
[in]naNumber of equalities
[in]amatmatrix for inequalities (Dimension: neq * na)
[in]bmatinequality vector (Dimension: na)
[in]xmatsolution of the linear system with no constraint. On return, solution with constraints (Dimension: neq)
[out]lambdaworking vector (Dimension: na)
Remarks
In input:
If flag_invert== 1, H is provided as the generalized inverse
and x contains the solution of the linear system with no constraint
If flag_invert==0, H is the primal matrix
In output, H contains the inverse matrix

◆ _setValues()

void MatrixSymmetric::_setValues ( const double *  values,
bool  byCol = true 
)
overridevirtual
Warning
: values is provided as a square complete matrix

Reimplemented from AMatrix.

◆ _terminateEigen()

int MatrixSymmetric::_terminateEigen ( const VectorDouble eigenValues,
const VectorDouble eigenVectors,
bool  optionPositive = true,
bool  changeOrder = false 
)

◆ compress0MatLC()

MatrixSymmetric MatrixSymmetric::compress0MatLC ( const MatrixDense matLC)

◆ computeEigen()

int MatrixSymmetric::computeEigen ( bool  optionPositive = true)

◆ computeGeneralizedEigen()

int MatrixSymmetric::computeGeneralizedEigen ( const MatrixSymmetric b,
bool  optionPositive = true 
)

◆ computeGeneralizedInverse()

int MatrixSymmetric::computeGeneralizedInverse ( MatrixSymmetric tabout,
double  maxicond = 1.e20,
double  eps = EPSILON20 
)

Calculate the generalized inverse of the input square symmetric matrix

Returns
Error returned code
Parameters
[out]taboutInverted matrix (suqrae symmetric)
[out]maxicondMaximum value for the Condition Index (MAX(ABS(eigval)))
[in]epsTolerance
Remarks
The input and output matrices can match

◆ createFromTLTU()

MatrixSymmetric * MatrixSymmetric::createFromTLTU ( int  neq,
const VectorDouble tl 
)
static

Create the Symmetric matrix as the product of 'tl' (lower triangle) by its transpose

Parameters
[in]neqNumber of rows or columns in the system
[in]tlLower triangular matrix defined by column (Dimension; neq*(neq+1)/2)

◆ createFromTriangle()

MatrixSymmetric * MatrixSymmetric::createFromTriangle ( int  mode,
int  neq,
const VectorDouble tl 
)
static

Fill a square matrix with a triangular matrix

Parameters
[in]mode0: TL (upper); 1: TL (lower)
[in]neqnumber of equations in the system
[in]tlTriangular matrix (any part)

◆ createFromVD()

MatrixSymmetric * MatrixSymmetric::createFromVD ( const VectorDouble X)
static

◆ createFromVVD()

MatrixSymmetric * MatrixSymmetric::createFromVVD ( const VectorVectorDouble X)
static

Converts a VectorVectorDouble into a Square Symmetric Matrix Note: the input argument is stored by row (if coming from [] specification)

Parameters
XInput VectorVectorDouble argument
Returns
The returned square symmetric matrix
Remarks
: the matrix is transposed implicitly while reading

◆ createRandomDefinitePositive()

MatrixSymmetric * MatrixSymmetric::createRandomDefinitePositive ( int  neq,
int  seed = 13242 
)
static

◆ isDefinitePositive()

bool MatrixSymmetric::isDefinitePositive ( )

Check if a matrix is definite positive

Returns
True if the matrix is definite positive; False otherwise

◆ isSymmetric()

bool MatrixSymmetric::isSymmetric ( double  eps = EPSILON10,
bool  printWhyNot = false 
) const
inlinefinalvirtual

Check if the input matrix is (non empty and square) symmetric

Indicate if the current matrix is symmetric

Parameters
epsEpsilon for double equality comparison
printWhyNotPrint the message is the answer is false
Returns
true if the current matrix is symmetric

Reimplemented from AMatrix.

◆ minimizeWithConstraintsInPlace()

int MatrixSymmetric::minimizeWithConstraintsInPlace ( const VectorDouble gmat,
const MatrixDense aemat,
const VectorDouble bemat,
const MatrixDense aimat,
const VectorDouble bimat,
VectorDouble xmat 
)

Minimize 1/2 t(x) %*% H %*% x + t(g) %*% x under the constraints t(Ae) %*% x = be and t(Ai) %*% x = bi

Returns
Error return code
Parameters
[in]gmatright-hand side vector (Dimension: neq)
[in]aematMatrix rectangular for equalities (Dimension: neq * nae)
[in]bematright-hand side for equalities (Dimension: nae)
[in]aimatMatrix rectangular for inequalities (Dimension: neq * nai)
[in]bimatright-hand side for inequalities (Dimension: nai)
[in,out]xmatsolution of the linear system with constraints (neq)

REMARKS: The initial xmat has to be satisfied by all the constraints.

◆ mustBeSymmetric()

bool MatrixSymmetric::mustBeSymmetric ( ) const
inlinefinalvirtual

ICloneable interface.

Interface to AMatrix

Reimplemented from MatrixSquare.

◆ normMatrix()

void MatrixSymmetric::normMatrix ( const AMatrix y,
const MatrixSquare x = MatrixSquare(),
bool  transpose = false 
)

Perform the product: this = t(Y) %*% X %*% Y (T=false) or Y % X %*% t(Y) (T=true)

Parameters
yMatrix (possibly rectangular)
xSquare matrix (optional)
transposetransposition flag (T in the description)
Remarks
The number of rows of Y must be equal to the dimension of X
The output matrix is square with dimension equal to the number of columns of Y

◆ operator=()

MatrixSymmetric & MatrixSymmetric::operator= ( const MatrixSymmetric m)

◆ resetFromVVD()

void MatrixSymmetric::resetFromVVD ( const VectorVectorDouble tab,
bool  byCol = true 
)
overridevirtual

Reset the matrix from an array of double values.

Parameters
tabThe array of values
byColTrue if values are column-major in the array

Reimplemented from MatrixSquare.

◆ sample()

MatrixSymmetric * MatrixSymmetric::sample ( const MatrixSymmetric A,
const VectorInt rowKeep,
bool  flagInvert = false 
)
static

Create an output Square Symmetric Matrix by selecting some rows (and columns) of the Input matrix 'A'.

Parameters
AInput Square Symmetric Matrix
rowKeepSet of Rows (same for columns) to be kept
flagInvertwhen True, transform 'rowKeep' into 'rowDrop'
Returns
Pointer to the newly created Square Symmetric Matrix

Member Data Documentation

◆ DECLARE_TOTL

MatrixSymmetric::DECLARE_TOTL

Has a specific implementation in the Target language.


The documentation for this class was generated from the following files: