Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
Matrix.cpp File Reference
#include "Matrix.h"
#include <gsl/gsl_errno.h>
Include dependency graph for Matrix.cpp:

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &os, RealMatrix A)
 
RealMatrix eye (std::size_t n)
 Returns the identity matrix of size n.
 
RealMatrix diag (const gsl_vector *X)
 Builds a diagonal matrix from a GSL vector.
 
RealMatrix nearest_psd (RealMatrix R, double thr)
 Projects a matrix to the nearest positive semi-definite correlation-like matrix.
 
RealMatrix cholesky_L (RealMatrix R)
 Returns the lower-triangular Cholesky factor of a PSD matrix.
 
RealMatrix block_diag (const std::vector< RealMatrix > &blocks)
 Builds a block-diagonal matrix from several square blocks.
 

Function Documentation

◆ block_diag()

RealMatrix block_diag ( const std::vector< RealMatrix > &  blocks)

Builds a block-diagonal matrix from several square blocks.

Parameters
blocksList of square matrices.
Returns
Block-diagonal concatenation of all input matrices.
Exceptions
std::invalid_argumentif one input block is not square.

Definition at line 529 of file Matrix.cpp.

◆ cholesky_L()

RealMatrix cholesky_L ( RealMatrix  R)

Returns the lower-triangular Cholesky factor of a PSD matrix.

If R = L L^T, this function returns L.

Parameters
RInput matrix.
Returns
Lower-triangular Cholesky factor.
Exceptions
std::invalid_argumentif the matrix is not square.
std::runtime_errorif Cholesky decomposition fails.

Definition at line 508 of file Matrix.cpp.

◆ diag()

RealMatrix diag ( const gsl_vector *  X)

Builds a diagonal matrix from a GSL vector.

Parameters
XInput vector.
Returns
Square diagonal matrix whose diagonal entries are the values of X.

Definition at line 464 of file Matrix.cpp.

◆ eye()

RealMatrix eye ( std::size_t  n)

Returns the identity matrix of size n.

Parameters
nMatrix dimension.
Returns
n × n identity matrix.

Definition at line 453 of file Matrix.cpp.

◆ nearest_psd()

RealMatrix nearest_psd ( RealMatrix  R,
double  thr = 1e-12 
)

Projects a matrix to the nearest positive semi-definite correlation-like matrix.

Algorithm:

  • symmetrize the input,
  • diagonalize it,
  • clip eigenvalues below thr,
  • reconstruct the matrix,
  • renormalize the diagonal to 1,
  • symmetrize again.

This is especially useful for repairing numerically inconsistent correlation matrices.

Parameters
RInput matrix.
thrLower bound applied to eigenvalues during clipping.
Returns
Positive semi-definite, unit-diagonal repaired matrix.
Exceptions
std::invalid_argumentif the matrix is not square.

Definition at line 475 of file Matrix.cpp.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
RealMatrix  A 
)

Prints the matrix in a nested bracket form.

Parameters
osOutput stream.
AMatrix to print.
Returns
Output stream.

Definition at line 439 of file Matrix.cpp.