ReFRACtor
composite_initial_guess.cc
Go to the documentation of this file.
2 #include <boost/foreach.hpp>
3 
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 #ifdef HAVE_LUA
8 #include "register_lua.h"
9 // Lua has trouble with the multiple inheritance of
10 // CompositeInitialGuess, so add a add_builder that has the right type
11 // without needed to convert to InitialGuessBuilder
12 void composite_initial_guess_add_builder(CompositeInitialGuess& Ig,
14 {
15  Ig.add_builder(boost::dynamic_pointer_cast<CompositeInitialGuess>(V));
16 }
17 void composite_initial_guess_add_builder2(CompositeInitialGuess& Ig,
19 {
20  Ig.add_builder(boost::dynamic_pointer_cast<CompositeInitialGuess>(V));
21 }
22 
26 .def(luabind::constructor<>())
27 .def("add_builder", &CompositeInitialGuess::add_builder)
28 .def("add_builder", &composite_initial_guess_add_builder)
29 .def("add_builder", &composite_initial_guess_add_builder2)
31 #endif
32 
33 //-----------------------------------------------------------------------
35 //-----------------------------------------------------------------------
36 
37 blitz::Array<double, 1> CompositeInitialGuess::initial_guess() const
38 {
39  blitz::Array<double, 1> res(number_element());
40  int index = 0;
41  BOOST_FOREACH(const boost::shared_ptr<InitialGuessBuilder>& v, blist) {
42  v->build_initial_value(res, index);
43  index += v->number_element();
44  }
45  return res;
46 }
47 
48 //-----------------------------------------------------------------------
50 //-----------------------------------------------------------------------
51 
53 {
54  int res = 0;
55  BOOST_FOREACH(const boost::shared_ptr<InitialGuessBuilder>& v, blist)
56  res += v->number_element();
57  return res;
58 }
59 
60 //-----------------------------------------------------------------------
62 //-----------------------------------------------------------------------
63 
64 blitz::Array<double, 1> CompositeInitialGuess::apriori() const
65 {
66  blitz::Array<double, 1> res(number_element());
67  int index = 0;
68  BOOST_FOREACH(const boost::shared_ptr<InitialGuessBuilder>& v, blist) {
69  v->build_apriori(res, index);
70  index += v->number_element();
71  }
72  return res;
73 }
74 
75 //-----------------------------------------------------------------------
77 //-----------------------------------------------------------------------
78 
80 const
81 {
82  int n = number_element();
83  // Create array in Fortran Column major order, but still use a 0 base.
84  blitz::Array<double, 2> res(n,n,blitz::ColumnMajorArray<2>());
85  res = 0.0;
86  int index = 0;
87  BOOST_FOREACH(const boost::shared_ptr<InitialGuessBuilder>& v, blist) {
88  v->build_apriori_covariance(res, index);
89  index += v->number_element();
90  }
91  return res;
92 }
93 
94 //-----------------------------------------------------------------------
96 //-----------------------------------------------------------------------
97 
98 void CompositeInitialGuess::print(std::ostream& Os) const
99 {
100  Os << "Composite Initial Guess";
101 }
102 
104 (blitz::Array<double, 1>& v, int index) const
105 {
106  if(number_element() == 0)
107  return;
108  v(Range(index, index + number_element() - 1)) = initial_guess();
109 }
110 
112 (blitz::Array<double, 1>& v, int index) const
113 {
114  if(number_element() == 0)
115  return;
116  v(Range(index, index + number_element() - 1)) = apriori();
117 }
118 
120 (blitz::Array<double, 2>& m, int index) const
121 {
122  if(number_element() == 0)
123  return;
124  Range r(index, index + number_element() - 1);
125  m(r, r) = apriori_covariance();
126 }
127 
128 
129 
virtual blitz::Array< double, 1 > initial_guess() const
Return the initial state vector to use.
void add_builder(const boost::shared_ptr< InitialGuessBuilder > &B)
Add a builder to the build list.
virtual blitz::Array< double, 1 > apriori() const
Return the apriori state vector to use.
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
A common way to create an initial guess is to have other classes responsible for portions of the stat...
#define REGISTER_LUA_CLASS(X)
Definition: register_lua.h:116
Apply value function to a blitz array.
Class that builds a portion of the state vector.
virtual void build_initial_value(blitz::Array< double, 1 > &v, int index) const
Called when we need this class to do its part in setting up the initial state vector.
const Unit m("m", 1.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
virtual int number_element() const
Number of elements that will be in the state vector.
virtual void print(std::ostream &Os) const
Print description of object.
virtual void build_apriori(blitz::Array< double, 1 > &v, int index) const
Called when we need this class to do its part in setting up the apriori state vector.
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"
This gets the initial guess and the apriori state vector values.
Definition: initial_guess.h:12
virtual void build_apriori_covariance(blitz::Array< double, 2 > &m, int index) const
Called when we need this class to do its part in setting up the covariance matrix for the a priori st...
virtual blitz::Array< double, 2 > apriori_covariance() const
Return the apriori state vector covariance to use.

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