1 #ifndef CONNOR_SOLVER_H 2 #define CONNOR_SOLVER_H 6 #include <blitz/array.h> 7 #include <boost/shared_ptr.hpp> 8 #include <boost/utility.hpp> 55 class ConnorSolverState;
70 double Gamma_initial = 0.0,
71 const std::string& Save_test_data =
"")
94 blitz::Array<double, 1>& Dx,
95 blitz::Array<double, 2>& Kt_se_m1_k);
96 virtual bool solve(
const blitz::Array<double, 1>& Initial_guess,
97 const blitz::Array<double, 1>& Apriori,
98 const blitz::Array<double, 2>& Apriori_cov);
173 virtual blitz::Array<double, 2>
jacobian()
const {
return k;}
202 void print(std::ostream& Os)
const { Os <<
"ConnorSolver";}
225 blitz::Array<double, 1>
se;
232 blitz::Array<double, 2>
k;
289 blitz::Array<double, 1>
x_a;
297 blitz::Array<double, 1>
x_i;
315 blitz::Array<double, 1>
dx;
345 const blitz::Array<double, 1>& X_a,
346 const blitz::Array<double, 2>& Apriori_cov_scaled,
347 const blitz::Array<double, 2>& Sa_m1_scaled,
348 const blitz::Array<double, 1>& Sigma_ap,
349 double Gamma,
double Gamma_last_step,
double Gamma_intial,
350 const blitz::Array<double, 1>& Residual,
351 const blitz::Array<double, 1>& Se,
352 const blitz::Array<double, 2>&
K,
353 const blitz::Array<double, 2>& Kt_se_m1_k,
354 const blitz::Array<double, 1>& Dx,
356 : x_i_(X_i.copy()), x_a_(X_a.copy()),
357 apriori_cov_scaled_(Apriori_cov_scaled.copy()),
358 sa_m1_scaled_(Sa_m1_scaled.copy()),
359 sigma_ap_(Sigma_ap.copy()), gamma_(Gamma),
361 residual_(Residual.copy()), se_(Se.copy()), k_(K.copy()),
362 kt_se_m1_k_(Kt_se_m1_k.copy()), dx_(Dx.copy()), fstat_(Fstat)
366 { Os <<
"ConnorSolverState"; }
367 const blitz::Array<double, 1>&
x_i()
const {
return x_i_;}
368 const blitz::Array<double, 1>&
x_a()
const {
return x_a_;}
370 {
return apriori_cov_scaled_;}
371 const blitz::Array<double, 2>&
sa_m1_scaled()
const {
return sa_m1_scaled_;}
372 const blitz::Array<double, 1>&
sigma_ap()
const {
return sigma_ap_;}
373 double gamma()
const {
return gamma_;}
377 const blitz::Array<double, 1>&
se()
const {
return se_;}
378 const blitz::Array<double, 2>&
k()
const {
return k_;}
379 const blitz::Array<double, 2>&
kt_se_m1_k()
const {
return kt_se_m1_k_;}
380 const blitz::Array<double, 1>&
dx()
const {
return dx_;}
383 blitz::Array<double, 1> x_i_;
384 blitz::Array<double, 1> x_a_;
385 blitz::Array<double, 2> apriori_cov_scaled_;
386 blitz::Array<double, 2>sa_m1_scaled_;
387 blitz::Array<double, 1> sigma_ap_;
390 double gamma_initial_;
392 blitz::Array<double, 1> se_;
393 blitz::Array<double, 2> k_;
394 blitz::Array<double, 2> kt_se_m1_k_;
395 blitz::Array<double, 1> dx_;
blitz::Array< double, 1 > zero_unused_parm() const
Array that is 0 where we are not using a parameter, and 1 elsewhere.
boost::shared_ptr< ConvergenceCheck > convergence_check() const
The convergence check object.
void save_test_data(const std::string &Fname)
Set save_test_data argument, see explanation before class for this.
virtual ~ConnorSolverState()
blitz::Array< double, 2 > apriori_cov_scaled
This is the apriori covariance matrix scaled by sigma_ap.
const blitz::Array< double, 1 > & x_i() const
const blitz::Array< double, 2 > & kt_se_m1_k() const
blitz::Array< double, 2 > sa_m1_scaled
This is the inverse of apriori_cov_scaled, but only for the rows and columns of the jacobian that are...
This class holds various parameters describing how good of a fit we have.
void print(std::ostream &Os) const
blitz::Array< double, 1 > se
This is the covariance matrix of the residual, called in the ATB.
blitz::Array< double, 1 > x_a
This is the apriori X value, called in the ATB.
std::istream & operator>>(std::istream &Is, ConnorSolver &Solve)
virtual bool solve(const blitz::Array< double, 1 > &Initial_guess, const blitz::Array< double, 1 > &Apriori, const blitz::Array< double, 2 > &Apriori_cov)
This solves the least squares problem starting at the initial guess.
boost::shared_ptr< ConnorSolverState > state() const
Save state to a ConnorSolverState object.
const blitz::Array< double, 1 > & sigma_ap() const
virtual blitz::Array< double, 1 > residual() const
Return residual for solution to last problem solved.
const FitStatistic & fstat() const
blitz::Array< double, 1 > x_update() const
const blitz::Array< double, 2 > & k() const
double gamma_initial
Initial value of gamma.
Class that saves the state of a ConnorSolver.
void add_observer_do(Observer< ConnorSolver > &Obs, ConnorSolver &t)
Add an observer.
boost::shared_ptr< CostFunction > cost_function() const
Cost function.
const blitz::Array< double, 1 > & residual() const
blitz::Array< double, 1 > dx
This is the update to , .
boost::shared_ptr< CostFunction > cost_function_
The cost function.
void test_do_inversion(const std::string &Fname, blitz::Array< double, 1 > &Dx, blitz::Array< double, 2 > &Kt_se_m1_k)
Restore state previously saved, and run do_inversion.
blitz::Array< double, 1 > residual_
This is the residual from the model, .
blitz::Array< double, 1 > x_solution_zero_unused() const
Return the solution to the last problem solved.
int number_iteration() const
Number of iterations for the last problem solved.
virtual void remove_observer(Observer< ConnorSolver > &Obs)
Remove an observer.
void remove_observer_do(Observer< ConnorSolver > &Obs, ConnorSolver &t)
Remove an observer.
blitz::Array< double, 1 > sigma_ap
This is the sqrt of S_a diagonal, or the sigma of the apriori.
virtual FitStatistic fit_statistic() const
Return fit results for solution to last problem solved.
This is a Mixin for classes that can be printed.
ConnorSolver(const boost::shared_ptr< CostFunction > &Cf, const boost::shared_ptr< ConvergenceCheck > &Conv, double Gamma_initial=0.0, const std::string &Save_test_data="")
Constructor.
int number_divergent
Number of divergent steps.
blitz::Array< double, 1 > x_i
This is the current value of the state vector X value, called in the ATB.
virtual blitz::Array< double, 2 > aposteriori_covariance() const
Return a posteriori covariance matrix for last problem solved.
const blitz::Array< double, 2 > & apriori_cov_scaled() const
const blitz::Array< double, 1 > & dx() const
ConnorSolverState(const blitz::Array< double, 1 > &X_i, const blitz::Array< double, 1 > &X_a, const blitz::Array< double, 2 > &Apriori_cov_scaled, const blitz::Array< double, 2 > &Sa_m1_scaled, const blitz::Array< double, 1 > &Sigma_ap, double Gamma, double Gamma_last_step, double Gamma_intial, const blitz::Array< double, 1 > &Residual, const blitz::Array< double, 1 > &Se, const blitz::Array< double, 2 > &K, const blitz::Array< double, 2 > &Kt_se_m1_k, const blitz::Array< double, 1 > &Dx, const FitStatistic &Fstat)
blitz::Array< double, 2 > apriori_covariance() const
Apriori covariance matrix.
double gamma_last_step() const
Mixin for a class that allows other classes to observe it state.
int x_solution_size() const
void print(std::ostream &Os) const
const Unit K("K", 1.0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)
double gamma
Levenberg-Marquardt parameter.
void to_stream(std::ostream &os) const
Save state of object.
blitz::Array< double, 2 > kt_se_m1_k
This is .
blitz::Array< double, 1 > x_solution_uncertainty() const
Return the uncertainty of x_solution, this is just the sqrt of the diagonal of the full aposteriori_c...
OUTCOME outcome
Flag indicating success of fit, or why fit wasn't succesful.
double gamma_last_step() const
Levenberg-Marquardt parameter for last step we processed.
virtual blitz::Array< double, 2 > aposteriori_covariance_scaled() const
Return a scaled a posteriori covariance matrix for last problem solved.
virtual void add_observer(Observer< ConnorSolver > &Obs)
Add an observer.
double gamma_last_step_
Stash gamma from last step we processed.
double gamma_initial() const
const blitz::Array< double, 1 > & x_a() const
virtual blitz::Array< double, 2 > apriori_covariance_inv_norm() const
Return normalized apriori covariance inverse matrix.
void from_stream(std::istream &is)
Restore state of object previous saved with "to_stream".
Contains classes to abstract away details in various Spurr Radiative Transfer software.
static double rcond
Factor to determine if we treat a singular factor as 0.
virtual blitz::Array< double, 2 > averaging_kernel() const
Return averaging kernel for last problem solved.
int number_iteration
Number of iterations.
virtual blitz::Array< double, 1 > residual_covariance_diagonal() const
Return diagonal of covariance matrix of residual for solution to last problem solved.
const blitz::Array< double, 2 > & sa_m1_scaled() const
blitz::Array< double, 1 > x_apriori() const
Return the a priori of the last problem solved.
blitz::Array< double, 2 > k
This is the Jacobian, called in the ATB.
void do_inversion()
This does an inversion step.
const blitz::Array< double, 1 > & se() const
int number_divergent() const
Number of divergent steps for the last problem solved.
FitStatistic fstat
Results from last fit step.
boost::shared_ptr< ConvergenceCheck > convergence_check_
The convergence check object.
virtual blitz::Array< double, 2 > jacobian() const
Return the last jacobian calculated.
virtual blitz::Array< double, 1 > x_solution() const
blitz::Array< double, 1 > x_apriori_uncertainty() const
Return the uncertainty of the apriori of the last problem solved.
std::string save_test_data_
If this isn't an empty string, save to this file in the first iteration.
int outcome_flag() const
Outcome flag. This is an integer version of FitStatistic::OUTCOME.