libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | List of all members
crn::SquareMatrixDouble Class Reference

Square double matrix class. More...

#include <CRNSquareMatrixDouble.h>

+ Inheritance diagram for crn::SquareMatrixDouble:
+ Collaboration diagram for crn::SquareMatrixDouble:

Public Member Functions

 SquareMatrixDouble (size_t size, double value=0.0)
 Constructor. More...
 
 SquareMatrixDouble (const Matrix< double > &m)
 
 SquareMatrixDouble (Matrix< double > &&m)
 
 SquareMatrixDouble (const std::vector< std::vector< double >> &m)
 
 SquareMatrixDouble (std::vector< std::vector< double >> &&m)
 
 SquareMatrixDouble (const SquareMatrixDouble &)=default
 
 SquareMatrixDouble (SquareMatrixDouble &&)=default
 
virtual ~SquareMatrixDouble () override=default
 Destructor. More...
 
SquareMatrixDoubleoperator= (const SquareMatrixDouble &)=default
 
SquareMatrixDoubleoperator= (SquareMatrixDouble &&)=default
 
bool IsUpperTriangular () const
 Check if matrix is upper triangular. More...
 
bool IsLowerTriangular () const
 Check if matrix is lower triangular. More...
 
bool IsUpperHessenberg () const
 Check if matrix is upper Hessenberg. More...
 
bool IsDiagonal () const
 Check if matrix is diagonal. More...
 
double Trace () const
 Trace. More...
 
double DiagonalProduct () const
 Diagonal product. More...
 
virtual SquareMatrixDoubleTranspose () override
 Transposition. More...
 
SquareMatrixDouble MakeMinor (size_t r, size_t c) const
 Minor matrix. More...
 
double Cofactor (size_t r, size_t c) const
 Cofactor. More...
 
double Determinant () const
 Determinant. More...
 
SquareMatrixDouble MakeInverse () const
 Invert using determinants. More...
 
SquareMatrixDouble MakeGaussJordanInverse () const
 Invert using Gauss-Jordan elimination. More...
 
SquareMatrixDouble MakeCholesky () const
 Get the lower triangular factor in Cholesky decomposition. More...
 
SquareMatrixDouble MakeUpperHessenberg () const
 Get the upper Hessenberg form of matrix. More...
 
std::multimap< double,
MatrixDouble
MakeSpectralEigensystem () const
 Perform diagonalization for 2x2 symmetric matrix. More...
 
std::multimap< double,
MatrixDouble
MakeJacobiEigensystem (size_t MaxIteration=100) const
 Perform diagonalization for symmetric matrix. More...
 
std::multimap< double,
MatrixDouble
MakeTQLIEigensystem (size_t maxiter=30) const
 Perform diagonalization for positive symmetric matrix. More...
 
std::vector< std::complex
< double > > 
Eigenvalues (size_t max_iter=30) const
 Extract eigenvalues for matrix of real (eigenvalues may be complex) More...
 
 SquareMatrixDouble (xml::Element &el)
 
- Public Member Functions inherited from crn::MatrixDouble
 MatrixDouble (const Matrix< double > &m)
 
 MatrixDouble (Matrix< double > &&m)
 
 MatrixDouble (xml::Element &el)
 Defines a default constructor from xml element. More...
 
 MatrixDouble (const MatrixDouble &)=default
 
 MatrixDouble (MatrixDouble &&)=default
 
MatrixDoubleoperator= (const MatrixDouble &)=default
 
MatrixDoubleoperator= (MatrixDouble &&)=default
 
virtual ~MatrixDouble () override=default
 Destructor. More...
 
double CumulateSquaredCells () const
 Computes the sum of the squared elements. More...
 
SquareMatrixDouble MakeVectorRightAutoProduct () const
 Get the product of a column vector by its own transposed on the right side. More...
 
virtual void Deserialize (xml::Element &el)
 
virtual xml::Element Serialize (xml::Element &parent) const
 
- Public Member Functions inherited from crn::Matrix< double >
 Matrix (size_t nrow, size_t ncol, const double &value=double(0))
 Constructor. More...
 
 Matrix (const std::vector< std::vector< double >> &m)
 Constructor from std::vector matrix. More...
 
 Matrix (const std::vector< double > &vect, Orientation ori=Orientation::VERTICAL)
 Constructor from std::vector 1D vector. More...
 
 Matrix (std::vector< double > &&vect, Orientation ori=Orientation::VERTICAL)
 Constructor from std::vector 1D vector. More...
 
 Matrix (const Matrix &)=default
 
 Matrix (const Matrix< Y > &m)
 
 Matrix (Matrix &&)=default
 
