ARTS
2.4.0(git:4fb77825)
|
Test for the OEM functions. More...
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "engine.h"
#include "lin_alg.h"
#include "matpackII.h"
#include "matrix.h"
#include "oem.h"
#include "test_utils.h"
#include "unistd.h"
Go to the source code of this file.
Classes | |
class | LinearModel |
Linear Forward model. More... | |
class | QuadraticModel |
Quadratic Forward Model. More... | |
Functions | |
void | write_matrix (ConstMatrixView A, const char *filename) |
Write matrix to text file. More... | |
void | write_vector (ConstVectorView v, const char *filename) |
Write vector to text file. More... | |
void | generate_test_data (VectorView y, VectorView xa, MatrixView Se, MatrixView Sx) |
Generate test data for linear OEM retrieval. More... | |
void | generate_linear_model (MatrixView K) |
Generate linear forward model. More... | |
Index | run_test_matlab (Engine *eng, string filename) |
Run test script in matlab. More... | |
Index | run_oem_matlab (VectorView x, MatrixView G, Engine *eng, string filename) |
Run test script in matlab and return result vector. More... | |
void | setup_test_environment (Engine *&eng) |
Setup the test environment. More... | |
void | run_plot_script (Engine *eng, string filename, string title) |
Plot benchmark results. More... | |
void | tidy_up_test_environment (Engine *eng) |
Tidy up test environment. More... | |
void | benchmark_inv (Engine *eng, Index n0, Index n1, Index ntests) |
Matrix inversion benchmark. More... | |
void | benchmark_mult (Engine *eng, Index n0, Index n1, Index ntests) |
Matrix multiplication benchmark. More... | |
void | benchmark_oem_linear (Engine *eng, Index n0, Index n1, Index ntests) |
Benchmark linear oem. More... | |
void | test_oem_linear (Engine *eng, Index m, Index n, Index ntests) |
Test linear_oem. More... | |
void | test_oem_gauss_newton (Engine *eng, Index m, Index n, Index ntests) |
Test non-linear OEM. More... | |
void | test_oem_levenberg_marquardt (Engine *eng, Index m, Index n, Index ntests) |
Test non-linear OEM. More... | |
void | test_oem_gauss_newton_sparse (Index m, Index n, Index ntests) |
Test sparse non-linear OEM. More... | |
void | test_oem_levenberg_marquardt_sparse (Index m, Index n, Index ntests) |
Test sparse non-linear OEM. More... | |
int | main () |
Variables | |
string | source_dir = SOURCEDIR |
string | atmlab_dir = ATMLABDIR |
Matrix inversion benchmark.
Inverts randomly generated matrix matrices in matlab and in arts and compares the performance. Performs ntests numbers of test with matrices linearly increasing in size starting at n0 and ending an n1. Writes the result to standard out and to the file "times_inv.txt" in the current directory. Also generates a plot of the data using matlab stored in "times_inv.png".
[in] | n0 | Size of the smallest matrix in the benchmark. |
[in] | n1 | Size of the largest matrix in the benchmark. |
[in] | ntests | Number of tests to be performed. In each step the size of the matrix is linearly increased from n0 to n1. |
Definition at line 381 of file test_oem.cc.
References inv(), random_fill_matrix(), run_plot_script(), run_test_matlab(), and write_matrix().
Matrix multiplication benchmark.
Multiplies two identical matrices in matlab and in arts and compares the performance. Performs ntests numbers of test with matrices linearly increasing in size starting at n0 and ending an n1. Writes the result to standard out and to the file "times_mult.txt" in the current directory. Also generates a plot of the data using matlab stored in "times_mult.png".
[in] | n0 | Size of the smallest matrix in the benchmark. |
[in] | n1 | Size of the largest matrix in the benchmark. |
[in] | ntests | Number of tests to be performed. In each step the size of the matrix is linearly increased from n0 to n1. |
Definition at line 441 of file test_oem.cc.
References mult(), mult_general(), random_fill_matrix(), run_plot_script(), run_test_matlab(), and write_matrix().
Benchmark linear oem.
Run linear oem test and benchmark. Runs ntests numbers of tests with the size of K growing linearly from n0 to n1. Prints for each test the maximum relative error in the result compared to the matlab implementation and the cpu time in milliseconds needed for the execution. The timing results are also written to to a file "times_linear.txt" in the current directory.
n0 | Starting size for the K matrix. |
n1 | Final size for the K matrix. |
ntests | Number of tests to be performed. |
Definition at line 499 of file test_oem.cc.
References generate_linear_model(), generate_test_data(), inv(), mult(), run_oem_matlab(), run_plot_script(), write_matrix(), write_vector(), ARTS::Var::xa(), ARTS::Var::y(), and ARTS::Var::yf().
void generate_linear_model | ( | MatrixView | K | ) |
Generate linear forward model.
Fills the given matrix K with random values in the range [-10,10].
[in,out] | K | The matrix representing the forward model. |
Definition at line 245 of file test_oem.cc.
References random_fill_matrix().
Referenced by benchmark_oem_linear(), and test_oem_linear().
void generate_test_data | ( | VectorView | y, |
VectorView | xa, | ||
MatrixView | Se, | ||
MatrixView | Sx | ||
) |
Generate test data for linear OEM retrieval.
Fills the given matrices and vectors needed for the linear OEM retrieval functions with random values.
y | The measurement vector. Filled with random integer values in the range [0, 10]. |
xa | The a priori vector. Filled with random integer values in the range [0, 10]. |
K | The linear forward model. Filled with random integer values in the range [-10, 10]. |
Se | The covariance matrix for observation uncertainties. Filled with random values in the range [-1, 1] (Scaled down from the range [-10, 10]). |
Sa | The covariance matrix for a priori uncertainties. Filled with random values in the range [-1, 1] (Scaled down from the range [-10, 10]). |
Definition at line 220 of file test_oem.cc.
References mult(), random_fill_matrix(), random_fill_matrix_symmetric(), random_fill_vector(), transpose(), ARTS::Var::xa(), and ARTS::Var::y().
Referenced by benchmark_oem_linear(), test_oem_gauss_newton(), test_oem_levenberg_marquardt(), and test_oem_linear().
int main | ( | void | ) |
Definition at line 987 of file test_oem.cc.
References test_oem_gauss_newton_sparse().
Index run_oem_matlab | ( | VectorView | x, |
MatrixView | G, | ||
Engine * | eng, | ||
string | filename | ||
) |
Run test script in matlab and return result vector.
Runs the oem function from the atmlab package. Runs the given external matlab script. The results of the computation are read from the Matlab workspace variables x and t and returned in the x vector argument and the return value.
[out] | x | Vector to write the results of the retrieval to. |
[in] | eng | Pointer to the matlab engine that manages the running Matlab session. |
[in] | filename | Name of the test script to be run. |
Definition at line 285 of file test_oem.cc.
References ConstMatrixView::ncols(), ConstMatrixView::nrows(), ARTS::Var::time(), and ARTS::Var::x().
Referenced by benchmark_oem_linear().
void run_plot_script | ( | Engine * | eng, |
string | filename, | ||
string | title | ||
) |
Plot benchmark results.
Run matlab script that generates a plot of the benchmark results.
[in] | eng | Pointer to the running matlab engine. |
[in] | filename | Filename of the file containing the results. Should be 'times_mult.txt' or 'times_linear.txt'. |
Definition at line 347 of file test_oem.cc.
Referenced by benchmark_inv(), benchmark_mult(), and benchmark_oem_linear().
Index run_test_matlab | ( | Engine * | eng, |
string | filename | ||
) |
Run test script in matlab.
Runs the test script given by filename in matlab. Reads out the the execution time from the variable t in the current workspace and returns is as return value.
[in] | eng | Pointer to the running matlab engine. |
[in] | filename | Name of the file to be run. |
Definition at line 258 of file test_oem.cc.
References ARTS::Var::time().
Referenced by benchmark_inv(), and benchmark_mult().
void setup_test_environment | ( | Engine *& | eng | ) |
Setup the test environment.
Changes to the test directory and initializes the matlab engine. Initialized the atmlab package.
[in,out] | eng | Pointer variable that will contain the pointer to the initialized Matlab engine. |
Definition at line 321 of file test_oem.cc.
References atmlab_dir, and source_dir.
Test non-linear OEM.
Test the non-linear OEM functions using the Gauss-Newton method using a random quadratic model. Performs ntest numbers of test with a state space of dimension n and a measurement space of dimension m. Test each iteration method and compares the result to the Matlab result. The maximum relative error is printed to stdout.
eng | The Matlba engine handle. |
m | The dimension of the measurement space space. |
n | The dimension of the state space. |
ntests | The number of tests to perform. |
Definition at line 686 of file test_oem.cc.
References add_noise(), QuadraticModel::evaluate(), generate_test_data(), inv(), linalg::std(), x0, and ARTS::Var::xa().
Test sparse non-linear OEM.
Test the non-linear OEM function using Gauss-Newton method with a random quadratic model and sparse matrix arithmetic. In each test, the result is compared to the result obtained using dense arithmetic. Checks both the standard and the normalized case. The maximum relative error of both cases and the Gain matrix is printed to stdout for each test.
m | The dimension of the measurement space space. |
n | The dimension of the state space. |
ntests | The number of tests to perform. |
Definition at line 897 of file test_oem.cc.
References add_noise(), QuadraticModel::evaluate(), id_mat(), random_fill_vector(), linalg::std(), x0, and ARTS::Var::xa().
Referenced by main().
Test non-linear OEM.
Test the non-linear OEM function using Levenberg-Marquardt method with a random quadratic model. Performs ntest numbers of tests with a state space of dimension n and a measurement space of dimension m. Test each iteration method and compares the result to the Matlab result. The maximum relative error is printed to stdout.
eng | The Matlba engine handle. |
m | The dimension of the measurement space space. |
n | The dimension of the state space. |
ntests | The number of tests to perform. |
Definition at line 790 of file test_oem.cc.
References add_noise(), QuadraticModel::evaluate(), generate_test_data(), inv(), linalg::std(), x0, and ARTS::Var::xa().
Test sparse non-linear OEM.
Test the non-linear OEM function using Levenberg-Marquardt method with a random quadratic model and sparse matrix arithmetic. In each test, the result is compared to the result obtained using dense arithmetic. Checks both the standard and the normalized case. The maximum relative error of both cases and the Gain matrix is printed to stdout for each test.
m | The dimension of the measurement space space. |
n | The dimension of the state space. |
ntests | The number of tests to perform. |
Definition at line 985 of file test_oem.cc.
Test linear_oem.
Tests the linear_oem function using randomized input data. Performs ntest numbers of tests with a m times n K-matrix. For each test, the maximum relative error is printed to standard out.
[in] | m | Size of the measurement space. |
[in] | n | Size of the state space. |
[in] | ntests | Number of tests to be performed. |
Definition at line 575 of file test_oem.cc.
References generate_linear_model(), generate_test_data(), linalg::std(), ARTS::Var::xa(), and ARTS::Var::y().
void tidy_up_test_environment | ( | Engine * | eng | ) |
Tidy up test environment.
Deletes temporary test files and closes the Matlab session.
[in] | eng | Pointer to the running Matlab engine. |
Definition at line 360 of file test_oem.cc.
void write_matrix | ( | ConstMatrixView | A, |
const char * | filename | ||
) |
Write matrix to text file.
Write the given matrix in plain text to the file filename in the current directory.
[in] | A | The matrix to write to the file. |
[in] | filename | The name of the file to write to. |
Definition at line 170 of file test_oem.cc.
References ConstMatrixView::ncols(), and ConstMatrixView::nrows().
Referenced by benchmark_inv(), benchmark_mult(), benchmark_oem_linear(), and QuadraticModel::QuadraticModel().
void write_vector | ( | ConstVectorView | v, |
const char * | filename | ||
) |
Write vector to text file.
Write the given vector to the file filename in the current directory.
[in] | v | The vector to write. |
[in] | filename | The name of the file to write to. |
Definition at line 192 of file test_oem.cc.
References ConstVectorView::nelem().
Referenced by benchmark_oem_linear().
string atmlab_dir = ATMLABDIR |
Definition at line 33 of file test_oem.cc.
Referenced by setup_test_environment().
string source_dir = SOURCEDIR |
Definition at line 32 of file test_oem.cc.
Referenced by setup_test_environment().