Go to the documentation of this file.
40 using RetrievalData = std::tuple<ArrayOfRetrievalQuantity, ArrayOfArrayOfIndex>;
67 std::shared_ptr<Matrix> c =
68 std::make_shared<Matrix>(gv1.
nelem(), gv2.
nelem());
72 (*c)(k, l) = f(gv1[k], gv2[l]);
94 std::shared_ptr<Sparse> s =
95 std::make_shared<Sparse>(gv1.
nelem(), gv2.
nelem());
100 row_indices.reserve(
nelem);
101 col_indices.reserve(
nelem);
102 elements.reserve(
nelem);
105 row_indices.push_back(k);
106 col_indices.push_back(l);
107 elements.push_back(f(gv1[k], gv2[l]));
110 s->insert_elements(
nelem, row_indices, col_indices,
Vector(elements));
121 std::random_device rd;
122 std::mt19937 gen(rd());
123 std::uniform_int_distribution<> n_rqs_dist(2, 10), n_gs_dist(10, 100);
125 Index n_rqs = n_rqs_dist(gen);
130 for (
Index i = 0; i < n_rqs; i++) {
131 Index n_gs = n_gs_dist(gen);
134 for (
Index j = 0; j < n_gs; j++) {
136 gvs[0][j] = g_begin + (g_end - g_begin) * frac;
138 rqs.emplace_back(
"maintag",
"subtag",
"subsubtag",
"mode", 1, 0.0, gvs);
143 for (
Index i = 0; i < n_rqs; i++) {
144 Index n_grid_points = 1;
147 n_grid_points *= g.
nelem();
153 return std::make_tuple(rqs, jis);
165 std::random_device rd;
166 std::mt19937 gen(rd());
167 std::uniform_real_distribution<> dis(0.0, 1.0);
183 for (
size_t i = 0; i < rqs.size(); i++) {
184 Range range(jis[i][0], jis[i][1] - jis[i][0] + 1);
185 auto inds = std::make_pair(i, i);
190 covmat.add_correlation(
Block(range, range, inds, m));
192 std::shared_ptr<Sparse> m =
194 covmat.add_correlation(
Block(range, range, inds, m));
198 for (
size_t i = 0; i < rqs.size(); i++) {
199 for (
size_t j = i + 1; j < rqs.size(); j++) {
200 Range row_range(jis[i][0], jis[i][1] - jis[i][0] + 1);
201 Range col_range(jis[j][0], jis[j][1] - jis[j][0] + 1);
202 auto inds = std::make_pair(i, j);
208 covmat.add_correlation(
Block(row_range, col_range, inds, m));
210 std::shared_ptr<Sparse> m =
212 covmat.add_correlation(
Block(row_range, col_range, inds, m));
229 for (
Index i = 0; i < n_tests; i++) {
257 for (
Index i = 0; i < n_tests; i++) {
264 Matrix A(covmat), B(n, n), C(n, n), C_ref(n, n);
290 for (
Index i = 0; i < n_tests; i++) {
297 Matrix A(covmat), B(n, n), B_ref(n, n), C(n, n);
303 mult(C, covmat, B_ref);
321 for (
Index i = 0; i < n_tests; i++) {
328 Matrix A(covmat), B(n, n), B_ref(n, n), C(n, n);
356 for (
Index i = 0; i < n_tests; i++) {
378 for (
Index i = 0; i < n_tests; i++) {
388 Matrix A(covmat_1), B(covmat_2), C(covmat_1);
399 template <
typename MatrixType>
404 template <
typename MatrixType>
409 template <
typename MatrixType>
416 template <
typename MatrixType>
423 template <
typename MatrixType>
431 template <
typename MatrixType>
452 assert(covmat.ncols() == 10);
457 assert(covmat.ncols() == 20);
463 }
catch (
const std::runtime_error&) {
474 }
catch (
const std::runtime_error&) {
483 }
catch (
const std::runtime_error&) {
488 assert(covmat.ncols() == 10);
493 A_sparse.
resize(8000, 8000);
512 }
catch (
const std::runtime_error&) {
522 }
catch (
const std::runtime_error&) {
534 #pragma GCC diagnostic push
535 #pragma GCC diagnostic ignored "-Wunused-function"
536 #pragma GCC diagnostic ignored "-Wconversion"
538 #include "invlib/algebra.h"
539 #include "invlib/interfaces/arts_wrapper.h"
543 for (
Index i = 0; i < n_tests; i++) {
548 invlib::Matrix<ArtsCovarianceMatrixWrapper> wrapper(covmat);
549 Index n = covmat.ncols();
552 invlib::Vector<ArtsVector> v{},
w{}, w_ref{};
563 w_ref =
inv(wrapper) * v;
565 w_ref =
inv(
inv(wrapper)) * v;
568 invlib::Matrix<ArtsMatrix> A{
static_cast<Matrix>(covmat)}, B{}, C{},
586 C_ref = C_ref + wrapper;
591 C_ref = C_ref +
inv(wrapper);
597 #pragma GCC diagnostic pop
603 std::cout <<
"Testing covariance matrix: " << std::endl;
605 std::cout <<
"\tAddition: " << e << std::endl;
612 std::cout <<
"\tVector Multiplication: " << e << std::endl;
619 std::cout <<
"\tMatrix Multiplication: " << e << std::endl;
626 std::cout <<
"\tInverse: " << e << std::endl;
633 std::cout <<
"\tXML IO: " << e << std::endl;
639 e = test_invlib_wrapper(10);
640 std::cout <<
"\tinvlib Wrapper: " << e << std::endl;
647 std::cout <<
"\tdiagonal " << e << std::endl;
653 std::cout << std::endl <<
"\tTesting workspace functions ... ";
655 std::cout <<
" DONE." << std::endl;
Numeric test_multiplication_by_matrix(Index n_tests)
Tests the multiplication of covariance matrices with matrices.
Numeric test_multiplication_by_vector(Index n_tests)
Tests the multiplication of covariance matrices with vectors.
Complex w(Complex z) noexcept
The Faddeeva function.
const ArrayOfVector & Grids() const
Returns the grids of the retrieval.
Utility functions for testing.
Numeric test_diagonal(Index n_tests)
Test extraction of diagonal.
void id_mat(MatrixView I)
Identity Matrix.
void test_workspace_methods()
Test general functionality of CovarianceMatrix class.
void inv(MatrixView Ainv, ConstMatrixView A)
Matrix Inverse.
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
void covmat_seSet(CovarianceMatrix &covmat, const MatrixType &block, const Verbosity &)
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
CovarianceMatrix random_covariance_matrix(const ArrayOfRetrievalQuantity &rqs, const ArrayOfArrayOfIndex &jis)
Create a covariance matrix with correlations between retrieval quantitites given in rqs and jis.
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
void random_fill_vector(VectorView v, Numeric range, bool positive)
Fill vector with random values.
Vector y(Workspace &ws) noexcept
Array< RetrievalQuantity > ArrayOfRetrievalQuantity
Vector diagonal() const
Diagonal elements as vector.
void covmat_sxAddInverseBlock(CovarianceMatrix &covmat_se, const ArrayOfRetrievalQuantity &jq, const MatrixType &block, const Index &i, const Index &j, const Verbosity &)
Header files of CovarianceMatrix class.
This file contains the definition of Array.
void compute_inverse() const
Compute the inverse of this correlation matrix.
void covmat_sxAddBlock(CovarianceMatrix &covmat_se, const ArrayOfRetrievalQuantity &jq, const MatrixType &block, const Index &i, const Index &j, const Verbosity &)
This can be used to make arrays out of anything.
Numeric test_io(Index n_tests)
Test input and output of covariance matrices.
Index nelem(const Lines &l)
Number of lines.
void random_fill_matrix(MatrixView A, Numeric range, bool positive)
Fill matrix with random values.
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Numeric test_addition(Index n_tests)
Test addition of covariance matrices and inverse covariance matrices.
Index nelem() const
Returns the number of elements.
std::shared_ptr< Matrix > create_covariance_matrix_1D(Index i, Index j, ArrayOfRetrievalQuantity jqs, F f)
Create a block of a covariance matrix representating a correlation between the retrieval quantities i...
Routines for setting up the jacobian.
NUMERIC Numeric
The type to use for all floating point numbers.
Linear algebra functions.
CovarianceMatrix covmat_se(Workspace &ws) noexcept
std::tuple< ArrayOfRetrievalQuantity, ArrayOfArrayOfIndex > RetrievalData
Eigen::Matrix< Numeric, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixType
void resize(Index r, Index c)
Resize function.
void mult_inv(MatrixView C, ConstMatrixView A, const CovarianceMatrix &B)
void resize(Index r, Index c)
Resize function.
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
void covmat_sxSet(CovarianceMatrix &covmat, const MatrixType &block, const Verbosity &)
void xml_write_to_file(const String &filename, const T &type, const FileType ftype, const Index no_clobber, const Verbosity &verbosity)
Write data to XML file.
void covmat_seAddBlock(CovarianceMatrix &covmat_se, const MatrixType &block, const Index &i, const Index &j, const Verbosity &)
RetrievalData setup_retrieval_1D()
Setup a random retrieval case for testing.
void add_inv(MatrixView A, const CovarianceMatrix &B)
Numeric get_maximum_error(ConstVectorView v1, ConstVectorView v2, bool relative)
Maximum element-wise error of two vectors.
Numeric test_inverse(Index n_tests)
Tests the inversion of covariance matrices by computing the products of inverses of covariance matric...
Vector x(Workspace &ws) noexcept
INDEX Index
The type to use for all integer numbers and indices.
Deals with internal derivatives, Jacobian definition, and OEM calculations.
Index nelem() const
Number of elements.
void covmat_seAddInverseBlock(CovarianceMatrix &covmat_se, const MatrixType &block, const Index &i, const Index &j, const Verbosity &)
std::shared_ptr< Sparse > create_sparse_covariance_matrix_1D(Index i, Index j, ArrayOfRetrievalQuantity jqs, F f)
Same as create_covariance_matrix_1D but creates a matrix of type sparse.
This file contains basic functions to handle XML data files.
void solve(VectorView w, const CovarianceMatrix &A, ConstVectorView v)