virtual ~Matrix () override=default
 Destructor. More...
 
Matrixoperator= (const Matrix &)=default
 
Matrixoperator= (Matrix &&)=default
 
void Swap (Matrix &m)
 
size_t GetRows () const noexcept
 Returns the number of rows. More...
 
size_t GetCols () const noexcept
 Returns the number of columns. More...
 
const double & At (size_t pos) const noexcept
 
double & At (size_t pos) noexcept
 
const double & At (size_t r, size_t c) const noexcept
 
double & At (size_t r, size_t c) noexcept
 
void SetAll (const double &v)
 Set all elements. More...
 
void Negative ()
 Change sign for all elements. More...
 
void SetRow (size_t r, const std::vector< double > &row)
 Sets the values of a row. More...
 
void SetColum (size_t c, const std::vector< double > &col)
 Sets the values of a column. More...
 
void IncreaseElement (size_t r, size_t c, const double &delta)
 Increases the value of an element. More...
 
void IncreaseRow (size_t r, const double &v)
 Increase one row from matrix. More...
 
void IncreaseColumn (size_t c, const double &v)
 Increase one column from matrix. More...
 
Matrixoperator+= (const Matrix &m)
 
Matrixoperator-= (const Matrix &m)
 
Matrixoperator*= (const Matrix &m)
 
Matrixoperator*= (double d)
 Scaling. More...
 
bool operator== (const Matrix &m) const
 
bool operator!= (const Matrix &m) const
 
Matrixoperator/= (double d)
 Scaling. More...
 
void MultRow (size_t r, double v)
 Scale one row from matrix. More...
 
void MultColumn (size_t c, double v)
 Scale one column from matrix. More...
 
void CenterColumns ()
 Centers all columns by subtracting the mean for each column. More...
 
void ReduceColumns (bool centered=true)
 Reduces all columns by dividing by the standard deviation of each column. More...
 
void SwapRows (size_t r1, size_t r2)
 Swap two rows in matrix. More...
 
void SwapColumns (size_t c1, size_t c2)
 Swap two columns in matrix. More...
 
void NormalizeForConvolution ()
 Normalizes the matrix to be used for convolution. More...
 
TypeInfo< double >::SumType CumulateCells () const
 
double GetMin () const
 
double GetMax () const
 
std::pair< size_t, size_t > Argmin () const
 
std::pair< size_t, size_t > Argmax () const
 
Matrix MakeTranspose ()
 Create transposition. More...
 
Matrix MakeRowAsColumn (size_t r) const
 Creates a column matrix from a row. More...
 
Matrix MakeRow (size_t r) const
 Extract a row from current matrix. More...
 
Matrix MakeColumn (size_t k) const
 Extracts one column from matrix. More...
 
size_t ArgmaxInRow (size_t r) const
 Returns the row index of the maximal element in a row. More...
 
size_t ArgmaxInColumn (size_t c) const
 Returns the row index of the maximal element in a column. More...
 
size_t CountNullCellsInRow (size_t r) const
 Counts null cells in row. More...
 
size_t CountNullCellsInColumn (size_t c) const
 Counts null cells in column. More...
 
size_t CountNullCells () const
 
Matrix MakeColumnMeans () const
 
Matrix MakeColumnDeviations (const Matrix &means) const
 
Matrix MakeColumnDeviations (bool zero_means=false) const
 standard deviation of patterns stored as the rows of a data matrix More...
 
Matrix MakeCovariance () const
 
double * operator[] (size_t r)
 Returns a row. More...
 
const double * operator[] (size_t r) const
 Returns a row. More...
 
const std::vector< double > & Std () const &noexcept
 
std::vector< double > Std ()&&
 
IMG ToImage () const
 Converts to image. More...
 
String ToString () const
 Prints matrix into a string. More...
 
- Public Member Functions inherited from crn::Object
virtual ~Object ()=default
 

Static Public Member Functions

static SquareMatrixDouble NewGaussian (double sigma)
 Create Gaussian matrix. More...
 
static SquareMatrixDouble NewGaussianSobelX (double sigma)
 Create Gaussian Sobel X derivation mask. More...
 
static SquareMatrixDouble NewGaussianSobelY (double sigma)
 Create Gaussian Sobel Y derivation mask. More...
 
