ARTS  2.3.1285(git:92a29ea9-dirty)
CovarianceMatrix Class Reference

#include <covariance_matrix.h>

Public Member Functions

 CovarianceMatrix ()=default
 
 CovarianceMatrix (const CovarianceMatrix &)=default
 
 CovarianceMatrix (CovarianceMatrix &&)=default
 
CovarianceMatrixoperator= (const CovarianceMatrix &)=default
 
CovarianceMatrixoperator= (CovarianceMatrix &&)=default
 
 ~CovarianceMatrix ()=default
 
 operator Matrix () const
 
Matrix get_inverse () const
 
Index nrows () const
 
Index ncols () const
 
Index ndiagblocks () const
 ! The number of diagonal blocks in the matrix excluding inverses. More...
 
Index nblocks () const
 ! The number of blocks in the matrix excluding inverses. More...
 
bool has_block (Index i, Index j)
 Check if the block with indices (i, j) is contained in the covariance matrix. More...
 
const Blockget_block (Index i=-1, Index j=-1)
 Return a pointer to the block with indices (i,j). More...
 
std::vector< Block > & get_blocks ()
 Block in the covariance matrix. More...
 
std::vector< Block > & get_inverse_blocks ()
 Blocks of the inverse covariance matrix. More...
 
bool has_diagonal_blocks (const ArrayOfArrayOfIndex &jis) const
 Checks that the covariance matrix contains one diagonal block per retrieval quantity. More...
 
bool is_consistent (const ArrayOfArrayOfIndex &jis) const
 Checks that the dimensions of the blocks in the covariance matrix are consistent with ranges occupied by the different retrieval quantities in the state vector. More...
 
bool is_consistent (const Block &block) const
 This method checks whether a block is consistent with existing blocks in the covariance matrix, i.e. More...
 
void compute_inverse () const
 Compute the inverse of this correlation matrix. More...
 
void add_correlation (Block c)
 Add block to covariance matrix. More...
 
void add_correlation_inverse (Block c)
 Add block inverse to covariance matrix. More...
 
Vector diagonal () const
 Diagonal elements as vector. More...
 
Vector inverse_diagonal () const
 Diagonal of the inverse of the covariance matrix as vector. More...
 

Private Member Functions

void generate_blocks (std::vector< std::vector< const Block *>> &) const
 
void invert_correlation_block (std::vector< Block > &inverses, std::vector< const Block *> &blocks) const
 
bool has_inverse (IndexPair indices) const
 

Private Attributes

std::vector< Blockcorrelations_
 
std::vector< Blockinverses_
 

Friends

void mult (MatrixView, ConstMatrixView, const CovarianceMatrix &)
 
void mult (MatrixView, const CovarianceMatrix &, ConstMatrixView)
 
void mult (VectorView, const CovarianceMatrix &, ConstVectorView)
 
void mult_inv (MatrixView, ConstMatrixView, const CovarianceMatrix &)
 
void mult_inv (MatrixView, const CovarianceMatrix &, ConstMatrixView)
 
void solve (VectorView, const CovarianceMatrix &, ConstVectorView)
 
MatrixViewoperator+= (MatrixView &, const CovarianceMatrix &)
 
void add_inv (MatrixView, const CovarianceMatrix &)
 
void xml_read_from_stream (istream &, CovarianceMatrix &, bifstream *, const Verbosity &)
 Reads CovarianceMatrix from XML input stream. More...
 
void xml_write_to_stream (ostream &, const CovarianceMatrix &, bofstream *, const String &, const Verbosity &)
 Write CovarianceMatrix to XML output stream. More...
 
std::ostream & operator<< (std::ostream &os, const CovarianceMatrix &v)
 

Detailed Description

A Covariance Matrix

This class represents correlations between retrieval quantities in the form of a covariance matrix. The covariance matrix is represented by a vector of blocks that describe the correlations between the retrieval quantities.

