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

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