15 int max_cost_function_calls,
60 scaled_p->parameters(scaled_p->scale_parameters(map->parameters()));
62 firstIndex i1; secondIndex i2;
64 gamma = gamma_initial;
70 bool has_converged =
false;
71 convergence_check()->initialize_check();
80 record_cost_at_accepted_point(P->cost());
81 record_accepted_point(P->parameters());
82 record_gradient_at_accepted_point(P->gradient());
84 while(!has_converged) {
85 fstat.number_iteration += 1;
88 bool step_diverged, convergence_failed;
89 gamma_last_step_ = gamma;
90 convergence_check()->convergence_check(fstat_last, fstat,
93 gamma, step_diverged);
94 if(convergence_failed) {
96 fstat.fit_succeeded =
false;
103 scaled_p->parameters(scaled_p->scale_parameters(m_state_last.
parameters()));
104 map->set(m_state_last);
106 fstat.number_iteration -= 1;
107 fstat.number_divergent += 1;
110 m_state_last.
set(*map);
114 scaled_p->parameters(scaled_p->scale_parameters( Array<double, 1>(map->parameters()+dx) ));
118 record_cost_at_accepted_point(P->cost());
119 record_accepted_point(P->parameters());
120 record_gradient_at_accepted_point(P->gradient());
125 convergence_check()->evaluate_quality(fstat, map->model_measure_diff(), map->measurement_error_cov());
168 using namespace blitz;
169 firstIndex i1; secondIndex i2; thirdIndex i3;
174 Array<double,2> jac(scaled_p->jacobian());
175 Array<double,1> res(scaled_p->residual());
176 Array<double,2> lhs(jac.cols(),jac.cols());
177 Array<double,1> rhs(jac.cols());
180 Array<double,2> Sa_chol_inv(map->a_priori_cov_chol_inv());
181 Array<double,2> Sa_inv(sum(Sa_chol_inv(i3,i1) * Sa_chol_inv(i3, i2), i3));
182 Array<double,2> lev_mar_term(map->param_a_priori_uncertainty()(i1)*Sa_inv(i1,i2)*map->param_a_priori_uncertainty()(i2) * gamma);
183 lhs = sum(jac(i3,i1) * jac(i3, i2), i3) + lev_mar_term;
184 rhs = -sum(jac(i2,i1) * res(i2), i2);
190 dx.resize(lhs.cols());
192 dx = scaled_p->unscale_parameters(dxscale);
198 Array<double,1> temp;
200 fstat.d_sigma_sq = sum(dxscale * rhs);
203 int d_sigma_sq_numrow = jac.cols();
204 fstat.d_sigma_sq_scaled = fstat.d_sigma_sq / d_sigma_sq_numrow;
205 temp.reference(map->cov_weighted_parameter_a_priori_diff());
206 fstat.chisq_apriori = sum(temp*temp);
207 temp.reference(map->uncert_weighted_model_measure_diff());
208 fstat.chisq_measured = sum(temp*temp);
215 Array<double, 1> residual_fc = map->model_measure_diff();
216 residual_fc += sum(map->jacobian()(i1, i2) * dx(i2), i2);
217 Array<double, 1> x_i_fc = map->parameters();
220 temp.resize(x_i_fc.rows());
221 temp = sum(map->a_priori_cov_chol_inv()(i1, i2) * Array<double,1>(x_i_fc-map->a_priori_params())(i2), i2);
222 fstat.chisq_apriori_fc = sum(temp*temp);
223 fstat.chisq_measured_fc = sum(residual_fc * residual_fc / map->measurement_error_cov());
virtual void parameters(const blitz::Array< double, 1 > &x)
Sets the problem at a new point in the parameter space.
blitz::Array< double, 1 > solve_least_squares(const blitz::Array< double, 2 > &A, const blitz::Array< double, 1 > &B, double Rcond=1e-12)
This solves the least squares system A*x = b, returning the minimum norm solution.
This class holds various parameters describing how good of a fit we have.
The state for a parametrized mathematical model (a vector function) and its Jacobian.
void do_inversion()
This does an inversion step.
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
void solve()
This solves the least squares problem starting at the initial guess.
Apply value function to a blitz array.
boost::shared_ptr< IterativeSolver > connor_solver_map_create(const boost::shared_ptr< CostFunc > &NLLS_MAP, const boost::shared_ptr< ConvergenceCheck > &Convergence_check, int max_cost_function_calls, double Gamma_initial)
static double rcond
Factor to determine if we treat a singular factor as 0.
bool fit_succeeded
Was the fit successful?
This solves a nonlinear least squares problem using Levenberg-Marquardt.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
#define REGISTER_LUA_END()
def(luabind::constructor< int >()) .def("rows"
The base class for all iterative optimizers.
virtual void set(const ModelState &s)
Makes self a copy of the input state.