A block in a covariance matrix is identified by its block-row and block-column indices. The block-row i is defined by the row of blocks that contains the ith diagonal block. Similarly, the block-column j is defined as the column of block that contains the jth diagonal block.

The covariance matrix class implements overloads for the common ARTS operations for multiplication by matrices and vectors as well as adding covariance matrices to other matrices.

Computing inverses of covariance matrices is handled indirectly by providing mult_inv methods that multiply the inverse of the covariance matrix by a given vector or matrix. This, however, requires previously having computed the inverse of the matrix using the compute_inverse method.

Definition at line 226 of file covariance_matrix.h.

Constructor & Destructor Documentation

◆ CovarianceMatrix() [1/3]

CovarianceMatrix::CovarianceMatrix ( )
default

◆ CovarianceMatrix() [2/3]

CovarianceMatrix::CovarianceMatrix ( const CovarianceMatrix )
default

◆ CovarianceMatrix() [3/3]

CovarianceMatrix::CovarianceMatrix ( CovarianceMatrix &&  )
default

◆ ~CovarianceMatrix()

CovarianceMatrix::~CovarianceMatrix ( )
default

Member Function Documentation

◆ add_correlation()

void CovarianceMatrix::add_correlation ( Block  c)

Add block to covariance matrix.

This function add a given block to the covariance matrix. If this block is not consistent with other blocks in the matrix an error will be thrown.

Parameters
cThe block to add to the covariance matrix

Definition at line 510 of file covariance_matrix.cc.

Referenced by add_scalar_variance(), check_and_add_block(), covmat_seAddBlock(), covmat_sxAddBlock(), and setCovarianceMatrix().

◆ add_correlation_inverse()

void CovarianceMatrix::add_correlation_inverse ( Block  c)

Add block inverse to covariance matrix.

This function adds the inverse of a given block to a covariance matrix. An error will be thrown if the corresponding non-inverse block is not already in the covariance matrix.

Parameters
cThe inverse of a block already in the matrix.

Definition at line 512 of file covariance_matrix.cc.

Referenced by add_scalar_variance(), check_and_add_block(), covmat_seAddInverseBlock(), and covmat_sxAddInverseBlock().

◆ compute_inverse()

void CovarianceMatrix::compute_inverse ( ) const

Compute the inverse of this correlation matrix.

This function must be executed after all block have been added to the covariance matrix and before any of the mult_inv or add_inv methods is used.

Definition at line 391 of file covariance_matrix.cc.

References generate_blocks(), inverses_, and invert_correlation_block().

Referenced by inverse_diagonal(), and x2artsSpectroscopy().

◆ diagonal()

Vector CovarianceMatrix::diagonal ( ) const

Diagonal elements as vector.

Extracts the diagonal elements from the covariance matrix. matrix.

Returns
A vector containing the diagonal elements.

Definition at line 516 of file covariance_matrix.cc.

References correlations_, i, and nrows().

Referenced by covmat_sxExtractSqrtDiagonal().

◆ generate_blocks()

void CovarianceMatrix::generate_blocks ( std::vector< std::vector< const Block *>> &  corr_blocks) const
private

Definition at line 347 of file covariance_matrix.cc.

References correlations_, and i.

Referenced by compute_inverse().

◆ get_block()

const Block * CovarianceMatrix::get_block ( Index  i = -1,
Index  j = -1 
)

Return a pointer to the block with indices (i,j).

If any of i or j is less than zero, than the first block found in this row or column is returned. This is useful for obtaining the element range corresponding to a given block row or column range.

Parameters
iThe block-row index of the block to return or -1.
jThe block-column index of the block to return or -1.
Returns
A pointer to the block at (i,j) or nullptr if this block doesn't exist.

Definition at line 252 of file covariance_matrix.cc.

References correlations_, and swap().

Referenced by covmat_seAddBlock(), and covmat_seAddInverseBlock().

◆ get_blocks()

std::vector<Block>& CovarianceMatrix::get_blocks ( )
inline

