ReFRACtor
initial_guess_value.cc
Go to the documentation of this file.
1 #include "initial_guess_value.h"
2 #include "ostream_pad.h"
3 #include "fp_exception.h"
4 
5 using namespace FullPhysics;
6 using namespace blitz;
7 
8 #ifdef HAVE_LUA
9 #include "register_lua.h"
10 typedef const blitz::Array<double, 1>& (InitialGuessValue::*a1)(void) const;
11 typedef void (InitialGuessValue::*a2)(const blitz::Array<double, 1>&);
12 typedef const blitz::Array<double, 2>& (InitialGuessValue::*b1)(void) const;
13 typedef void (InitialGuessValue::*b2)(const blitz::Array<double, 2>&);
14 double initial_guess_value_apriori_double_get(const InitialGuessValue& ig)
15 { return ig.apriori()(0); }
16 void initial_guess_value_apriori_double_set(InitialGuessValue& ig,
17  double val)
18 { Array<double, 1> v(1);
19  v(0) = val;
20  ig.apriori(v);
21 }
22 double initial_guess_value_initial_guess_double_get(const InitialGuessValue& ig)
23 { return ig.initial_guess()(0); }
24 void initial_guess_value_initial_guess_double_set(InitialGuessValue& ig,
25  double val)
26 { Array<double, 1> v(1);
27  v(0) = val;
28  ig.initial_guess(v);
29 }
30 double initial_guess_value_apriori_cov_double_get(const InitialGuessValue& ig)
31 { return ig.apriori_covariance()(0, 0); }
32 void initial_guess_value_apriori_cov_double_set(InitialGuessValue& ig,
33  double val)
34 { Array<double, 2> v(1,1);
35  v(0,0) = val;
36  ig.apriori_covariance(v);
37 }
38 
40 .def(luabind::constructor<>())
41 .property("apriori",
43  ((a2) &InitialGuessValue::apriori))
44 .def("apriori_subset", &InitialGuessValue::apriori_subset)
45 .def("initial_guess_subset", &InitialGuessValue::initial_guess_subset)
46 .def("apriori_covariance_subset",
48 .property("apriori_double",
49  &initial_guess_value_apriori_double_get,
50  &initial_guess_value_apriori_double_set)
51 .property("initial_guess",
53  ((a2) &InitialGuessValue::initial_guess))
54 .property("initial_guess_double",
55  &initial_guess_value_initial_guess_double_get,
56  &initial_guess_value_initial_guess_double_set)
57 .property("apriori_covariance",
59  ((b2) &InitialGuessValue::apriori_covariance))
60 .property("apriori_covariance_double",
61  &initial_guess_value_apriori_cov_double_get,
62  &initial_guess_value_apriori_cov_double_set)
64 #endif
65 
66 //-----------------------------------------------------------------------
68 //-----------------------------------------------------------------------
69 
71 (const blitz::Array<bool, 1>& Flag,
72  const blitz::Array<double, 1>& V)
73 {
74  if(Flag.rows() != V.rows()) {
75  std::stringstream err_msg;
76  err_msg << "Flag and apriori need to be same size. "
77  << Flag.rows() << " != " << V.rows();
78  throw Exception(err_msg.str());
79  }
80  apriori_.resize(count(Flag));
81  int ind = 0;
82  for(int i = 0; i < V.rows(); ++i)
83  if(Flag(i))
84  apriori_(ind++) = V(i);
85 }
86 
87 //-----------------------------------------------------------------------
89 //-----------------------------------------------------------------------
90 
92 (const blitz::Array<bool, 1>& Flag,
93  const blitz::Array<double, 1>& V)
94 {
95  if(Flag.rows() != V.rows()) {
96  std::stringstream err_msg;
97  err_msg << "Flag and initial guess need to be same size. "
98  << Flag.rows() << " != " << V.rows();
99  throw Exception(err_msg.str());
100  }
101  initial_guess_.resize(count(Flag));
102  int ind = 0;
103  for(int i = 0; i < V.rows(); ++i)
104  if(Flag(i))
105  initial_guess_(ind++) = V(i);
106 }
107 
108 //-----------------------------------------------------------------------
110 //-----------------------------------------------------------------------
111 
113 (const blitz::Array<bool, 1>& Flag,
114  const blitz::Array<double, 2>& V)
115 {
116  if(Flag.rows() != V.rows() ||
117  Flag.rows() != V.cols()) {
118  std::stringstream err_msg;
119  err_msg << "Flag and covariance need to be same size. "
120  << Flag.rows() << " != " << "[ " << V.rows() << ", " << V.cols() << " ]";
121  throw Exception(err_msg.str());
122  }
123 
124  apriori_covariance_.resize(count(Flag), count(Flag));
125  int ind1 = 0;
126  for(int i = 0; i < V.rows(); ++i)
127  if(Flag(i)) {
128  int ind2 = 0;
129  for(int j = 0; j < V.cols(); ++j)
130  if(Flag(j))
131  apriori_covariance_(ind1, ind2++) = V(i, j);
132  ++ind1;
133  }
134 }
135 
136 void InitialGuessValue::build_initial_value(blitz::Array<double, 1>& v,
137  int index) const
138 {
139  if(number_element() == 0)
140  return;
141  if(initial_guess().rows() != number_element()) {
142  Exception e;
143  e << "initial_guess() in InitialGuessValue has " << initial_guess().rows()
144  << " elements, but apriori has " << number_element();
145  throw e;
146  }
147  v(Range(index, index + number_element() - 1)) = initial_guess();
148 }
149 
150 void InitialGuessValue::build_apriori(blitz::Array<double, 1>& v,
151  int index) const
152 {
153  if(number_element() == 0)
154  return;
155  v(Range(index, index + number_element() - 1)) = apriori();
156 }
157 
158 void InitialGuessValue::build_apriori_covariance(blitz::Array<double, 2>& m,
159  int index) const
160 {
161  if(number_element() == 0)
162  return;
163  if(apriori_covariance().rows() != number_element() ||
164  apriori_covariance().cols() != number_element()) {
165  Exception e;
166  e << "apriori_covariance() in InitialGuessValue has "
167  << apriori_covariance().rows() << " x " << apriori_covariance().cols()
168  << " elements, but apriori has " << number_element();
169  throw e;
170  }
171  Range r(index, index + number_element() - 1);
172  m(r, r) = apriori_covariance();
173 }
174 
175 void InitialGuessValue::print(std::ostream& Os) const
176 {
177  Os << "InitialGuessValue:\n";
178  OstreamPad opad(Os, " ");
179  Os << "Apriori:\n" << apriori() << "\n"
180  << "Initial guess:\n" << initial_guess() << "\n"
181  << "Covariance:\n" << apriori_covariance() << "\n";
182 }
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
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.
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
void apriori_covariance_subset(const blitz::Array< bool, 1 > &Flag, const blitz::Array< double, 2 > &V)
Subset a value to include only those elements where Flag is true.
Apply value function to a blitz array.
virtual void print(std::ostream &Os) const
Class that builds a portion of the state vector.
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.
This is a simple implementation of InitialGuessBuilder that just has variables used to give the aprio...
const Unit m("m", 1.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
const blitz::Array< double, 2 > & apriori_covariance() const
Apriori covariance value.
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 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...
void apriori_subset(const blitz::Array< bool, 1 > &Flag, const blitz::Array< double, 1 > &V)
Subset a value to include only those elements where Flag is true.
void initial_guess_subset(const blitz::Array< bool, 1 > &Flag, const blitz::Array< double, 1 > &V)
Subset a value to include only those elements where Flag is true.
const blitz::Array< double, 1 > & apriori() const
Apriori value.
const blitz::Array< double, 1 > & initial_guess() const
First guess value.

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