ARTS
2.3.1285(git:92a29ea9-dirty)
|
Optimal inversion methods for linear and non-linear inverse problems. More...
#include "arts.h"
#include <iostream>
#include "lin_alg.h"
#include "logic.h"
#include "math.h"
#include "stdlib.h"
#include "arts_omp.h"
Go to the source code of this file.
Functions | |
void | separator (ostream &stream, Index length) |
void | log_init_li (ostream &stream) |
Initial log message, linear. More... | |
void | log_step_li (ostream &stream, Index step_number, Numeric cost, Numeric cost_x, Numeric cost_y) |
Step log message, linear. More... | |
void | log_finalize_li (ostream &stream) |
Final log message, linear. More... | |
void | log_init_gn (ostream &stream, Numeric tol, Index max_iter) |
Initial log message, Gauss-Newton. More... | |
void | log_step_gn (ostream &stream, Index step_number, Numeric cost, Numeric cost_x, Numeric cost_y, Numeric di2) |
Step log message, Gauss-Newton. More... | |
void | log_finalize_gn (ostream &stream, bool converged, Index iter, Index max_iter) |
Final log message, Gauss-Newton. More... | |
void | log_init_lm (ostream &stream, Numeric tol, Index max_iter) |
Initial log message, Levenberg-Marquardt. More... | |
void | log_gamma_step_lm (ostream &stream, Numeric cost, Numeric cost_x, Numeric cost_y, Numeric gamma) |
void | log_step_lm (ostream &stream, Index step_number, Numeric cost, Numeric cost_x, Numeric cost_y, Numeric gamma, Numeric di2) |
Step log message, Levenberg-Marquardt. More... | |
void | log_finalize_lm (ostream &stream, bool converged, Numeric cost, Numeric cost_x, Numeric cost_y, Numeric gamma, Numeric gamma_max, Index iter, Index max_iter) |
Final log message, Levenberg-Marquardt. More... | |
template<typename Se_t > | |
void | oem_cost_y (Numeric &cost_y, ConstVectorView y, ConstVectorView yf, Se_t SeInv, const Numeric &normfac) |
Calculation of y-part of cost function. More... | |
void | oem_cost_x (Numeric &cost_x, ConstVectorView x, ConstVectorView xa, ConstMatrixView SxInv, const Numeric &normfac) |
Calculation of x-part of cost function. More... | |
void | mult_outer (MatrixView A, ConstMatrixView B, ConstVectorView b) |
Multiply matrix element-wise by outer product of vector. More... | |
void | scale_columns (MatrixView A, ConstMatrixView B, ConstVectorView b) |
Scale columns. More... | |
void | scale_rows (MatrixView A, ConstMatrixView B, ConstVectorView b) |
Scale rows. More... | |
Index | oem_linear_nform (Vector &x, Matrix &G, Matrix &J, Vector &yf, Numeric &cost_y, Numeric &cost_x, ForwardModel &F, ConstVectorView xa, ConstVectorView x_norm, ConstVectorView y, ConstMatrixView SeInv, ConstMatrixView SxInv, const Numeric &cost_start, const bool &verbose) |
Linear OEM, n-form. More... | |
template<typename Se_t , typename Sx_t > | |
Index | oem_gauss_newton (Vector &x, Matrix &G, Matrix &J, Vector &yf, Numeric &cost_y, Numeric &cost_x, Index &iter, ForwardModel &F, ConstVectorView xa, ConstVectorView x_norm, ConstVectorView y, const Se_t &SeInv, const Sx_t &SxInv, const Index max_iter, const Numeric tol, bool verbose) |
Gauss-Newton non-linear OEM using precomputed inverses, n-form. More... | |
template<typename Se_t , typename Sx_t > | |
Index | oem_levenberg_marquardt (Vector &x, Matrix &G, Matrix &J, Vector &yf, Numeric &cost_y, Numeric &cost_x, Index &iter, ForwardModel &F, ConstVectorView xa, ConstVectorView x_norm, ConstVectorView y, const Se_t &SeInv, const Sx_t &SxInv, Index max_iter, Numeric tol, Numeric gamma_start, Numeric gamma_decrease, Numeric gamma_increase, Numeric gamma_max, Numeric gamma_threshold, bool verbose) |
Non-linear OEM using Levenberg-Marquardt method. More... | |
void | oem_linear_mform (VectorView x, MatrixView G, ConstVectorView xa, ConstVectorView yf, ConstVectorView y, ConstMatrixView K, ConstMatrixView Se, ConstMatrixView Sx) |
Linear OEM, m-form. More... | |
bool | oem_gauss_newton_m_form (VectorView x, ConstVectorView y, ConstVectorView xa, ForwardModel &K, ConstMatrixView Se, ConstMatrixView Sx, Numeric tol, Index max_iter) |
Non-linear OEM using Gauss-Newton method. More... | |
bool | oem_gauss_newton_n_form (VectorView x, ConstVectorView y, ConstVectorView xa, ForwardModel &K, ConstMatrixView Se, ConstMatrixView Sx, Numeric tol, Index max_iter) |
Non-linear OEM using Gauss-Newton method. More... | |
Optimal inversion methods for linear and non-linear inverse problems.
Definition in file oem.cc.
Final log message, Gauss-Newton.
[in] | stream | Stream to print message to. |
[in] | converged | converged flag. |
[in] | cost | Value of cost function. |
[in] | cost_x | x-component of cost function. |
[in] | cost_y | y-component of cost function. |
[in] | iter | Final step number. |
[in] | max_iter | Maximum step number. |
Definition at line 163 of file oem.cc.
References separator().
void log_finalize_li | ( | ostream & | stream | ) |
Final log message, linear.
[in] | stream | Stream to print message to. |
[in] | converged | converged flag. |
[in] | cost | Value of cost function. |
[in] | cost_x | x-component of cost function. |
[in] | cost_y | y-component of cost function. |
[in] | iter | Final step number. |
[in] | max_iter | Maximum step number. |
Definition at line 91 of file oem.cc.
References separator().
Referenced by oem_linear_nform().
void log_finalize_lm | ( | ostream & | stream, |
bool | converged, | ||
Numeric | cost, | ||
Numeric | cost_x, | ||
Numeric | cost_y, | ||
Numeric | gamma, | ||
Numeric | gamma_max, | ||
Index | iter, | ||
Index | max_iter | ||
) |
Final log message, Levenberg-Marquardt.
[in] | stream | Stream to print message to. |
[in] | converged | converged flag. |
[in] | cost | Value of cost function. |
[in] | cost_x | x-component of cost function. |
[in] | cost_y | y-component of cost function. |
[in] | gamma | Final gamma value. |
[in] | gamma_max | Maximum gamma value. |
[in] | iter | Final step number. |
[in] | max_iter | Maximum step number. |
Definition at line 267 of file oem.cc.
References separator().
Initial log message, Gauss-Newton.
[in] | stream | Stream to print message to. |
[in] | tol | Tolerance. |
[in] | max_iter | Maximum Iterations. |
Definition at line 104 of file oem.cc.
References separator().
void log_init_li | ( | ostream & | stream | ) |
Initial log message, linear.
[in] | stream | Stream to print message to. |
Definition at line 44 of file oem.cc.
References separator().
Referenced by oem_linear_nform().
Initial log message, Levenberg-Marquardt.
[in] | stream | Stream to print message to. |
[in] | tol | Tolerance. |
[in] | max_iter | Maximum Iterations. |
Definition at line 187 of file oem.cc.
References separator().
void log_step_gn | ( | ostream & | stream, |
Index | step_number, | ||
Numeric | cost, | ||
Numeric | cost_x, | ||
Numeric | cost_y, | ||
Numeric | di2 | ||
) |
Step log message, Gauss-Newton.
[in] | stream | Stream to print message to. |
[in] | step_number | Current step number. |
[in] | cost | Current value of cost function. |
[in] | cost_x | x-component of current cost function value. |
[in] | cost_y | y-component of current cost function value. |
[in] | di2 | Convergence criterion. |
void log_step_li | ( | ostream & | stream, |
Index | step_number, | ||
Numeric | cost, | ||
Numeric | cost_x, | ||
Numeric | cost_y | ||
) |
Step log message, linear.
[in] | stream | Stream to print message to. |
[in] | step_number | Current step number. |
[in] | cost | Current value of cost function. |
[in] | cost_x | x-component of current cost function value. |
[in] | cost_y | y-component of current cost function value. |
Definition at line 66 of file oem.cc.
Referenced by oem_linear_nform().
void log_step_lm | ( | ostream & | stream, |
Index | step_number, | ||
Numeric | cost, | ||
Numeric | cost_x, | ||
Numeric | cost_y, | ||
Numeric | gamma, | ||
Numeric | di2 | ||
) |
Step log message, Levenberg-Marquardt.
[in] | stream | Stream to print message to. |
[in] | step_number | Current step number. |
[in] | cost | Current value of cost function. |
[in] | cost_x | x-component of current cost function value. |
[in] | cost_y | y-component of current cost function value. |
[in] | gamma | Current gamma value. |
[in] | di2 | Convergence criterion. |
void mult_outer | ( | MatrixView | A, |
ConstMatrixView | B, | ||
ConstVectorView | b | ||
) |
Multiply matrix element-wise by outer product of vector.
Multiplies the matrix B by the outer product b' * b of b. This is used to scale the a priori covariance matrix to avoid numerical problems. The Matrices A and B can be the same but shouldn't overlap in other ways.
[out] | A | The matrix B divided by b'*b. |
[in] | B | The matrix B to divide. |
[in] | b | The vector used to form the outer product. |
Definition at line 377 of file oem.cc.
References i, is_size(), n, and ConstVectorView::nelem().
Referenced by scale_rows().
void oem_cost_x | ( | Numeric & | cost_x, |
ConstVectorView | x, | ||
ConstVectorView | xa, | ||
ConstMatrixView | SxInv, | ||
const Numeric & | normfac | ||
) |
Calculation of x-part of cost function.
This version is suitable if no term is already at hand.
[out] | cost_x | Const function value |
[in] | x | State vector. |
[in] | xa | A priori state. |
[in] | SxInv | Inverse of relevenaty covariance matrix |
[in] | normfac | Normalisation factor. The cost is scaled with 1/normfac |
Definition at line 345 of file oem.cc.
References dx, mult(), and ConstVectorView::nelem().
void oem_cost_y | ( | Numeric & | cost_y, |
ConstVectorView | y, | ||
ConstVectorView | yf, | ||
Se_t | SeInv, | ||
const Numeric & | normfac | ||
) |
Calculation of y-part of cost function.
This version is suitable if no term is already at hand.
[out] | cost_y | Const function value |
[in] | y | Measurement vector. |
[in] | yf | Fitted measurement. |
[in] | SeInv | Inverse of relevenaty covariance matrix |
[in] | normfac | Normalisation factor. The cost is scaled with 1/normfac |
Definition at line 319 of file oem.cc.
References mult(), and ConstVectorView::nelem().
Index oem_gauss_newton | ( | Vector & | x, |
Matrix & | G, | ||
Matrix & | J, | ||
Vector & | yf, | ||
Numeric & | cost_y, | ||
Numeric & | cost_x, | ||
Index & | iter, | ||
ForwardModel & | F, | ||
ConstVectorView | xa, | ||
ConstVectorView | x_norm, | ||
ConstVectorView | y, | ||
const Se_t & | SeInv, | ||
const Sx_t & | SxInv, | ||
const Index | max_iter, | ||
const Numeric | tol, | ||
bool | verbose | ||
) |
Gauss-Newton non-linear OEM using precomputed inverses, n-form.
Computes the optimal nonlinear inverse of a given forward model using the Gauss-Newton method as given in eq. (5.8) in Rodgers book. The forward model is given by an object implementing the interface described by the ForwardModel class. Convergence is determined using equation (5.29). The given tolerance is scaled by the problem size n. If the method doesn't converge it abords after the given maximum number of iterations.
During execution two additional n-times-m and one n-times-n matrix is allocated. In addition to that, space for 4 length-n vectors and two length-m vectors is allocated. The given Matrix and Vector views may not overlap.
The returned Index value indicates if the computation was successful or if an error occured. The following encoding for errors is used:
0 - Success 1 - ERROR: Computation didn't converge. Maximum of iterations reached. 2 - ERROR: Computation didn't converge. Maximum gamma value reached. 9 - ERROR: Evaluation of forward model failed.
[out] | x | The optimal inverse x. |
[out] | G | The gain matrix corresponding to x. |
[out] | J | The jacobian as computed in the last LM iteration. |
[out] | yf | The fitted measurement vector. |
[out] | cost_y | The cost related to the measurement vector. |
[out] | cost_x | The cost related to the state vector. |
[out] | iter | The number of iterations. |
[in] | F | The ForwardModel representing the forward model to invert. |
[in] | xa | The size-n a-priori state vector. |
[in] | x_norm | Normalization vector for the state covariance matrix. |
[in] | y | The length-m, input measurement vector. |
[in] | SeInv | The inverse of the measurement error covariance (m,m)-matrix |
[in] | SxInv | The inverse of the a priori covariance (n,n)-matrix |
[in] | max_iter | Tha maximum number of iterations in case of no convergence. |
[in] | tol | The convergence criterium before scaling by the problem size. |
[in] | verbose | If true, log message are printed to stdout. |
Definition at line 1603 of file oem.cc.
References n, ConstMatrixView::ncols(), ConstVectorView::nelem(), and ConstMatrixView::nrows().
bool oem_gauss_newton_m_form | ( | VectorView | x, |
ConstVectorView | y, | ||
ConstVectorView | xa, | ||
ForwardModel & | K, | ||
ConstMatrixView | Se, | ||
ConstMatrixView | Sx, | ||
Numeric | tol, | ||
Index | max_iter | ||
) |
Non-linear OEM using Gauss-Newton method.
Computes the optimal nonlinear inverse of a given forward model using the Gauss-Newton method as given in eq. (5.10) in Rodgers book. The forward model is given by an object implementing the interface described by the ForwardModel class. Convergence is determined using equation (5.33). The given tolerance is scaled by the problem size m. If the method doesn't converge it abords after the given maximum number of iterations.
During the execution, space for up to 6 additional matrices and vectors is allocated. The given Matrix and Vector views should not overlap.
[out] | x | The optimal inverse x. |
[in] | y | The measurement vector containing m measurements. |
[in] | xa | The size-n a-priori state vector. |
[in] | K | The ForwardModel representing the forward model to invert. |
[in] | Se | The measurement error covariance (m,m)-matrix |
[in] | Sx | The a priori covariance (n,n)-matrix |
[in] | tol | The convergence criterium before scaling by the problem size. |
max_iter | Tha maximum number of iterations in case of no convergence. |
Definition at line 1852 of file oem.cc.
References mult(), n, ConstVectorView::nelem(), solve(), and transpose().
bool oem_gauss_newton_n_form | ( | VectorView | x, |
ConstVectorView | y, | ||
ConstVectorView | xa, | ||
ForwardModel & | K, | ||
ConstMatrixView | Se, | ||
ConstMatrixView | Sx, | ||
Numeric | tol, | ||
Index | max_iter | ||
) |
Non-linear OEM using Gauss-Newton method.
Computes the optimal nonlinear inverse of a given forward model using the Gauss-Newton method as given in eq. (5.9) in Rodgers book. The forward model is given by an object implementing the interface described by the ForwardModel class. Convergence is determined using equation (5.29). The given tolerance is scaled by the problem size m. If the method doesn't converge it abords after the given maximum number of iterations.
During the execution, space for up to 6 additional matrices and vectors is allocated. The given Matrix and Vector views should not overlap.
[out] | x | The optimal inverse x. |
[in] | y | The measurement vector containing m measurements. |
[in] | xa | The size-n a-priori state vector. |
[in] | K | The ForwardModel representing the forward model to invert. |
[in] | Se | The measurement error covariance (m,m)-matrix |
[in] | Sx | The a priori covariance (n,n)-matrix |
[in] | tol | The convergence criterium before scaling by the problem size. |
max_iter | Tha maximum number of iterations in case of no convergence. |
Definition at line 1941 of file oem.cc.
References dx, inv(), mult(), n, ConstVectorView::nelem(), solve(), and transpose().
Index oem_levenberg_marquardt | ( | Vector & | x, |
Matrix & | G, | ||
Matrix & | J, | ||
Vector & | yf, | ||
Numeric & | cost_y, | ||
Numeric & | cost_x, | ||
Index & | iter, | ||
ForwardModel & | F, | ||
ConstVectorView | xa, | ||
ConstVectorView | x_norm, | ||
ConstVectorView | y, | ||
const Se_t & | SeInv, | ||
const Sx_t & | SxInv, | ||
Index | max_iter, | ||
Numeric | tol, | ||
Numeric | gamma_start, | ||
Numeric | gamma_decrease, | ||
Numeric | gamma_increase, | ||
Numeric | gamma_max, | ||
Numeric | gamma_threshold, | ||
bool | verbose | ||
) |
Non-linear OEM using Levenberg-Marquardt method.
Inverts a given non-linear forward model using the Levenberg-Marquardt method. The implementation follows Eq. (5.36) in Rodger's book.
Communication with the forward model is performed in the same way as in oem_gauss_newton().
The start value for gamma is given by the parameter gamma_start. If a new x value is found, gamma is decreased by a factor gamma_scale_dec. If the ost is increased, gamma is increased by a factor gamma_scale_inc. If gamma falls below gamma_threshold, it is set to zero. If no lower cost can be obtained with gamma = 0, gamma is set to 1. If gamma becomes larger than gamma_max and the cost can not be reduced, the iteration is stopped.
During the execution, space for two n-times-n and one n-times-m matrices is allocated as well as space for 5 length-n vectors and two length-m vectors.
The returned Index value indicates if the computation was successful or if an error occured. The following encoding for errors is used:
0 - Success 1 - ERROR: Computation didn't converge. Maximum of iterations reached. 2 - ERROR: Computation didn't converge. Maximum gamma value reached. 9 - ERROR: Evaluation of forward model failed.
[out] | x | The optimal estimator of the state vector. |
[out] | yf | The fitted state vector as computed in the second-last LM iteration. |
[out] | G | The gain matrix. |
[out] | J | The jacobian as computed in the second-last LM iteration. |
[in] | y | The size-m input measurement vector. |
[in] | xa | The size-n a priori state vector. |
[in] | K | A forward model object implementing the FowardModel class. |
[in] | Seinv | The inverse of the covariance matrix of the measurement error. |
[in] | Sxinv | The inverse of the covariance matrix of the a priori error. |
[in] | tol | The normalized convergence criterion. |
[in] | max_iter | The maximum number of iterations before abortion. |
[in] | gamma_start | The start value of the gamma factor. |
[in] | gamma_scale_dec | The factor to decrease gamma by if the cost function was descreased. |
[in] | gamma_scale_inc | The factor to increase gamma by if the cost function could not be decreased. |
[in] | gamma_max | The maximum gamma value. If gamma == gamma_max and the cost function can not be decreased, the iteration is aborted. |
[in] | gamma_threshold | The minimum value that gamma can take on before it is set to zero. |
[in] | verbose | If true, log messages are printed to stdout. |
Definition at line 1703 of file oem.cc.
References n, ConstMatrixView::ncols(), ConstVectorView::nelem(), and ConstMatrixView::nrows().
void oem_linear_mform | ( | VectorView | x, |
MatrixView | G, | ||
ConstVectorView | xa, | ||
ConstVectorView | yf, | ||
ConstVectorView | y, | ||
ConstMatrixView | K, | ||
ConstMatrixView | Se, | ||
ConstMatrixView | Sx | ||
) |
Linear OEM, m-form.
Computes the inverse of a linear forward model by computing the MAP solution as described in Rodgers, Inverse Methods for Atmospheric Sounding, p. 67. This function uses the m-form ( Eq. (4.6) ) which requires the solution of a linear system of equations of size m-times-m.
For the execution 1 n-times-m matrices, 2 m-times-m matrices and a vector with m elements are allocated. The given Matrix and Vector views may not overlap.
[out] | x | The optimal, estimated state vector consisting of n elements. |
[in] | y | The measurement vector consisting of m elements. |
[in,out] | yf | On input yf should contain the value of the forward model at the linearization point. On output yf should contain the fitted measurement vector. |
[in] | xa | The mean a priori state vector. |
[in] | K | The weighting function (m,n)-matrix. |
[in] | Se | The measurement error covariance (m,m)-matrix. |
[in] | Sx | The a priori covariance (n,n)-matrix. |
[out] | G | The gain matrix. |
Definition at line 1789 of file oem.cc.
References inv(), mult(), n, ConstMatrixView::ncols(), ConstVectorView::nelem(), ConstMatrixView::nrows(), and transpose().
Index oem_linear_nform | ( | Vector & | x, |
Matrix & | G, | ||
Matrix & | J, | ||
Vector & | yf, | ||
Numeric & | cost_y, | ||
Numeric & | cost_x, | ||
ForwardModel & | F, | ||
ConstVectorView | xa, | ||
ConstVectorView | x_norm, | ||
ConstVectorView | y, | ||
ConstMatrixView | SeInv, | ||
ConstMatrixView | SxInv, | ||
const Numeric & | cost_start, | ||
const bool & | verbose | ||
) |
Linear OEM, n-form.
Computes the inverse of a linear forward model by computing the MAP solution as described in Rodgers, Inverse Methods for Atmospheric Sounding, p. 67. This function uses the n-form (eq. (4.3)) which requires the solution of a linear system of equations of size n-times-n.
Requires the inverses of the covariance matrices for the state and measurement vector to be provided as arguments.
The returned Index value indicates if the computation was successful or if an error occured. The following encoding for errors is used:
0 - Success 9 - ERROR: Evaluation of forward model failed.
[out] | x | The optimal, estimated state vector consisting of n elements. |
[out] | G | The gain matrix. |
[in] | xa | The a priori state vector |
[in] | yf | The value of the forward model at a priori. |
[in] | y | The measurement vector consisting of m elements. |
[in] | K | The weighting function (m,n)-matrix |
[in] | SeInv | The inverse of the measurement error covariance (m,m)-matrix |
[in] | SxInv | The inverse of the a priori covariance (n,n)-matrix |
Definition at line 836 of file oem.cc.
References dx, F, J, log_finalize_li(), log_init_li(), log_step_li(), n, ConstMatrixView::ncols(), ConstVectorView::nelem(), and ConstMatrixView::nrows().
void scale_columns | ( | MatrixView | A, |
ConstMatrixView | B, | ||
ConstVectorView | b | ||
) |
Scale columns.
Scales the columns of a matrix B by the elements of a vector b.
A | The scaled matrix |
B | The matrix to scale |
b | The vector containing the scaling factors |
Definition at line 406 of file oem.cc.
References i, is_size(), n, ConstMatrixView::ncols(), and ConstMatrixView::nrows().
void scale_rows | ( | MatrixView | A, |
ConstMatrixView | B, | ||
ConstVectorView | b | ||
) |
Scale rows.
Scales the rows of a matrix B by the elements of a vector b.
A | The scaled matrix |
B | The matrix to scale |
b | The vector containing the scaling factors |
Definition at line 436 of file oem.cc.
References lm_hitran_2017::compute(), F, i, is_size(), J, joker, lubacksub(), ludcmp(), mult(), mult_outer(), n, ConstMatrixView::ncols(), ConstMatrixView::nrows(), and transpose().
void separator | ( | ostream & | stream, |
Index | length | ||
) |
Definition at line 31 of file oem.cc.
References i.
Referenced by oem::ArtsLog< type >::finalize(), oem::ArtsLog< type >::init(), log_finalize_gn(), log_finalize_li(), log_finalize_lm(), log_init_gn(), log_init_li(), log_init_lm(), and oem::ArtsLog< type >::~ArtsLog().