ReFRACtor
nlls_problem_scaled.cc
Go to the documentation of this file.
1 #include "nlls_problem_scaled.h"
2 #include "fp_exception.h"
3 
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 #ifdef HAVE_LUA
8 #include "register_lua.h"
9 
10 boost::shared_ptr<CostFunc> create_nlls_problem_scaled
11 (const Array<double, 1>& S,
13 {
14  boost::shared_ptr<NLLSProblem> p = boost::dynamic_pointer_cast<NLLSProblem>(Cf);
16 }
17 
19 .def(luabind::constructor< const Array<double, 1>&, const boost::shared_ptr<NLLSProblem>& >())
20 .def("parameters", (void( NLLSProblemScaled::*)(const blitz::Array<double, 1>&))&NLLSProblemScaled::parameters)
21 .def("scale_parameters", &NLLSProblemScaled::scale_parameters)
22 .scope
23 [
24  luabind::def("create", &create_nlls_problem_scaled)
25 ]
27 #endif
28 
29 
30 
31 NLLSProblemScaled::NLLSProblemScaled( const Array<double, 1>& s,
33  : NLLSProblem(), S(s.copy()), P(p)
34 {
35  if(s.rows() != P->expected_parameter_size()) {
36  Exception e;
37  e << "Parameter space scaling diagonal matrix and parameters not equal in size:\n"
38  << " Parameter size " << P->expected_parameter_size()
39  << " Parameter space scaling diagonal matrix size " << s.rows();
40  throw e;
41  }
42 }
43 
44 
45 Array<double, 1> NLLSProblemScaled::residual()
46 {
48  P->parameters(unscale_parameters(X));
49  Array<double, 1> R(P->residual());
50 
51  // Depending on the developers intention, one of
52  // the following two methods can be used to update
53  // the cost evaluation counter. Just be consistent
54  // with the method used to update gradient (first
55  // order derivatives) evaluation counter in the
56  // method NLLSProblemScaled::jacobian()
57  //
58  set_num_cost_evaluations(P->num_residual_evaluations());
59 // increment_num_cost_evaluations();
60 
61  return R;
62 }
63 
64 
65 Array<double, 2> NLLSProblemScaled::jacobian()
66 {
68  P->parameters(unscale_parameters(X));
69  Array<double, 2> J(P->jacobian());
70  firstIndex i1; secondIndex i2;
71  J = J(i1,i2)*S(i2);
72 
73  // Depending on the developers intention, one of
74  // the following two methods can be used to update
75  // the gradient (first order derivatives) evaluation
76  // counter. Just be consistent with the method used
77  // to update cost evaluation counter in the method
78  // NLLSProblemScaled::residual()
79  //
80  set_num_der1_evaluations(P->num_jacobian_evaluations());
81 // increment_num_der1_evaluations();
82 
83  return J;
84 }
85 
86 
87 Array<double, 1> NLLSProblemScaled::scale_parameters(const Array<double, 1>& x) const
88 {
89  Array<double,1> _x_(x.copy());
90  for(int i=0; i<_x_.rows(); i++)
91  if(S(i)) _x_(i) /= S(i);
92  return _x_;
93 }
94 
95 
96 Array<double, 1> NLLSProblemScaled::unscale_parameters(const Array<double, 1>& x) const
97 {
98  Array<double,1> _x_(x.copy());
99  for(int i=0; i<_x_.rows(); i++)
100  if(S(i)) _x_(i) *= S(i);
101  return _x_;
102 }
103 
104 
105 void NLLSProblemScaled::parameters(const blitz::Array<double, 1>& x)
106 {
107  P->parameters(unscale_parameters(x));
109 }
virtual blitz::Array< double, 1 > residual()
Return the residual of the scaled NLLS problem at the current set point.
virtual void set_num_der1_evaluations(int count)
Sets the gradient evaluation counter to a desired value.
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
virtual void assert_parameter_set_correctly() const
Checks that the parameters are set correctly.
virtual void set_num_cost_evaluations(int count)
Sets the cost evaluation counter to a desired value.
Definition: cost_func.h:213
NLLSProblemScaled(const blitz::Array< double, 1 > &s, const boost::shared_ptr< NLLSProblem > &p)
Default Constructor.
blitz::Array< double, 1 > X
virtual blitz::Array< double, 2 > jacobian()
Return the Jacobian of the residual of the scaled 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.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
const Unit J("J", N *m)
virtual blitz::Array< double, 1 > parameters() const
Just returns the current values of parameters.
Apply value function to a blitz array.
The base class for the Non-Linear Least Squares problem.
Definition: nlls_problem.h:54
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
def(luabind::constructor< int >()) .def("rows"
virtual blitz::Array< double, 1 > scale_parameters(const blitz::Array< double, 1 > &x) const
If x is the input to the NLLS problem that this class is trying to scale, then this method scales the...
boost::shared_ptr< NLLSProblem > P
virtual blitz::Array< double, 1 > unscale_parameters(const blitz::Array< double, 1 > &x) const
The input is correctly scaled to be used as input to this scaled NLLS problem.
blitz::Array< double, 1 > S

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