Block in the covariance matrix.

Returns
Reference to the std::vector holding the block objects of this covariance matrix.

Definition at line 276 of file covariance_matrix.h.

Referenced by get_covariance_matrix_block().

◆ get_inverse()

Matrix CovarianceMatrix::get_inverse ( ) const

Definition at line 172 of file covariance_matrix.cc.

References n, and nrows().

◆ get_inverse_blocks()

std::vector<Block>& CovarianceMatrix::get_inverse_blocks ( )
inline

Blocks of the inverse covariance matrix.

Returns
Reference to the std::vector holding the blocks objects of the inverse of the covariance matrix.

Definition at line 283 of file covariance_matrix.h.

Referenced by get_covariance_matrix_block().

◆ has_block()

bool CovarianceMatrix::has_block ( Index  i,
Index  j 
)

Check if the block with indices (i, j) is contained in the covariance matrix.

Parameters
ithe block-row index
jthe block-column index

Definition at line 239 of file covariance_matrix.cc.

References correlations_, and swap().

Referenced by covmat_seAddBlock(), and covmat_sxAddInverseBlock().

◆ has_diagonal_blocks()

bool CovarianceMatrix::has_diagonal_blocks ( const ArrayOfArrayOfIndex jis) const

Checks that the covariance matrix contains one diagonal block per retrieval quantity.

TODO: This should be moved to m_retrieval

Parameters
jisThe ArrayOfArrayOfIndex containing the first and last indices of each retrieval quantity in the state vector.
Returns
true if the covariance matrix contains a diagonal block for each retrieval quantity

Definition at line 267 of file covariance_matrix.cc.

References correlations_, and i.

Referenced by retrievalDefClose().

◆ has_inverse()

bool CovarianceMatrix::has_inverse ( IndexPair  indices) const
private

Definition at line 338 of file covariance_matrix.cc.

References inverses_.

Referenced by invert_correlation_block(), and operator<<().

◆ inverse_diagonal()

Vector CovarianceMatrix::inverse_diagonal ( ) const

Diagonal of the inverse of the covariance matrix as vector.

Extracts the diagonal elements from the inverse of the covariance matrix. This can trigger the computation of the inverse of the matrix, if it has not been provided by the user.

Returns
A vector containing the diagonal elements.

Definition at line 529 of file covariance_matrix.cc.

References compute_inverse(), i, inverses_, and nrows().

◆ invert_correlation_block()

void CovarianceMatrix::invert_correlation_block ( std::vector< Block > &  inverses,
std::vector< const Block *> &  blocks 
) const
private

Definition at line 399 of file covariance_matrix.cc.

References a1, a2, b1, b2, Block::dense, Block::get_indices(), has_inverse(), i, inv(), and n.

Referenced by compute_inverse().

◆ is_consistent() [1/2]

bool CovarianceMatrix::is_consistent ( const ArrayOfArrayOfIndex jis) const

Checks that the dimensions of the blocks in the covariance matrix are consistent with ranges occupied by the different retrieval quantities in the state vector.

TODO: This should be moved to m_retrieval

Parameters
jisThe ArrayOfArrayOfIndex containing the first and last indices of each retrieval quantity in the state vector.
Returns
true if the covariance matrix contains a diagonal block for each retrieval quantity

Definition at line 283 of file covariance_matrix.cc.

References correlations_, Range::get_extent(), Range::get_start(), i, and inverses_.

Referenced by retrievalDefClose().

◆ is_consistent() [2/2]

bool CovarianceMatrix::is_consistent ( const Block block) const

This method checks whether a block is consistent with existing blocks in the covariance matrix, i.e.

that there is no other block in the given row i (colum j) that has a different number of rows (columns) than the given block.

Parameters
blockThe block for which to check consistent
Returns
true if the block is consistent with the other block contained in the matrix

Definition at line 315 of file covariance_matrix.cc.

References Block::get_indices(), and i.

