1.3.2
CCC
 
MatrixSquareSymmetric Class Reference

#include <MatrixSquareSymmetric.hpp>

Inheritance diagram for MatrixSquareSymmetric:
AMatrixSquare MatrixRectangular AMatrixDense AMatrix AStringable ICloneable

Detailed Description

Square Symmetric matrices

Public Member Functions

 MatrixSquareSymmetric (int nrow=0)
 
 MatrixSquareSymmetric (const MatrixSquareSymmetric &m)
 
 MatrixSquareSymmetric (const AMatrix &m)
 
MatrixSquareSymmetricoperator= (const MatrixSquareSymmetric &r)
 
virtual ~MatrixSquareSymmetric ()
 
bool mustBeSymmetric () const final
 ICloneable interface. More...
 
bool isSymmetric (bool printWhyNot=false, double eps=EPSILON10) const final
 Is the matrix symmetrical ? More...
 
void normMatrix (const AMatrix &y, const AMatrixSquare &x=AMatrixSquare(), bool transpose=false)
 
int computeEigen (bool optionPositive=true)
 
int computeGeneralizedEigen (const MatrixSquareSymmetric &b, bool optionPositive=true)
 
int computeGeneralizedInverse (MatrixSquareSymmetric &tabout, double maxicond=1.e20, double eps=EPSILON20)
 
bool isDefinitePositive ()
 
int minimizeWithConstraintsInPlace (const VectorDouble &gmat, const MatrixRectangular &aemat, const VectorDouble &bemat, const MatrixRectangular &aimat, const VectorDouble &bimat, VectorDouble &xmat)
 
int getTriangleSize () const
 
int computeCholesky ()
 
int invertCholesky ()
 
int solveCholeskyMat (const MatrixRectangular &b, MatrixRectangular &x)
 
int solveCholesky (const VectorDouble &b, VectorDouble &x)
 
VectorDouble getCholeskyTL () const
 
VectorDouble getCholeskyXL () const
 
MatrixRectangular productCholeskyInPlace (int mode, int neq, int nrhs, const VectorDouble &tl, const MatrixRectangular &a)
 
MatrixSquareSymmetric normCholeskyInPlace (int mode, int neq, const VectorDouble &tl, const MatrixSquareSymmetric &a)
 
double computeCholeskyLogDeterminant () const
 
virtual bool _isPhysicallyPresent (int irow, int icol) const override
 
virtual void _setValues (const double *values, bool byCol=true) override
 
virtual int _invert () override
 
void _recopy (const MatrixSquareSymmetric &r)
 
int _matrix_qo (const VectorDouble &gmat, VectorDouble &xmat)
 
int _matrix_qoc (bool flag_invert, const VectorDouble &gmat, int na, const MatrixRectangular &amat, const VectorDouble &bmat, VectorDouble &xmat, VectorDouble &lambda)
 
int _constraintsError (const VectorInt &active, const MatrixRectangular &aimat, const VectorDouble &bimat, const VectorDouble &xmat, VectorDouble &vmat, VectorInt &flag)
 
int _constraintsConcatenateMat (int nae, int nai, int neq, const VectorInt &active, const MatrixRectangular &tabemat, const MatrixRectangular &tabimat, MatrixRectangular &tabout)
 
int _constraintsConcatenateVD (int nae, int nai, const VectorInt &active, const VectorDouble &tabemat, const VectorDouble &tabimat, VectorDouble &tabout)
 
int _constraintsCount (int nai, VectorInt &active)
 
bool _checkCholeskyAlreadyPerformed (int status) const
 
int _terminateEigen (const VectorDouble &eigenValues, const VectorDouble &eigenVectors, bool optionPositive=true, bool changeOrder=false)
 
- Public Member Functions inherited from AMatrixSquare
 AMatrixSquare (int nrow=0)
 
 AMatrixSquare (const AMatrixSquare &m)
 
 AMatrixSquare (const AMatrix &m)
 
AMatrixSquareoperator= (const AMatrixSquare &r)
 
virtual ~AMatrixSquare ()
 
virtual double determinant (void) const
 Interface for AMatrix. More...
 
bool isSquare (bool printWhyNot=false) const override
 
int getNSize () const
 
double trace () const
 
void innerMatrix (const AMatrixSquare &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)
 
- Public Member Functions inherited from MatrixRectangular
 MatrixRectangular (int nrow=0, int ncol=0)
 
 MatrixRectangular (const MatrixRectangular &m)
 
 MatrixRectangular (const AMatrix &m)
 
MatrixRectangularoperator= (const MatrixRectangular &r)
 
virtual ~MatrixRectangular ()
 
void addRow (int nrow_added=1)
 
void addColumn (int ncolumn_added=1)
 
- Public Member Functions inherited from AMatrixDense
 AMatrixDense (int nrow=0, int ncol=0)
 
 AMatrixDense (const AMatrixDense &m)
 
 AMatrixDense (const AMatrix &m)
 
