ReFRACtor
chisq_convergence.cc
Go to the documentation of this file.
1 #include "chisq_convergence.h"
2 #include "fp_exception.h"
3 
4 using namespace FullPhysics;
5 
6 //-----------------------------------------------------------------------
8 //-----------------------------------------------------------------------
9 
10 ChisqConvergence::ChisqConvergence(double stopping_criteria,
11  double dropf, double boostf,
12  double min_chisq,
13  int max_iteration)
14 : stopping_criteria_(stopping_criteria), dropf_(dropf), boostf_(boostf),
15  min_chisq_(min_chisq), max_iteration_(max_iteration)
16 {
17  range_min_check(stopping_criteria, 0.0);
18  range_min_check(boostf, 1.0);
19  range_check(dropf, 0.0, 1.0);
20  range_min_check(max_iteration, 1);
21 }
22 
23 //-----------------------------------------------------------------------
24 // See ConvergenceCheck for description of this function.
25 //-----------------------------------------------------------------------
26 
28  FitStatistic& fit_stat,
29  bool& has_converged,
30  bool& convergence_failed,
31  double& gamma,
32  bool& step_diverged)
33 {
34  using namespace blitz;
35  has_converged = false;
36  convergence_failed = false;
37  step_diverged = false;
38  if(fit_stat.number_iteration <= 1)
39  return;
40  double chisqlast = fit_stat_last.chisq_measured;
41  double chisq = fit_stat.chisq_measured;
42  if(fit_stat.number_iteration >= max_iteration_) {
43  convergence_failed = true;
45  } else if(chisq >= chisqlast) {
46  step_diverged = true;
47  gamma = (1 + gamma) * boostf_ - 1;
48  } else if(chisq <= min_chisq_ ||
49  fabs((chisqlast - chisq) / chisq) <= stopping_criteria_) {
50  has_converged = true;
51  } else
52  gamma = (1 + gamma) * dropf_ - 1;
53 }
54 
55 //-----------------------------------------------------------------------
56 // See ConvergenceCheck for description of this function.
57 //-----------------------------------------------------------------------
58 
60  const blitz::Array<double, 1>& Residual,
61  const blitz::Array<double, 1>& Residual_cov_diag)
62 {
63  if (not fit_stat.fit_succeeded)
64  throw Exception("Can not evaulate quality when the fit has not succeeded");
65 
66  // Simple implementation that is not essential for the solver to be correct
67  // since this information would be evaluated by an external user
68  if(fit_stat.chisq_measured < 1.0) {
70  } else {
72  }
73 }
74 
75 //-----------------------------------------------------------------------
77 //-----------------------------------------------------------------------
78 
79 void ChisqConvergence::print(std::ostream& Os) const
80 {
81  Os << "ChisqConvergence:\n"
82  << " Stopping criteria: " << stopping_criteria_ << "\n"
83  << " Drop factor: " << dropf_ << "\n"
84  << " Boost factor: " << boostf_ << "\n"
85  << " Min Chisq: " << min_chisq_ << "\n"
86  << " Max iteration: " << max_iteration_ << "\n";
87 }
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
virtual void convergence_check(const FitStatistic &fit_stat_last, FitStatistic &fit_stat, bool &has_converged, bool &convergence_failed, double &gamma, bool &step_diverged)
Check for the convergence of a Solver, or if we have taken a divergent step.
This class holds various parameters describing how good of a fit we have.
virtual void evaluate_quality(FitStatistic &fit_stat, const blitz::Array< double, 1 > &Residual, const blitz::Array< double, 1 > &Residual_cov_diag)
Evaluates the quality of a converged fit from the residuals and expected residual error...
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
Apply value function to a blitz array.
bool fit_succeeded
Was the fit successful?
OUTCOME outcome
Flag indicating success of fit, or why fit wasn&#39;t succesful.
ChisqConvergence(double stopping_criteria=0.001, double dropf=0.1, double boostf=10, double min_chisq=0.01, int max_iteration=50)
Constructor.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
double chisq_measured
Chisq of the residuals of the measurement vs. model prediction.
#define range_min_check(V, Min)
Range check.
Definition: fp_exception.h:167
int number_iteration
Number of iterations.
virtual void print(std::ostream &Os) const
Print object to stream.

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