ReFRACtor
max_a_posteriori.cc
Go to the documentation of this file.
1 #include <max_a_posteriori.h>
2 #include <fp_exception.h>
3 #include <linear_algebra.h>
4 
5 
6 using namespace FullPhysics;
7 using namespace blitz;
8 
9 
10 
11 #ifdef HAVE_LUA
12 #include "register_lua.h"
14 .def("param_a_priori_uncertainty", &MaxAPosteriori::param_a_priori_uncertainty)
16 #endif
17 
18 
19 
20 MaxAPosteriori::MaxAPosteriori(const blitz::Array<double, 1>& a_priori_params,
21  const blitz::Array<double, 2>& a_priori_cov)
22  : Xa(a_priori_params.copy()), Sa(a_priori_cov.copy())
23 {
24  if(Xa.rows() <= 0)
25  throw Exception("The size of the a priori parameter values array is zero.");
26  if(Sa.rows() != Sa.cols() )
27  throw Exception("The a priori covariance matrix must be a square matrix.");
28  if(Sa.rows() != Xa.rows() )
29  throw Exception("The number of rows and columns of a priori covariance matrix must equal the size of the a priori parameter values array.");
30 
31  Sa_chol.reference(cholesky_decomposition(Sa));
32  Sa_chol_inv.reference(generalized_inverse(Sa_chol,1e-20));
33 }
34 
35 
37 {
38  firstIndex i1; secondIndex i2;
39  return blitz::Array<double, 1>(sum(Sa_chol_inv(i1, i2) * parameter_a_priori_diff()(i2), i2));
40 }
41 
42 
44 {
45  Array<double, 1> temp(measurement_size()+parameter_size());
46  Range r1(0, measurement_size()-1);
47  Range r2(measurement_size(), temp.rows()-1);
48  temp(r1) = model_measure_diff();
49  temp(r2) = parameter_a_priori_diff();
50  return temp;
51 }
52 
53 
55 {
56  Array<double, 1> temp(measurement_size()+parameter_size());
57  Range r1(0, measurement_size()-1);
58  Range r2(measurement_size(), temp.rows()-1);
61  return temp;
62 }
63 
64 
66 {
67  Array<double, 2> temp(measurement_size()+parameter_size(), parameter_size());
68  Range r1(0, measurement_size()-1);
69  Range r2(measurement_size(), temp.rows()-1);
70  temp(r1, Range::all()) = uncert_weighted_jacobian();
71  temp(r2, Range::all()) = Sa_chol_inv;
72  return temp;
73 }
74 
75 
77 {
78  // Two ways to compute the returned value.
79  // The first one is commented out.
80  // The second one is a numerically more stable
81  // and better way of computing the result.
82 
83 // Array<double, 2> temp(weighted_jacobian_aug());
84 // firstIndex i1; secondIndex i2; thirdIndex i3;
85 // return generalized_inverse(Array<double, 2>(sum(temp(i3,i1)*temp(i3,i2), i3)));
86 
88 }
89 
90 
92 {
93  firstIndex i1; secondIndex i2; thirdIndex i3;
94  return Array<double, 2>(sum(a_posteriori_covariance()(i1,i3)*uncert_weighted_jac_inner_product()(i3,i2), i3));
95 }
96 
97 
99 {
100  firstIndex i1;
101  return Array<double, 1>(sqrt(Sa(i1,i1)));
102 }
103 
104 
106 {
107  firstIndex i1;
108  return Array<double, 1>(sqrt(a_posteriori_covariance()(i1,i1)));
109 }
virtual blitz::Array< double, 2 > weighted_jacobian_aug()
Returns the matrix returned by uncert_weighted_jacobian() augmented at the bottom by the matrix retur...
virtual blitz::Array< double, 1 > model_measure_diff()
Returns model and measurement difference (model - measurement)
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...
blitz::Array< double, 2 > Sa_chol_inv
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 pa...
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...
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...
virtual int parameter_size() const
Returns the size of the parameters.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
blitz::Array< double, 2 > cholesky_decomposition(const blitz::Array< double, 2 > &A)
This calculates the Cholesky Decompostion of A so that A = L L^T.
virtual blitz::Array< double, 2 > uncert_weighted_jacobian()
Returns the model Jacobian weighted by the inverse of the Cholesky decomposition of the error covaria...
MaxAPosteriori(const blitz::Array< double, 1 > &a_priori_params, const blitz::Array< double, 2 > &a_priori_cov)
Constructor.
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 ve...
blitz::Array< double, 2 > Sa
#define REGISTER_LUA_CLASS(X)
Definition: register_lua.h:116
virtual int measurement_size() const
Returns the size of the measurement data vector.
Apply value function to a blitz array.
blitz::Array< double, 1 > Xa
virtual blitz::Array< double, 2 > a_posteriori_covariance()
Returns a-posteriori covariance matrix.
blitz::Array< double, 2 > multifit_covar(const blitz::Array< double, 2 > &J, double Eps_rel=std::numeric_limits< double >::epsilon())
The base class for maximum a posteriori estimation.
blitz::Array< double, 2 > generalized_inverse(const blitz::Array< double, 2 > &A, double Rcond=std::numeric_limits< double >::epsilon())
This returns the generalized inverse of the given matrix.
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 pa...
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
#define REGISTER_LUA_END()
Definition: register_lua.h:134
virtual blitz::Array< double, 1 > param_a_priori_uncertainty() const
Returns the square root of the diagonal of the a-priori covariance matrix.
virtual blitz::Array< double, 1 > param_a_posteriori_uncertainty()
Returns the square root of the diagonal of the a-posteriori covariance matrix.
blitz::Array< double, 2 > Sa_chol
virtual blitz::Array< double, 2 > averaging_kernel()
Returns the averaging kernel matrix.

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10