AMatrixDenseoperator= (const AMatrixDense &r)
 
virtual ~AMatrixDense ()
 
bool isDense () const override
 Interface for AMatrix. More...
 
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) override
 
virtual void setRow (int irow, const VectorDouble &tab) override
 
virtual void setDiagonal (const VectorDouble &tab) 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
 
virtual void prodMatMatInPlace (const AMatrix *x, const AMatrix *y, bool transposeX=false, bool transposeY=false) override
 
void addMatInPlace (const AMatrixDense &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). More...
 
virtual void prodNormMatMatInPlace (const AMatrixDense &a, const AMatrixDense &m, bool transpose=false)
 
virtual void prodNormMatInPlace (const AMatrixDense &a, const VectorDouble &vec=VectorDouble(), bool transpose=false)
 
VectorDouble getEigenValues () const
 
const MatrixSquareGeneralgetEigenVectors () const
 
- 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. More...
 
virtual void resetFromArray (int nrows, int ncols, const double *tab, bool byCol=true)
 Reset the matrix from an array of double values. More...
 
virtual void resetFromVD (int nrows, int ncols, const VectorDouble &tab, bool byCol=true)
 Reset the matrix from a vector of double values. More...
 
virtual void resetFromVVD (const VectorVectorDouble &tab, bool byCol=true)
 Reset the matrix from an array of double values. More...
 
virtual String toString (const AStringFormat *strfmt=nullptr) const override
 Interface to AStringable. More...
 
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 prodNormMatInPlace (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) More...
 
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 getNumberColumnDefined () const
 
int getNumberRowDefined () const
 
bool isNonNegative (bool verbose=false)
 
void prodMatVecInPlace (const VectorDouble &x, VectorDouble &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 setIdentity (double value=1.)
 
void fillRandom (int seed=432432, double zeroPercent=0.1)
 
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 &activeRows, const VectorInt &activeCols)
 
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 operator() (int row, int col) const
 
double & operator() (int row, int col)
 
- 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 MatrixSquareSymmetriccreateFromVVD (const VectorVectorDouble &X)
 
static MatrixSquareSymmetriccreateFromVD (const VectorDouble &X, int nrow)
 
static MatrixSquareSymmetriccreateFromTLTU (int neq, const VectorDouble &tl)
 
static MatrixSquareSymmetriccreateFromTriangle (int mode, int neq, const VectorDouble &tl)
 
- Static Public Member Functions inherited from MatrixRectangular
static MatrixRectangularcreateFromVVD (const VectorVectorDouble &X)
 
static MatrixRectangularcreateFromVD (const VectorDouble &X, int nrow, int ncol, bool byCol=false, bool invertColumnOrder=false)
 
static MatrixRectangularglue (const AMatrix *A1, const AMatrix *A2, bool flagShiftRow, bool flagShiftCol)
 

Public Attributes

 DECLARE_TOTL
 Has a specific implementation in the Target language. More...
 
- Public Attributes inherited from MatrixRectangular
 DECLARE_TOTL
 Has a specific implementation in the Target language. More...
 

Constructor & Destructor Documentation

◆ MatrixSquareSymmetric() [1/3]

MatrixSquareSymmetric::MatrixSquareSymmetric ( int  nrow = 0)

◆ MatrixSquareSymmetric() [2/3]

MatrixSquareSymmetric::MatrixSquareSymmetric ( const MatrixSquareSymmetric m)

◆ MatrixSquareSymmetric() [3/3]

MatrixSquareSymmetric::MatrixSquareSymmetric ( const AMatrix m)

◆ ~MatrixSquareSymmetric()

MatrixSquareSymmetric::~MatrixSquareSymmetric ( )
virtual

Member Function Documentation

◆ _checkCholeskyAlreadyPerformed()

bool MatrixSquareSymmetric::_checkCholeskyAlreadyPerformed ( int  status) const

◆ _constraintsConcatenateMat()

int MatrixSquareSymmetric::_constraintsConcatenateMat ( int  nae,
int  nai,
int  neq,
const VectorInt active,
const MatrixRectangular tabemat,
const MatrixRectangular tabimat,
MatrixRectangular tabout 
)

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 MatrixSquareSymmetric::_constraintsConcatenateVD ( int  nae,
int  nai,
const VectorInt active,
const VectorDouble tabemat,
const VectorDouble tabimat,
VectorDouble tabout 
)

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 MatrixSquareSymmetric::_constraintsCount ( int  nai,
VectorInt active 
)

Count the number of active constraints

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

◆ _constraintsError()