◆ nblocks()

Index CovarianceMatrix::nblocks ( ) const

! The number of blocks in the matrix excluding inverses.

Definition at line 237 of file covariance_matrix.cc.

References correlations_.

◆ ncols()

Index CovarianceMatrix::ncols ( ) const

Definition at line 222 of file covariance_matrix.cc.

References nrows().

Referenced by OEM_checks(), operator<<(), and test_workspace_methods().

◆ ndiagblocks()

Index CovarianceMatrix::ndiagblocks ( ) const

! The number of diagonal blocks in the matrix excluding inverses.

Definition at line 224 of file covariance_matrix.cc.

Referenced by covmat_seAddBlock(), covmat_seAddInverseBlock(), and covmat_sxAddBlock().

◆ nrows()

◆ operator Matrix()

CovarianceMatrix::operator Matrix ( ) const
explicit

Definition at line 145 of file covariance_matrix.cc.

References n.

◆ operator=() [1/2]

CovarianceMatrix& CovarianceMatrix::operator= ( const CovarianceMatrix )
default

◆ operator=() [2/2]

CovarianceMatrix& CovarianceMatrix::operator= ( CovarianceMatrix &&  )
default

Friends And Related Function Documentation

◆ add_inv

void add_inv ( MatrixView  ,
const CovarianceMatrix  
)
friend

Definition at line 611 of file covariance_matrix.cc.

◆ mult [1/3]

void mult ( MatrixView  ,
ConstMatrixView  ,
const CovarianceMatrix  
)
friend

Definition at line 544 of file covariance_matrix.cc.

◆ mult [2/3]

void mult ( MatrixView  ,
const CovarianceMatrix ,
ConstMatrixView   
)
friend

Definition at line 554 of file covariance_matrix.cc.

◆ mult [3/3]

void mult ( VectorView  ,
const CovarianceMatrix ,
ConstVectorView   
)
friend

Definition at line 564 of file covariance_matrix.cc.

◆ mult_inv [1/2]

void mult_inv ( MatrixView  ,
ConstMatrixView  ,
const CovarianceMatrix  
)
friend

Definition at line 574 of file covariance_matrix.cc.

◆ mult_inv [2/2]

void mult_inv ( MatrixView  ,
const CovarianceMatrix ,
ConstMatrixView   
)
friend

Definition at line 584 of file covariance_matrix.cc.

◆ operator+=

MatrixView& operator+= ( MatrixView ,
const CovarianceMatrix  
)
friend

Definition at line 604 of file covariance_matrix.cc.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const CovarianceMatrix v 
)
friend

Definition at line 617 of file covariance_matrix.cc.

◆ solve

void solve ( VectorView  ,
const CovarianceMatrix ,
ConstVectorView   
)
friend

Definition at line 594 of file covariance_matrix.cc.

◆ xml_read_from_stream

void xml_read_from_stream ( istream &  is_xml,
CovarianceMatrix covmat,
bifstream pbifs,
const Verbosity verbosity 
)
friend

Reads CovarianceMatrix from XML input stream.

Parameters
is_xmlXML Input stream
covmatCovarianceMatrix
pbifsPointer to binary file stream. NULL for ASCII output.
verbosity

Definition at line 129 of file xml_io_compound_types.cc.

◆ xml_write_to_stream

void xml_write_to_stream ( ostream &  os_xml,
const CovarianceMatrix covmat,
bofstream pbofs,
const String name,
const Verbosity verbosity 
)
friend

Write CovarianceMatrix to XML output stream.

Parameters
os_xmlXML output stream
covmatCovarianceMatrix
pbofsPointer to binary file stream. NULL for ASCII output.
nameUnused
verbosity

Definition at line 208 of file xml_io_compound_types.cc.

Member Data Documentation

◆ correlations_

std::vector<Block> CovarianceMatrix::correlations_
private

◆ inverses_

std::vector<Block> CovarianceMatrix::inverses_
mutableprivate

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