static SquareMatrixDouble NewIdentity (size_t n)
 Create identity matrix. More...
 
- Static Public Member Functions inherited from crn::MatrixDouble
static MatrixDouble NewGaussianLine (double sigma)
 Creates a line matrix with a centered Gaussian. More...
 
static MatrixDouble NewGaussianLineDerivative (double sigma)
 Creates a line matrix with the derivative of a centered Gaussian. More...
 
static MatrixDouble NewGaussianLineSecondDerivative (double sigma)
 Creates a line matrix with the second derivative of a centered Gaussian. More...
 

Additional Inherited Members

- Protected Types inherited from crn::Matrix< double >
using datatype = std::vector< double >
 
- Protected Member Functions inherited from crn::Matrix< double >
bool areValidIndexes (size_t r, size_t c) const
 checks the validity of indexes More...
 
- Protected Attributes inherited from crn::Matrix< double >
datatype data
 
size_t rows
 
size_t cols
 

Detailed Description

Square double matrix class.

Square matrix containing doubles

Author
Jean DUONG
Date
February 2008
Version
0.2

Definition at line 40 of file CRNSquareMatrixDouble.h.

Constructor & Destructor Documentation

crn::SquareMatrixDouble::SquareMatrixDouble ( size_t  size,
double  value = 0.0 
)
inline

Constructor.

Definition at line 44 of file CRNSquareMatrixDouble.h.

SquareMatrixDouble::SquareMatrixDouble ( const Matrix< double > &  m)

Definition at line 36 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble::SquareMatrixDouble ( Matrix< double > &&  m)

Definition at line 43 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble::SquareMatrixDouble ( const std::vector< std::vector< double >> &  m)

Definition at line 50 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble::SquareMatrixDouble ( std::vector< std::vector< double >> &&  m)

Definition at line 57 of file CRNSquareMatrixDouble.cpp.

crn::SquareMatrixDouble::SquareMatrixDouble ( const SquareMatrixDouble )
default
crn::SquareMatrixDouble::SquareMatrixDouble ( SquareMatrixDouble &&  )
default
virtual crn::SquareMatrixDouble::~SquareMatrixDouble ( )
overridevirtualdefault

Destructor.

crn::SquareMatrixDouble::SquareMatrixDouble ( xml::Element el)
inline

Definition at line 115 of file CRNSquareMatrixDouble.h.

Member Function Documentation

double SquareMatrixDouble::Cofactor ( size_t  r,
size_t  c 
) const

Cofactor.

Cofactor

Exceptions
ExceptionDomainrow or column out of range
Parameters
[in]rrow index
[in]ccolumn index
Returns
the cofactor at the given row and column

Definition at line 448 of file CRNSquareMatrixDouble.cpp.

double SquareMatrixDouble::Determinant ( ) const

Determinant.

Determinant

Returns
the determinant of the matrix

Definition at line 468 of file CRNSquareMatrixDouble.cpp.

double SquareMatrixDouble::DiagonalProduct ( ) const

Diagonal product.

Product of the elements on the diagonal

Returns
the diagonal product

Definition at line 375 of file CRNSquareMatrixDouble.cpp.

std::vector< std::complex< double > > SquareMatrixDouble::Eigenvalues ( size_t  max_iter = 30) const

Extract eigenvalues for matrix of real (eigenvalues may be complex)

Finds all eigenvalues of a [1..n][1..n] upper Hessenberg matrix.

Parameters
[in]matthe input matrix
[in]max_iterthe maximal number of iterations
Returns
eigenvalues stored in a vector of complex numbers

Implementation from "Numerical Recipes in C"

Definition at line 1195 of file CRNSquareMatrixDouble.cpp.

bool SquareMatrixDouble::IsDiagonal ( ) const

Check if matrix is diagonal.

Check if matrix is diagonal

Returns
true if the matrix is diagonal

Definition at line 334 of file CRNSquareMatrixDouble.cpp.

bool SquareMatrixDouble::IsLowerTriangular ( ) const

Check if matrix is lower triangular.

Check if matrix is lower triangular

Returns
true if the matrix is lower triangular

Definition at line 282 of file CRNSquareMatrixDouble.cpp.

bool SquareMatrixDouble::IsUpperHessenberg ( ) const

Check if matrix is upper Hessenberg.

Check if matrix is upper Hessenberg

Returns
true if the matrix has upper Hessenberg form, false else

Definition at line 308 of file CRNSquareMatrixDouble.cpp.

