ARTS
2.3.1285(git:92a29ea9-dirty)
|
#include <covariance_matrix.h>
Public Member Functions | |
CovarianceMatrix ()=default | |
CovarianceMatrix (const CovarianceMatrix &)=default | |
CovarianceMatrix (CovarianceMatrix &&)=default | |
CovarianceMatrix & | operator= (const CovarianceMatrix &)=default |
CovarianceMatrix & | operator= (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 Block * | get_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< Block > | correlations_ |
std::vector< Block > | inverses_ |
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. 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) |
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.
|
default |
|
default |
|
default |
|
default |
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.
c | The 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().
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.
c | The 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().
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().
Vector CovarianceMatrix::diagonal | ( | ) | const |
Diagonal elements as vector.
Extracts the diagonal elements from the covariance matrix. matrix.
Definition at line 516 of file covariance_matrix.cc.
References correlations_, i, and nrows().
Referenced by covmat_sxExtractSqrtDiagonal().
|
private |
Definition at line 347 of file covariance_matrix.cc.
References correlations_, and i.
Referenced by compute_inverse().
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.
i | The block-row index of the block to return or -1. |
j | The block-column index of the block to return or -1. |
Definition at line 252 of file covariance_matrix.cc.
References correlations_, and swap().
Referenced by covmat_seAddBlock(), and covmat_seAddInverseBlock().
|
inline |
Block in the covariance matrix.
Definition at line 276 of file covariance_matrix.h.
Referenced by get_covariance_matrix_block().
Matrix CovarianceMatrix::get_inverse | ( | ) | const |
Definition at line 172 of file covariance_matrix.cc.
|
inline |
Blocks of the inverse covariance matrix.
Definition at line 283 of file covariance_matrix.h.
Referenced by get_covariance_matrix_block().
Check if the block with indices (i, j) is contained in the covariance matrix.
i | the block-row index |
j | the block-column index |
Definition at line 239 of file covariance_matrix.cc.
References correlations_, and swap().
Referenced by covmat_seAddBlock(), and covmat_sxAddInverseBlock().
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
jis | The ArrayOfArrayOfIndex containing the first and last indices of each retrieval quantity in the state vector. |
Definition at line 267 of file covariance_matrix.cc.
References correlations_, and i.
Referenced by retrievalDefClose().
|
private |
Definition at line 338 of file covariance_matrix.cc.
References inverses_.
Referenced by invert_correlation_block(), and operator<<().
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.
Definition at line 529 of file covariance_matrix.cc.
References compute_inverse(), i, inverses_, and nrows().
|
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().
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
jis | The ArrayOfArrayOfIndex containing the first and last indices of each retrieval quantity in the state vector. |
Definition at line 283 of file covariance_matrix.cc.
References correlations_, Range::get_extent(), Range::get_start(), i, and inverses_.
Referenced by retrievalDefClose().
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.
block | The block for which to check consistent |
Definition at line 315 of file covariance_matrix.cc.
References Block::get_indices(), and i.
Index CovarianceMatrix::nblocks | ( | ) | const |
! The number of blocks in the matrix excluding inverses.
Definition at line 237 of file covariance_matrix.cc.
References correlations_.
Index CovarianceMatrix::ncols | ( | ) | const |
Definition at line 222 of file covariance_matrix.cc.
References nrows().
Referenced by OEM_checks(), operator<<(), and test_workspace_methods().
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().
Index CovarianceMatrix::nrows | ( | ) | const |
Definition at line 199 of file covariance_matrix.cc.
Referenced by add_scalar_variance(), check_and_add_block(), covmat_seAddBlock(), diagonal(), get_inverse(), inverse_diagonal(), ncols(), OEM(), OEM_checks(), operator<<(), and x2artsSpectroscopy().
|
explicit |
Definition at line 145 of file covariance_matrix.cc.
References n.
|
default |
|
default |
|
friend |
Definition at line 611 of file covariance_matrix.cc.
|
friend |
Definition at line 544 of file covariance_matrix.cc.
|
friend |
Definition at line 554 of file covariance_matrix.cc.
|
friend |
Definition at line 564 of file covariance_matrix.cc.
|
friend |
Definition at line 574 of file covariance_matrix.cc.
|
friend |
Definition at line 584 of file covariance_matrix.cc.
|
friend |
Definition at line 604 of file covariance_matrix.cc.
|
friend |
Definition at line 617 of file covariance_matrix.cc.
|
friend |
Definition at line 594 of file covariance_matrix.cc.
|
friend |
Reads CovarianceMatrix from XML input stream.
is_xml | XML Input stream |
covmat | CovarianceMatrix |
pbifs | Pointer to binary file stream. NULL for ASCII output. |
verbosity |
Definition at line 129 of file xml_io_compound_types.cc.
|
friend |
Write CovarianceMatrix to XML output stream.
os_xml | XML output stream |
covmat | CovarianceMatrix |
pbofs | Pointer to binary file stream. NULL for ASCII output. |
name | Unused |
verbosity |
Definition at line 208 of file xml_io_compound_types.cc.
|
private |
Definition at line 399 of file covariance_matrix.h.
Referenced by diagonal(), generate_blocks(), get_block(), has_block(), has_diagonal_blocks(), is_consistent(), nblocks(), operator<<(), xml_read_from_stream(), and xml_write_to_stream().
|
mutableprivate |
Definition at line 400 of file covariance_matrix.h.
Referenced by compute_inverse(), has_inverse(), inverse_diagonal(), is_consistent(), xml_read_from_stream(), and xml_write_to_stream().