ReFRACtor
nlls_max_a_posteriori.cc
Go to the documentation of this file.
2 
3 
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 
8 
9 #ifdef HAVE_LUA
10 #include "register_lua.h"
12 .def(luabind::constructor< const boost::shared_ptr<MaxAPosteriori>& >())
13 .def("parameters", (void( NLLSMaxAPosteriori::*)(const blitz::Array<double, 1>&))&NLLSMaxAPosteriori::parameters)
14 .def("max_a_posteriori", &NLLSMaxAPosteriori::max_a_posteriori)
16 #endif
17 
18 
19 
20 Array<double, 1> NLLSMaxAPosteriori::residual()
21 {
22  if(R.size() <= 0) {
23 
24  assert_parameter_set_correctly();
25 // MAP->parameters(X); // If everything implemented correctly,
26  // there should be no need for this.
27 
28  // For some mathematical models it is just practical to compute
29  // the model and its Jacobian at the same time. Here, we want to
30  // check whether or not the model assigned to this NLLS adaptor
31  // (MAPE-problem to NLLS-problem) is implemented such that the
32  // model and its Jacobian are computed simultaneously.
33  //
34  bool j_computed_before = MAP->jacobean_computed();
35  MAP->model_eval();
36  bool j_computed_after = MAP->jacobean_computed();
37 
38  // If the model Jacobian is computed as well when the model
39  // is computed, here we may as well compute the NLLS problem
40  // residual Jacobian, which is not the same as the model Jacobian.
41  // Usually the computation of the model Jacobian is much more
42  // expensive than the computation of the residual Jacobian based
43  // on the model Jacobian.
44  //
45  if( (!j_computed_before) && j_computed_after ) {
46  increment_num_der1_evaluations();
47  J.reference(MAP->weighted_jacobian_aug());
48  }
49 
50  // Compute the NLLS problem residual.
51  //
52  increment_num_cost_evaluations();
53  R.reference(MAP->weighted_model_measure_diff_aug());
54 
55  }
56  return R.copy();
57 }
58 
59 
60 Array<double, 2> NLLSMaxAPosteriori::jacobian()
61 {
62  if(J.size() <= 0) {
63 
64  assert_parameter_set_correctly();
65 // MAP->parameters(X);
66 
67  // For some mathematical models it is just practical to compute
68  // the model and its Jacobian at the same time. Here, we want to
69  // check whether or not the model assigned to this NLLS adaptor
70  // (MAPE-problem to NLLS-problem) is implemented such that the
71  // model and it Jacobian are computed simultaneously.
72  //
73  bool m_computed_before = MAP->model_computed();
74  MAP->jacobian_eval();
75  bool m_computed_after = MAP->model_computed();
76 
77  // If the model is computed as well when the model Jacobian
78  // is computed, here we may as well compute the NLLS problem
79  // residual, which is not the same as the model. Usually the
80  // computation of the model is much more expensive than the
81  // computation of the residual based on the model.
82  //
83  if( (!m_computed_before) && m_computed_after ) {
84  increment_num_cost_evaluations();
85  R.reference(MAP->weighted_model_measure_diff_aug());
86  }
87 
88  // Compute the NLLS problem residual Jacobian.
89  //
90  increment_num_der1_evaluations();
91  J.reference(MAP->weighted_jacobian_aug());
92 
93  }
94  return J.copy();
95 }
96 
97 
98 void NLLSMaxAPosteriori::parameters(const blitz::Array<double, 1>& x)
99 {
100  MAP->parameters(x);
102 }
virtual blitz::Array< double, 1 > residual()
Return the residual of the NLLS problem at the current set point.
The base class for all problem classes that implement a cost function.
Definition: cost_func.h:20
virtual blitz::Array< double, 1 > parameters() const
Returns the current parameters.
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
const Unit J("J", N *m)
Apply value function to a blitz array.
virtual blitz::Array< double, 2 > jacobian()
Return the Jacobian of the residual of the NLLS problem at the current set point. ...
virtual blitz::Array< double, 1 > parameters() const
Just returns the current values of parameters.
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
boost::shared_ptr< MaxAPosteriori > max_a_posteriori()

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