ARTS 2.5.11 (git: 6827797f)
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.

Index ninvdiagblocks () const
! The number of inverse diagonal blocks in the matrix.

Index nblocks () const
! The number of blocks in the matrix excluding inverses.

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

const Blockget_block (Index i=-1, Index j=-1)
Return a pointer to the block with indices (i,j).

std::vector< Block > & get_blocks ()
Block in the covariance matrix.

std::vector< Block > & get_inverse_blocks ()
Blocks of the inverse covariance matrix.

bool has_diagonal_blocks (const ArrayOfArrayOfIndex &jis) const
Checks that the covariance matrix contains one diagonal block per retrieval quantity.

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.

bool is_consistent (const Block &block) const
This method checks whether a block is consistent with existing blocks in the covariance matrix, i.e.

void compute_inverse () const
Compute the inverse of this correlation matrix.

Add block inverse to covariance matrix.

Vector diagonal () const
Diagonal elements as vector.

Vector inverse_diagonal () const
Diagonal of the inverse of the covariance matrix as vector.

## 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)

MatrixView operator+= (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.

void xml_write_to_stream (ostream &, const CovarianceMatrix &, bofstream *, const String &, const Verbosity &)
Write CovarianceMatrix to XML output stream.

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 210 of file covariance_matrix.h.

## ◆ 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

 void CovarianceMatrix::add_correlation ( Block c )

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
 c The block to add to the covariance matrix

Definition at line 507 of file covariance_matrix.cc.

References c, and correlations_.

 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
 c The inverse of a block already in the matrix.

Definition at line 509 of file covariance_matrix.cc.

References c, and inverses_.

## ◆ 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 388 of file covariance_matrix.cc.

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

Referenced by inverse_diagonal().

## ◆ 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 513 of file covariance_matrix.cc.

References b, correlations_, 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 344 of file covariance_matrix.cc.

References correlations_.

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
 i The block-row index of the block to return or -1. j The 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 249 of file covariance_matrix.cc.

References b, and correlations_.

## ◆ 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 263 of file covariance_matrix.h.

References correlations_.

## ◆ get_inverse()

 Matrix CovarianceMatrix::get_inverse ( ) const

Definition at line 156 of file covariance_matrix.cc.

References c, Block::dense, inverses_, 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 270 of file covariance_matrix.h.

References inverses_.

## ◆ 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
 i the block-row index j the block-column index

Definition at line 236 of file covariance_matrix.cc.

References b, and correlations_.

## ◆ 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
 jis The 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 264 of file covariance_matrix.cc.

References b, and correlations_.

Referenced by retrievalDefClose().

## ◆ has_inverse()

 bool CovarianceMatrix::has_inverse ( IndexPair indices ) const
private

Definition at line 335 of file covariance_matrix.cc.

References b, and inverses_.

Referenced by invert_correlation_block().

## ◆ 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 526 of file covariance_matrix.cc.

References b, compute_inverse(), 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 396 of file covariance_matrix.cc.

References a, ARTS_ASSERT, b, Block::dense, and has_inverse().

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
 jis The 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 280 of file covariance_matrix.cc.

References b, correlations_, 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
 block The block for which to check consistent
Returns
true if the block is consistent with the other block contained in the matrix

Definition at line 312 of file covariance_matrix.cc.

References b, c, and correlations_.

## ◆ nblocks()

 Index CovarianceMatrix::nblocks ( ) const

! The number of blocks in the matrix excluding inverses.

Definition at line 234 of file covariance_matrix.cc.

References correlations_.

## ◆ ncols()

 Index CovarianceMatrix::ncols ( ) const

Definition at line 206 of file covariance_matrix.cc.

References nrows().

## ◆ ndiagblocks()

 Index CovarianceMatrix::ndiagblocks ( ) const

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

Definition at line 208 of file covariance_matrix.cc.

References c, and correlations_.

## ◆ ninvdiagblocks()

 Index CovarianceMatrix::ninvdiagblocks ( ) const

! The number of inverse diagonal blocks in the matrix.

Definition at line 221 of file covariance_matrix.cc.

References c, and inverses_.

## ◆ nrows()

 Index CovarianceMatrix::nrows ( ) const

Definition at line 183 of file covariance_matrix.cc.

References c, correlations_, and inverses_.

## ◆ operator Matrix()

 CovarianceMatrix::operator Matrix ( ) const
explicit

Definition at line 129 of file covariance_matrix.cc.

References c, and Block::dense.

## ◆ operator=() [1/2]

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

## ◆ operator=() [2/2]

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

## Friends And Related Function Documentation

 void add_inv ( MatrixView , const CovarianceMatrix & )
friend

Definition at line 608 of file covariance_matrix.cc.

## ◆ mult [1/3]

 void mult ( MatrixView , const CovarianceMatrix & , ConstMatrixView )
friend

Definition at line 551 of file covariance_matrix.cc.

## ◆ mult [2/3]

 void mult ( MatrixView , ConstMatrixView , const CovarianceMatrix & )
friend

Definition at line 541 of file covariance_matrix.cc.

## ◆ mult [3/3]

 void mult ( VectorView , const CovarianceMatrix & , ConstVectorView )
friend

Definition at line 561 of file covariance_matrix.cc.

## ◆ mult_inv [1/2]

 void mult_inv ( MatrixView , const CovarianceMatrix & , ConstMatrixView )
friend

Definition at line 581 of file covariance_matrix.cc.

## ◆ mult_inv [2/2]

 void mult_inv ( MatrixView , ConstMatrixView , const CovarianceMatrix & )
friend

Definition at line 571 of file covariance_matrix.cc.

## ◆ operator+=

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

Definition at line 601 of file covariance_matrix.cc.

## ◆ operator<<

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

Definition at line 614 of file covariance_matrix.cc.

## ◆ solve

 void solve ( VectorView , const CovarianceMatrix & , ConstVectorView )
friend

Definition at line 591 of file covariance_matrix.cc.

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

Reads CovarianceMatrix from XML input stream.

Parameters
 is_xml XML Input stream covmat CovarianceMatrix pbifs Pointer to binary file stream. NULL for ASCII output. verbosity

Definition at line 105 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_xml XML output stream covmat CovarianceMatrix pbofs Pointer to binary file stream. NULL for ASCII output. name Unused verbosity

Definition at line 184 of file xml_io_compound_types.cc.

## ◆ correlations_

 std::vector CovarianceMatrix::correlations_
private

Definition at line 386 of file covariance_matrix.h.

## ◆ inverses_

 std::vector CovarianceMatrix::inverses_
mutableprivate

Definition at line 387 of file covariance_matrix.h.

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