ReFRACtor
fm_nlls_problem.cc
Go to the documentation of this file.
1 #include "fm_nlls_problem.h"
2 #include "linear_algebra.h"
3 
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 //-----------------------------------------------------------------------
9 //-----------------------------------------------------------------------
10 
14  const Array<double, 1>& Rad,
15  const Array<double, 1>& Rad_uncer,
16  const Array<double, 1> X_apriori,
17  const Array<double, 2> Apriori_cov)
18 : fm(Fm), statev(Sv), rad(Rad.copy()), x_a(X_apriori.copy())
19 {
20  if(Rad.rows() != Rad_uncer.rows())
21  throw Exception("Rad and Rad_uncer need to be the same size");
22  if(X_apriori.rows() != Apriori_cov.rows() ||
23  Apriori_cov.rows() != Apriori_cov.cols())
24  throw Exception("Apriori_cov needs to be square, and the same size a X_apriori");
25  se_sqrt_inv.resize(Rad_uncer.shape());
26  se_sqrt_inv = 1 / Rad_uncer;
27  sa_sqrt_inv.
28  reference(generalized_inverse(cholesky_decomposition(Apriori_cov)));
29 }
30 
31 // See base class for description.
32 Array<double, 1> FmNLLSProblem::residual()
33 {
34  assert_parameter_set_correctly();
35  firstIndex i1; secondIndex i2;
36  Array<double, 1> res(rad.rows() + sa_sqrt_inv.rows());
37  Range r1(0, rad.rows() - 1);
38  Range r2(rad.rows(), res.rows() - 1);
39  statev->update_state(X);
40  res(r1) = (fm->radiance_all(true).spectral_range().data() - rad) *
41  se_sqrt_inv;
42  res(r2) = sum(sa_sqrt_inv(i1, i2) * (X(i2) - x_a(i2)));
43  return res;
44 }
45 
46 // See base class for description.
47 Array<double, 2> FmNLLSProblem::jacobian()
48 {
49  assert_parameter_set_correctly();
50  firstIndex i1; secondIndex i2; thirdIndex i3;
51  Array<double, 2> res(rad.rows() + sa_sqrt_inv.rows(),
52  sa_sqrt_inv.cols());
53  Range r1(0, rad.rows() - 1);
54  Range r2(rad.rows(), res.rows() - 1);
55  statev->update_state(X);
56  ArrayAd<double, 1> fmrad = fm->radiance_all().spectral_range().data_ad();
57  res(r1, Range::all()) = fmrad.jacobian()(i1, i2) * se_sqrt_inv(i1);
58  res(r2, Range::all()) = sa_sqrt_inv;
59  return res;
60 }
FmNLLSProblem(const boost::shared_ptr< ForwardModel > &Fm, const boost::shared_ptr< StateVector > &Sv, const blitz::Array< double, 1 > &Rad, const blitz::Array< double, 1 > &Rad_uncer, const blitz::Array< double, 1 > X_apriori, const blitz::Array< double, 2 > Apriori_cov)
Constructor.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
blitz::Array< double, 2 > cholesky_decomposition(const blitz::Array< double, 2 > &A)
This calculates the Cholesky Decompostion of A so that A = L L^T.
const blitz::Array< T, D+1 > jacobian() const
Definition: array_ad.h:307
Apply value function to a blitz array.
blitz::Array< double, 2 > generalized_inverse(const blitz::Array< double, 2 > &A, double Rcond=std::numeric_limits< double >::epsilon())
This returns the generalized inverse of the given matrix.
virtual blitz::Array< double, 2 > jacobian()
The Jacobian matrix function.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
const Unit rad("rad", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0)
virtual blitz::Array< double, 1 > residual()
The residual vector function.

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