ARTS 2.5.0 (git: 9ee3ac6c)
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 ninvdiagblocks () const
! The number of inverse diagonal blocks in the matrix. 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...

Add block to covariance matrix. More...

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 227 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 523 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 525 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 404 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 529 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 360 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 265 of file covariance_matrix.cc.

References b, correlations_, and swap().

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

References correlations_.

Referenced by get_covariance_matrix_block().

◆ get_inverse()

 Matrix CovarianceMatrix::get_inverse ( ) const

Definition at line 172 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 287 of file covariance_matrix.h.

References inverses_.

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

Definition at line 252 of file covariance_matrix.cc.

References b, correlations_, and swap().

◆ 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 280 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 351 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 542 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 412 of file covariance_matrix.cc.

References a, a1, a2, ARTS_ASSERT, b, b1, b2, Block::dense, has_inverse(), and inv().

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 296 of file covariance_matrix.cc.

References b, correlations_, Range::get_extent(), Range::get_start(), 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 328 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 250 of file covariance_matrix.cc.

References correlations_.

◆ ncols()

 Index CovarianceMatrix::ncols ( ) const

Definition at line 222 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 224 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 237 of file covariance_matrix.cc.

References c, and inverses_.

◆ nrows()

 Index CovarianceMatrix::nrows ( ) const

Definition at line 199 of file covariance_matrix.cc.

References c, correlations_, inverses_, and max.

◆ operator Matrix()

 CovarianceMatrix::operator Matrix ( ) const
explicit

Definition at line 145 of file covariance_matrix.cc.

References c, Block::dense, nrows, and transpose().

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

◆ mult [1/3]

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

Definition at line 567 of file covariance_matrix.cc.

◆ mult [2/3]

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

Definition at line 557 of file covariance_matrix.cc.

◆ mult [3/3]

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

Definition at line 577 of file covariance_matrix.cc.

◆ mult_inv [1/2]

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

Definition at line 597 of file covariance_matrix.cc.

◆ mult_inv [2/2]

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

Definition at line 587 of file covariance_matrix.cc.

◆ operator+=

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

Definition at line 617 of file covariance_matrix.cc.

◆ operator<<

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

Definition at line 630 of file covariance_matrix.cc.

◆ solve

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

Definition at line 607 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 119 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 198 of file xml_io_compound_types.cc.

◆ correlations_

 std::vector CovarianceMatrix::correlations_
private

Definition at line 403 of file covariance_matrix.h.

◆ inverses_

 std::vector CovarianceMatrix::inverses_
mutableprivate

Definition at line 404 of file covariance_matrix.h.

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