int MatrixSquareSymmetric::_constraintsError ( const VectorInt active,
const MatrixRectangular 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 MatrixSquareSymmetric::_invert ( )
overridevirtual

Reimplemented from AMatrixDense.

◆ _isPhysicallyPresent()

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

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

Reimplemented from AMatrix.

◆ _matrix_qo()

int MatrixSquareSymmetric::_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 MatrixSquareSymmetric::_matrix_qoc ( bool  flag_invert,
const VectorDouble gmat,
int  na,
const MatrixRectangular 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

◆ _recopy()

void MatrixSquareSymmetric::_recopy ( const MatrixSquareSymmetric r)

◆ _setValues()

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

Reimplemented from AMatrix.

◆ _terminateEigen()

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

◆ computeCholesky()

int MatrixSquareSymmetric::computeCholesky ( )

Performs the Cholesky triangular decomposition of a definite positive symmetric matrix A = t(TL) * TL

Returns
Error return code

◆ computeCholeskyLogDeterminant()

double MatrixSquareSymmetric::computeCholeskyLogDeterminant ( ) const

◆ computeEigen()

int MatrixSquareSymmetric::computeEigen ( bool  optionPositive = true)

◆ computeGeneralizedEigen()

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

◆ computeGeneralizedInverse()

int MatrixSquareSymmetric::computeGeneralizedInverse ( MatrixSquareSymmetric 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()

MatrixSquareSymmetric * MatrixSquareSymmetric::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()

MatrixSquareSymmetric * MatrixSquareSymmetric::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 (lower part)

◆ createFromVD()

MatrixSquareSymmetric * MatrixSquareSymmetric::createFromVD ( const VectorDouble X,
int  nrow 
)
static

◆ createFromVVD()

MatrixSquareSymmetric * MatrixSquareSymmetric::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

◆ getCholeskyTL()

VectorDouble MatrixSquareSymmetric::getCholeskyTL ( ) const

◆ getCholeskyXL()

VectorDouble MatrixSquareSymmetric::getCholeskyXL ( ) const

◆ getTriangleSize()

int MatrixSquareSymmetric::getTriangleSize ( ) const

◆ invertCholesky()

int MatrixSquareSymmetric::invertCholesky ( )

Invert the Cholesky matrix

◆ isDefinitePositive()

bool MatrixSquareSymmetric::isDefinitePositive ( )

Check if a matrix is definite positive

Returns
True if the matrix is definite positive; False otherwise

◆ isSymmetric()

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

Is the matrix symmetrical ?

Reimplemented from AMatrix.

◆ minimizeWithConstraintsInPlace()

int MatrixSquareSymmetric::minimizeWithConstraintsInPlace ( const VectorDouble gmat,
const MatrixRectangular aemat,
const VectorDouble bemat,
const MatrixRectangular 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 MatrixSquareSymmetric::mustBeSymmetric ( ) const
inlinefinalvirtual

ICloneable interface.

Interface to AMatrix

Say if the matrix must be symmetric

Reimplemented from MatrixRectangular.

◆ normCholeskyInPlace()

MatrixSquareSymmetric MatrixSquareSymmetric::normCholeskyInPlace ( int  mode,
int  neq,
const VectorDouble tl,
const MatrixSquareSymmetric a 
)

Performs the product B = TL * A * TU or TU * A * TL where TL,TU is a triangular matrix and A a square symmetric matrix

Parameters
[in]mode0: TL * A * TU; 1: TU * A * TL
[in]neqnumber of equations in the system
[in]tlTriangular matrix defined by column
[in]aSquare symmetric matrix (optional)

◆ normMatrix()

void MatrixSquareSymmetric::normMatrix ( const AMatrix y,
const AMatrixSquare x = AMatrixSquare(),
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=()

MatrixSquareSymmetric & MatrixSquareSymmetric::operator= ( const MatrixSquareSymmetric r)

◆ productCholeskyInPlace()

MatrixRectangular MatrixSquareSymmetric::productCholeskyInPlace ( int  mode,
int  neq,
int  nrhs,
const VectorDouble tl,
const MatrixRectangular a 
)

Performs the product between a triangular and a square matrix TL is the lower triangular matrix and X is a square matrix

Parameters
[in]modeType of calculations: 0 : X=TU%*A 1 : X=TL%*A 2 : X=A%*TU 3 : X=A%*TL 4 : X=t(A)%*TU 5 : X=t(A)%*TL
[in]neqnumber of equations in the system
[in]nrhsnumber of columns in x
[in]tlTriangular matrix defined by column
[in]amatrix (dimension neq * nrhs)

◆ solveCholesky()

int MatrixSquareSymmetric::solveCholesky ( const VectorDouble b,
VectorDouble x 
)

◆ solveCholeskyMat()

int MatrixSquareSymmetric::solveCholeskyMat ( const MatrixRectangular b,
MatrixRectangular x 
)

Member Data Documentation

◆ DECLARE_TOTL

MatrixSquareSymmetric::DECLARE_TOTL

Has a specific implementation in the Target language.


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