ReFRACtor
|
The base class for maximum a posteriori estimation. More...
#include <max_a_posteriori.h>
Public Member Functions | |
MaxAPosteriori (const blitz::Array< double, 1 > &a_priori_params, const blitz::Array< double, 2 > &a_priori_cov) | |
Constructor. More... | |
virtual | ~MaxAPosteriori () |
virtual blitz::Array< double, 2 > | a_posteriori_covariance () |
Returns a-posteriori covariance matrix. More... | |
virtual blitz::Array< double, 2 > | a_priori_cov () const |
Returns the a priori covariance matrix. More... | |
virtual blitz::Array< double, 2 > | a_priori_cov_chol () const |
Returns the Cholesky decomposition of the a-priori covariance matrix. More... | |
virtual blitz::Array< double, 2 > | a_priori_cov_chol_inv () const |
Returns the inverse of the Cholesky decomposition of the a priori covariance matrix. More... | |
virtual blitz::Array< double, 1 > | a_priori_params () const |
Returns the a priori values (knowledge) of the parameters. More... | |
virtual void | assert_jacobian_correct (const blitz::Array< double, 2 > &k) const |
Conditions that must be satisfied when a derived class computes the Jacobian of the model. More... | |
virtual void | assert_model_correct (const blitz::Array< double, 1 > &m) const |
Conditions that must be satisfied when a derived class computes the model. More... | |
virtual void | assert_parameter_correct (const blitz::Array< double, 1 > &x) const |
Checks that the new input parameters are correct. More... | |
virtual void | assert_parameter_set_correctly () const |
Checks that the parameters are set correctly. More... | |
virtual blitz::Array< double, 2 > | averaging_kernel () |
Returns the averaging kernel matrix. More... | |
virtual void | clear () |
Deletes data contents. More... | |
virtual blitz::Array< double, 1 > | cov_weighted_parameter_a_priori_diff () const |
Returns the current parameters value and their a priori value difference (current param - a priori param) weighted by the inverse of the Cholesky decomposition of the a priori covariance matrix. More... | |
virtual int | expected_parameter_size () const |
Returns the expected size of the parameters. More... | |
bool | jacobean_computed () const |
A boolean function to check whether or not the Jacobean of the model is computed. More... | |
virtual blitz::Array< double, 2 > | jacobian () |
Evaluates and returns the Jacobian of the model at the currently set parameter values. More... | |
virtual void | jacobian_eval ()=0 |
Evaluates the Jacobian of the model at the currently set parameter values. More... | |
virtual blitz::Array< double, 2 > | jacobian_x (const blitz::Array< double, 1 > &x) |
The model Jacobian with parameters. More... | |
virtual blitz::Array< double, 1 > | measurement () const |
Returns the measured data, to which the model is fit. More... | |
virtual blitz::Array< double, 1 > | measurement_error_cov () const |
Returns the measurement error covariance (implemented as a diagonal matrix). More... | |
virtual int | measurement_size () const |
Returns the size of the measurement data vector. More... | |
virtual blitz::Array< double, 1 > | model () |
Evaluates and returns the model at the currently set parameter values. More... | |
bool | model_computed () const |
A boolean function to check whether or not the model is computed. More... | |
virtual void | model_eval ()=0 |
Evaluates the model at the currently set parameter values. More... | |
virtual void | model_jacobian (blitz::Array< double, 1 > &m, blitz::Array< double, 2 > &k) |
Evaluates model and its Jacobian together. More... | |
virtual void | model_jacobian_eval () |
Evaluates the model and its Jacobian at the currently set parameter values. More... | |
virtual void | model_jacobian_x (const blitz::Array< double, 1 > &x, blitz::Array< double, 1 > &m, blitz::Array< double, 2 > &k) |
Model and its Jacobian with parameters. More... | |
virtual blitz::Array< double, 1 > | model_measure_diff () |
Returns model and measurement difference (model - measurement) More... | |
virtual blitz::Array< double, 1 > | model_measure_diff_aug () |
Returns the vector returned by model_measure_diff() augmented at the bottom by the vector returned by parameter_a_priori_diff() More... | |
virtual blitz::Array< double, 1 > | model_x (const blitz::Array< double, 1 > &x) |
The model function with parameters. More... | |
virtual blitz::Array< double, 1 > | param_a_posteriori_uncertainty () |
Returns the square root of the diagonal of the a-posteriori covariance matrix. More... | |
virtual blitz::Array< double, 1 > | param_a_priori_uncertainty () const |
Returns the square root of the diagonal of the a-priori covariance matrix. More... | |
virtual blitz::Array< double, 1 > | parameter_a_priori_diff () const |
Returns the current parameters value and their a priori value difference (current param - a priori param) More... | |
virtual int | parameter_size () const |
Returns the size of the parameters. More... | |
virtual void | parameters (const blitz::Array< double, 1 > &x) |
Sets the problem at a new point in the parameter space. More... | |
virtual blitz::Array< double, 1 > | parameters () const |
Returns the current parameters. More... | |
virtual bool | parameters_different (const blitz::Array< double, 1 > &x) const |
Checks whether or not new input parameters are different from the current ones. More... | |
virtual void | print (std::ostream &Os) const |
Prints description of object. More... | |
std::string | print_to_string () const |
Print to string. More... | |
virtual void | set (const ModelState &s) |
Makes self a copy of the input state. More... | |
virtual void | set (const ProblemState &s) |
Makes self a copy of the input state. More... | |
void | set_measurement (const blitz::Array< double, 1 > &measurement, const blitz::Array< double, 1 > &measurement_error_cov) |
For setting measurement and the error covariance matrix. More... | |
virtual blitz::Array< double, 2 > | uncert_weighted_jac_inner_product () |
Returns the inner product of the matrix returned by the method uncert_weighted_jacobian() by itself. More... | |
virtual blitz::Array< double, 2 > | uncert_weighted_jacobian () |
Returns the model Jacobian weighted by the inverse of the Cholesky decomposition of the error covariance matrix. More... | |
virtual blitz::Array< double, 1 > | uncert_weighted_model_measure_diff () |
Returns model and measurement difference weighted by the inverse of the Cholesky decomposition of the error covariance matrix. More... | |
virtual blitz::Array< double, 2 > | weighted_jacobian_aug () |
Returns the matrix returned by uncert_weighted_jacobian() augmented at the bottom by the matrix returned by a_priori_cov_chol_inv() More... | |
virtual blitz::Array< double, 1 > | weighted_model_measure_diff_aug () |
Returns the vector returned by uncert_weighted_model_measure_diff() augmented at the bottom by the vector returned by cov_weighted_parameter_a_priori_diff() More... | |
Protected Attributes | |
blitz::Array< double, 2 > | K |
blitz::Array< double, 1 > | M |
blitz::Array< double, 1 > | msrmnt |
blitz::Array< double, 2 > | Sa |
blitz::Array< double, 2 > | Sa_chol |
blitz::Array< double, 2 > | Sa_chol_inv |
blitz::Array< double, 1 > | Se |
blitz::Array< double, 1 > | Se_chol |
blitz::Array< double, 1 > | X |
blitz::Array< double, 1 > | Xa |
The base class for maximum a posteriori estimation.
This class is the base class for all classes that use maximum a posteriori estimation method to implement the problem of estimating the parameters of a statistical model.
Definition at line 15 of file max_a_posteriori.h.
MaxAPosteriori::MaxAPosteriori | ( | const blitz::Array< double, 1 > & | a_priori_params, |
const blitz::Array< double, 2 > & | a_priori_cov | ||
) |
Constructor.
[in] | a_priori_params | A priori knowledge on the parameters |
[in] | a_priori_cov | A priori covariance matrix |
Definition at line 20 of file max_a_posteriori.cc.
|
inlinevirtual |
Definition at line 35 of file max_a_posteriori.h.
|
virtual |
Returns a-posteriori covariance matrix.
After the parameters of the model are retrieved such that the model is fitted to the measurement data, then a call to this method returns the a-posteriori covariance matrix.
Assume the following:
Then this method returns
In the context of the Non-Linear Least Squares (NLLS) problem, where J is the Jacobian of the NLLS problem,
is known as the best fit covariance.
I am not sure where the best location to implement this method is. Maybe it is better to rename it best_fit_covariance() and add to the class NLLSProblem as a method. Or, maybe there are two different perspectives of the same thing:
If two perspectives, then perhaps it is best to keep a_posteriori_covariance() method here, and also implement best_fit_covariance() as a member of NLLSProblem class. If we decide to implement both methods, there will not be a lot of duplicate code because the body of a_posteriori_covariance() is just a function call.
Definition at line 76 of file max_a_posteriori.cc.
|
inlinevirtual |
Returns the a priori covariance matrix.
Definition at line 54 of file max_a_posteriori.h.
|
inlinevirtual |
Returns the Cholesky decomposition of the a-priori covariance matrix.
Assume
Then the Cholesky decomposition of the a priori covariance matrix is
and this method returns
Definition at line 407 of file max_a_posteriori.h.
|
inlinevirtual |
Returns the inverse of the Cholesky decomposition of the a priori covariance matrix.
Let the following be the a priori covariance matrix:
Then the Cholesky decomposition of the a priori covariance matrix is
and this method returns
The method cov_weighted_parameter_a_priori_diff() is the implementation of a function of the parameters and the method a_priori_cov_chol_inv() is the Jacobian of cov_weighted_parameter_a_priori_diff().
Definition at line 163 of file max_a_posteriori.h.
|
inlinevirtual |
Returns the a priori values (knowledge) of the parameters.
Definition at line 44 of file max_a_posteriori.h.
|
virtualinherited |
Conditions that must be satisfied when a derived class computes the Jacobian of the model.
This method is just the implementation of some conditions that must be satisfied after a derived class computes the Jacobian of the model. The derived class itself calls this method to check the computed Jacobian.
[in] | k | The computed model |
Definition at line 35 of file model_measure.cc.
|
virtualinherited |
Conditions that must be satisfied when a derived class computes the model.
This method is just the implementation of some conditions that must be satisfied after a derived class computes the model. The derived class itself calls this method to check the computed model.
[in] | m | The computed model |
Definition at line 28 of file model_measure.cc.
|
virtualinherited |
Checks that the new input parameters are correct.
This method checks to see whether or not the new input parameters are correct. If the parameters are not correct then it throws an exception.
Definition at line 44 of file problem_state.cc.
|
inlinevirtualinherited |
Checks that the parameters are set correctly.
This method checks to see whether or not the parameters are set correctly. If the parameters are not set correctly then it throws an exception.
Definition at line 197 of file problem_state.h.
|
virtual |
Returns the averaging kernel matrix.
This is another method that I am not sure about the best location for it. I chose it to be a method of this class because the class has all the data necessary to compute the averaging kernel.
Assume the following:
Then the averaging kernel is
Definition at line 91 of file max_a_posteriori.cc.
|
inlinevirtualinherited |
Deletes data contents.
This method deletes state. If needed, it must be reimplemented by other classes derived from this class to delete other saved components associated with the state as well.
Reimplemented from FullPhysics::ProblemState.
Definition at line 84 of file model_state.h.
|
virtual |
Returns the current parameters value and their a priori value difference (current param - a priori param) weighted by the inverse of the Cholesky decomposition of the a priori covariance matrix.
This method is for convenience. It returns the current parameters value and their a priori value difference weighted by the inverse of the Cholesky decomposition of the a priori covariance matrix.
This method does not have a good name. The "cov_weighted" portion of its name suggests that the difference is weighted by the a priori covariance matrix, but it is weighted by the inverse of the Cholesky decomposition of the covariance matrix.
Let the following be the current parameters value, the parameters a priori value, and the a priori covariance matrix respectively:
Then the Cholesky decomposition of the a priori covariance matrix is
and this method returns
Definition at line 36 of file max_a_posteriori.cc.
|
inlinevirtualinherited |
Returns the expected size of the parameters.
This method must be reimplemented by the problem class the inherits ProblemState. It is only in the context of an optimization problem that one knows what the size of the parameters (number of the dimensions of the parameter space) is.
This method is intentionally implemented here instead of being left as a pure virtual method. The intention is that the user to be able to create an object of this class or its derived classes for the purpose of preserving an older state of a problem if needed.
Reimplemented in FullPhysics::NLLSMaxAPosteriori, FullPhysics::NLLSMaxLikelihood, FullPhysics::NLLSProblemScaled, FullPhysics::ModelMeasureStandard, FullPhysics::ModelMeasureBard, FullPhysics::ModelMeasureMeyer, FullPhysics::FmNLLSProblem, FullPhysics::BardNLLSProblem, FullPhysics::BrownNLLSProblem, FullPhysics::FreudensteinRothNLLSProblem, FullPhysics::HelicalValleyNLLSProblem, FullPhysics::JennrichSampsonNLLSProblem, FullPhysics::MeyerNLLSProblem, FullPhysics::PowellNLLSProblem, FullPhysics::PowellSingularNLLSProblem, and FullPhysics::Rosenbrock2NLLSProblem.
Definition at line 185 of file problem_state.h.
|
inlineinherited |
A boolean function to check whether or not the Jacobean of the model is computed.
Definition at line 367 of file model_measure.h.
|
inlinevirtualinherited |
Evaluates and returns the Jacobian of the model at the currently set parameter values.
All the comments on jacobian_eval() method also apply to this method, and in addition this method returns the evaluated Jacobian.
The sizes of the Jacobian matrix can be obtained in advance:
Definition at line 190 of file model_measure.h.
|
pure virtualinherited |
Evaluates the Jacobian of the model at the currently set parameter values.
This method must be implemented by the classes derived from this class.
The parameters (the point in the parameter space) must have already been set before calling this method. The parameters are already set if one of the following methods is already called successfully:
If the parameters are already set, then this method evaluate the Jacobian of the model at the currently set parameter values (point in the parameter space).
Implemented in FullPhysics::ModelMeasureStandard, FullPhysics::ModelMeasureBard, and FullPhysics::ModelMeasureMeyer.
|
inlinevirtualinherited |
The model Jacobian with parameters.
This method also evaluates the Jacobian; however, it sets the model at the input new point and then evaluates its Jacobian.
The sizes of the Jacobian matrix can be obtained in advance:
[in] | x | New set of parameters |
Definition at line 211 of file model_measure.h.
|
inlinevirtualinherited |
Returns the measured data, to which the model is fit.
Definition at line 283 of file model_measure.h.
|
inlinevirtualinherited |
Returns the measurement error covariance (implemented as a diagonal matrix).
Definition at line 294 of file model_measure.h.
|
inlinevirtualinherited |
Returns the size of the measurement data vector.
This method returns the size of the measured data vector. The following must also be equal to the value returned by measurement_size():
Definition at line 312 of file model_measure.h.
|
inlinevirtualinherited |
Evaluates and returns the model at the currently set parameter values.
All the comments on model_eval() method also apply to this method, and in addition this method returns the evaluated model.
The size of the model vector can be obtained in advance by calling measurement_size().
Definition at line 128 of file model_measure.h.
|
inlineinherited |
A boolean function to check whether or not the model is computed.
Definition at line 356 of file model_measure.h.
|
pure virtualinherited |
Evaluates the model at the currently set parameter values.
This method must be implemented by the classes derived from this class.
The parameters (the point in the parameter space) must have already been set before calling this method. The parameters are already set if one of the following methods is already called successfully:
If the parameters are already set, then this method evaluate the model at the currently set parameter values (point in the parameter space).
Implemented in FullPhysics::ModelMeasureStandard, FullPhysics::ModelMeasureBard, and FullPhysics::ModelMeasureMeyer.
|
inlinevirtualinherited |
Evaluates model and its Jacobian together.
All the comments on model_jacobian_eval() method also apply to this method, and in addition this method passes to the caller the evaluated model and its Jacobian.
[out] | m | The model |
[out] | k | The Jacobian of the model |
Definition at line 251 of file model_measure.h.
|
inlinevirtualinherited |
Evaluates the model and its Jacobian at the currently set parameter values.
The parameters (the point in the parameter space) must have already been set before calling this method. The parameters are already set if one of the following methods is already called successfully:
If the parameters are already set, then this method evaluate the model and its Jacobian at the currently set parameter values (point in the parameter space).
Reimplemented in FullPhysics::ModelMeasureStandard, FullPhysics::ModelMeasureBard, and FullPhysics::ModelMeasureMeyer.
Definition at line 233 of file model_measure.h.
|
inlinevirtualinherited |
Model and its Jacobian with parameters.
This method passes to the caller the evaluated model and its Jacobian after setting the problem at the input new point.
[in] | x | New set of parameters |
[out] | m | The model |
[out] | k | The Jacobian of the model |
Definition at line 272 of file model_measure.h.
|
inlinevirtualinherited |
Returns model and measurement difference (model - measurement)
This method is for convenience. It returns the difference of the computed model and the measurement. The difference is not called residual on purpose. The term residual will be used in the context of the Non-Linear (or Linear) Least Squares optimization.
Let the following be the computed model and the measured data respectively
Then this method returns
Definition at line 410 of file model_measure.h.
|
virtual |
Returns the vector returned by model_measure_diff() augmented at the bottom by the vector returned by parameter_a_priori_diff()
This method is for convenience. It returns an augmented vector. The vectors returned by the following methods appear at the top and at the bottom of the augmented vector respectively:
Let the following be the computed model, the measured data, the current parameters value, and the parameters a priori value respectively:
Then this method returns
Definition at line 43 of file max_a_posteriori.cc.
|
inlinevirtualinherited |
The model function with parameters.
This method also evaluates the model; however, it sets the model at the input new point and then evaluates the model.
The size of the model vector can be obtained in advance by calling measurement_size().
[in] | x | New set of parameters |
Definition at line 147 of file model_measure.h.
|
virtual |
Returns the square root of the diagonal of the a-posteriori covariance matrix.
A-posteriori covariance matrix is returned by a_posteriori_covariance() method, and this method returns the square root of the diagonal of the matrix.
I am not sure where the best location for implementing this method is; however, it should be where a_posteriori_covariance() method is.
Definition at line 105 of file max_a_posteriori.cc.
|
virtual |
Returns the square root of the diagonal of the a-priori covariance matrix.
A-priori covariance matrix is returned by a_priori_cov() method, and this method returns the square root of the diagonal of the matrix.
Definition at line 98 of file max_a_posteriori.cc.
|
inlinevirtual |
Returns the current parameters value and their a priori value difference (current param - a priori param)
This method is for convenience. It returns the difference of the current parameters value and their a priori value.
Let the following be the current parameters value (a vector) and the parameters a prior value (another vector) respectively
Then this method returns
Definition at line 94 of file max_a_posteriori.h.
|
inlinevirtualinherited |
Returns the size of the parameters.
Definition at line 163 of file problem_state.h.
|
virtualinherited |
Sets the problem at a new point in the parameter space.
The method calls parameters_different() to determine whether or not the new parameters are different:
[in] | x | New set of parameters |
Reimplemented in FullPhysics::NLLSProblemScaled, FullPhysics::NLLSMaxAPosteriori, FullPhysics::NLLSMaxLikelihood, and FullPhysics::ModelMeasureStandard.
Definition at line 36 of file problem_state.cc.
|
inlinevirtualinherited |
Returns the current parameters.
Reimplemented in FullPhysics::NLLSProblemScaled, FullPhysics::NLLSMaxAPosteriori, FullPhysics::NLLSMaxLikelihood, and FullPhysics::ModelMeasureStandard.
Definition at line 153 of file problem_state.h.
|
virtualinherited |
Checks whether or not new input parameters are different from the current ones.
The methods checks to see whether or not the new input parameters (point in the parameter space) are different from the parameters maintained by the object for which the method is called.
If the size of the input parameters is not equal to the expected size of the parameters (check comments on expected_parameter_size), then the method will throw an exception.
If the object for which the method is called has currently no parameters set, then the method returns true. Otherwise, the method uses some algorithm to figure out when the difference is "big enough" to be considered different. If the method determines that the new input parameters are different from the current parameters, then it returns true, otherwise, it returns false.
[in] | x | New set of parameters |
Definition at line 9 of file problem_state.cc.
|
inlinevirtual |
Prints description of object.
Reimplemented from FullPhysics::ModelMeasure.
Reimplemented in FullPhysics::MaxAPosterioriStandard.
Definition at line 62 of file max_a_posteriori.h.
|
inlineinherited |
Print to string.
This is primarily useful for SWIG wrappers to this class, e.g. a to_s method in ruby.
Definition at line 31 of file printable.h.
|
virtualinherited |
Makes self a copy of the input state.
This method makes the object, for which it is called, a copy of the input state.
[in] | s | another ModelState |
Definition at line 7 of file model_state.cc.
|
inlinevirtualinherited |
Makes self a copy of the input state.
This method makes the object, for which it is called, a copy of the input state.
[in] | s | another ProblemState |
Definition at line 88 of file problem_state.h.
|
inherited |
For setting measurement and the error covariance matrix.
[in] | measurement | The measurement to which the model is to be fitted |
[in] | measurement_error_cov | The measurement error covariance matrix assumed to be diagonal (hence simply a vector containing the diagonal) |
Definition at line 9 of file model_measure.cc.
|
virtualinherited |
Returns the inner product of the matrix returned by the method uncert_weighted_jacobian() by itself.
Let the following be the computed model Jacobian and the measurement error covariance matrix respectively:
Then this method returns
Definition at line 54 of file model_measure.cc.
|
virtualinherited |
Returns the model Jacobian weighted by the inverse of the Cholesky decomposition of the error covariance matrix.
This method is for convenience. It returns the model Jacobian weighted by the Cholesky decomposition (roughly speaking the square root) of the error covariance matrix.
Let the following be the computed model Jacobian and the measurement error covariance matrix respectively:
Then the Cholesky decomposition of the error covariance matrix is
and this method returns
The method uncert_weighted_model_measure_diff() is another function of the parameters, and the method uncert_weighted_jacobian() is the Jacobian of uncert_weighted_model_measure_diff().
Definition at line 45 of file model_measure.cc.
|
inlinevirtualinherited |
Returns model and measurement difference weighted by the inverse of the Cholesky decomposition of the error covariance matrix.
This method is for convenience. It returns the difference of the computed model and measurement, model_measure_diff(), weighted by the Cholesky decomposition (roughly speaking the square root) of the error covariance matrix. In the name of this method "uncert" is the short for uncertainty, but probably using the word uncertainty or uncert in the name of this method is a bad Idea. In the implementation of this class the error covariance matrix is implemented as a diagonal matrix. However, if the matrix were not diagonal, still the purpose of this method would be to weight the model and the measurement difference with the Cholesky decomposition of the entire error covariance matrix.
Let the following be the computed model, the measured data, and the measurement error covariance matrix respectively:
Then the Cholesky decomposition of the error covariance matrix is
and this method returns
Definition at line 451 of file model_measure.h.
|
virtual |
Returns the matrix returned by uncert_weighted_jacobian() augmented at the bottom by the matrix returned by a_priori_cov_chol_inv()
This method is for convenience. It returns an augmented matrix. The matrices returned by the following methods appear at the top and at the bottom of the augmented matrix respectively:
Assume the following:
The Cholesky decomposition of the error covariance matrix is
and the Cholesky decomposition of the a priori covariance matrix is
Then this method returns
The method weighted_model_measure_diff_aug() is another function of the parameters, and the method weighted_jacobian_aug() is the Jacobian of weighted_model_measure_diff_aug().
Definition at line 65 of file max_a_posteriori.cc.
|
virtual |
Returns the vector returned by uncert_weighted_model_measure_diff() augmented at the bottom by the vector returned by cov_weighted_parameter_a_priori_diff()
This method is for convenience. It returns an augmented vector. The vectors returned by the following methods appear at the top and at the bottom of the augmented vector respectively:
Assume the following:
The Cholesky decomposition of the error covariance matrix is
and the Cholesky decomposition of the a priori covariance matrix is
Then this method returns
Definition at line 54 of file max_a_posteriori.cc.
|
protectedinherited |
Definition at line 99 of file model_state.h.
|
protectedinherited |
Definition at line 98 of file model_state.h.
|
protectedinherited |
Definition at line 512 of file model_measure.h.
|
protected |
Definition at line 447 of file max_a_posteriori.h.
|
protected |
Definition at line 450 of file max_a_posteriori.h.
|
protected |
Definition at line 451 of file max_a_posteriori.h.
|
protectedinherited |
Definition at line 513 of file model_measure.h.
|
protectedinherited |
Definition at line 516 of file model_measure.h.
|
protectedinherited |
Definition at line 222 of file problem_state.h.
|
protected |
Definition at line 446 of file max_a_posteriori.h.