bool SquareMatrixDouble::IsUpperTriangular ( ) const

Check if matrix is upper triangular.

Check if matrix is upper triangular

Returns
true if the matrix is upper triangular, false else

Definition at line 256 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::MakeCholesky ( ) const

Get the lower triangular factor in Cholesky decomposition.

Get the lower triangular factor in Cholesky decomposition. Matrix is supposed symetric semi-definite positive.

Property : M = L * transpose(L) with

M : the input matrix L : the lower triangular factor found

Returns
the lower triangular factor in Cholesky decomposition

Definition at line 713 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::MakeGaussJordanInverse ( ) const

Invert using Gauss-Jordan elimination.

Inversion using Gauss-Jordan elimination

Exceptions
ExceptionRuntimematrix cannot be inversed
Returns
the inverse matrix

Definition at line 610 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::MakeInverse ( ) const

Invert using determinants.

Inversion using determinants computation

Returns
the inverse matrix

Definition at line 559 of file CRNSquareMatrixDouble.cpp.

std::multimap< double, MatrixDouble > SquareMatrixDouble::MakeJacobiEigensystem ( size_t  MaxIteration = 100) const

Perform diagonalization for symmetric matrix.

Jacobi method to perform matrix diagonalization

Assumptions :

1 - Matrix is symetric 2 - Matrix has n distinct eigenvalues (n is the dimension of vector space) 2 - n > 2

Eigenpairs are returned in a multimap sorted according eigenvalues.

Returns
eigenpairs

Definition at line 893 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::MakeMinor ( size_t  r,
size_t  c 
) const

Minor matrix.

Create minor matrix

Exceptions
ExceptionDomainrow or column out of range
Parameters
[in]rrow index
[in]ccolumn index
Returns
a new matrix, less the column and row

Definition at line 406 of file CRNSquareMatrixDouble.cpp.

std::multimap< double, MatrixDouble > SquareMatrixDouble::MakeSpectralEigensystem ( ) const

Perform diagonalization for 2x2 symmetric matrix.

2x2 symetric matrix diagonalization using spectral theorem

Eigenpairs are returned in a multimap sorted according decreasing eigenvalues.

Returns
eigenpairs

Definition at line 834 of file CRNSquareMatrixDouble.cpp.

std::multimap< double, MatrixDouble > SquareMatrixDouble::MakeTQLIEigensystem ( size_t  maxiter = 30) const

Perform diagonalization for positive symmetric matrix.

Diagonalization for positive symmetric matrix

Exceptions
ExceptionRuntimetoo many iterations
Returns
eigenpairs

Definition at line 1023 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::MakeUpperHessenberg ( ) const

Get the upper Hessenberg form of matrix.

Get the upper Hessenberg form of matrix.

Returns
the upper Hessenberg form of matrix

Definition at line 756 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::NewGaussian ( double  sigma)
static

Create Gaussian matrix.

Create Gaussian matrix

Parameters
[in]sigmathe standard deviation of the Gaussian
Returns
a new matrix

Definition at line 75 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::NewGaussianSobelX ( double  sigma)
static

Create Gaussian Sobel X derivation mask.

Create Gaussian X derivation Sobel mask

Parameters
[in]sigmathe standard deviation of the Gaussian
Returns
a new matrix

Definition at line 127 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::NewGaussianSobelY ( double  sigma)
static

Create Gaussian Sobel Y derivation mask.

Create Gaussian Y derivation Sobel mask

Parameters
[in]sigmathe standard deviation of the Gaussian
Returns
a new matrix

Definition at line 193 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble SquareMatrixDouble::NewIdentity ( size_t  n)
static

Create identity matrix.

Make identity matrix

Parameters
[in]nthe dimension
Returns
a new matrix

Definition at line 587 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble& crn::SquareMatrixDouble::operator= ( const SquareMatrixDouble )
default
SquareMatrixDouble& crn::SquareMatrixDouble::operator= ( SquareMatrixDouble &&  )
default
double SquareMatrixDouble::Trace ( ) const

Trace.

Sum of the elements on the diagonal

Returns
the trace of the matrix

Definition at line 360 of file CRNSquareMatrixDouble.cpp.

SquareMatrixDouble & SquareMatrixDouble::Transpose ( )
overridevirtual

Transposition.

Transposes the matrix

Reimplemented from crn::Matrix< double >.

Definition at line 388 of file CRNSquareMatrixDouble.cpp.


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