1 #include <gsl/gsl_blas.h> 13 int max_cost_function_calls,
14 double dx_tol_abs,
double dx_tol_rel,
double g_tol,
33 void print_state(
unsigned int iter, gsl_multifit_fdfsolver *
s,
int status)
35 double c = gsl_blas_dnrm2( gsl_multifit_fdfsolver_residual(s) );
36 printf(
"Solver '%s'; iter = %3u; (|f(x)|^2)/2 = %g; status = %s\n",
37 gsl_multifit_fdfsolver_name(s), iter, c*c/2.0, gsl_strerror(status) );
39 printf(
"Where x is\n" );
40 (void) gsl_vector_fprintf(stdout, gsl_multifit_fdfsolver_position(s),
"%25.14lf");
45 printf(
"The gradient g(x) is\n");
46 (void) gsl_vector_fprintf(stdout, s->g,
"%25.14lf");
58 const gsl_multifit_fdfsolver_type * T = get_gsl_multifit_fdfsolver();
61 int gsl_status = GSL_FAILURE;
62 int gsl_status_conv = GSL_CONTINUE;
64 gsl_multifit_fdfsolver *
s = gsl_multifit_fdfsolver_alloc (T, f.n, f.p);
66 blitz::Array<double, 1> X(P->parameters());
71 if( !(gsl_status = gsl_multifit_fdfsolver_set(s, &f,
GslVector(X).gsl())) ) {
80 record_cost_at_accepted_point(P->cost());
81 record_accepted_point(P->parameters());
82 record_gradient_at_accepted_point(P->gradient());
91 gsl_status = gsl_multifit_fdfsolver_iterate(s);
92 if( (gsl_status != GSL_SUCCESS) && (gsl_status != GSL_ENOPROG) ) {
102 gsl_status_conv = gsl_multifit_fdfsolver_test(s, 1.0e-4, 1.0e-4, 1.0e-4, &info);
104 gsl_status_conv = gsl_multifit_test_delta(s->dx, s->x, Dx_tol_abs, Dx_tol_rel);
105 if( gsl_status_conv == GSL_CONTINUE )
106 gsl_status_conv = gsl_multifit_test_gradient(s->g, G_tol);
108 if( gsl_status_conv == GSL_SUCCESS ) {
113 if(gsl_status == GSL_ENOPROG) {
120 }
while (gsl_status_conv == GSL_CONTINUE && P->num_cost_evaluations() < max_cost_f_calls);
125 record_cost_at_accepted_point(P->cost());
126 record_accepted_point(P->parameters());
127 record_gradient_at_accepted_point(P->gradient());
129 if(
verbose && (stat != CONTINUE) )
130 print_state( num_step, s, ((stat == ERROR)?gsl_status:gsl_status_conv) );
132 if( s ) gsl_multifit_fdfsolver_free(s);
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
void print_state(unsigned int iter, gsl_multifit_fdfsolver *s, int status)
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Apply value function to a blitz array.
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.
gsl_multifit_function_fdf gsl_get_lsp_fdf(const FullPhysics::NLLSProblem *lsp_standard)
This provides thin wrapper around the GNU Scientific Library gsl_vector.
virtual void solve()
The method that solves the optimization problem.
boost::shared_ptr< IterativeSolver > nlls_solver_gsl_create(const boost::shared_ptr< CostFunc > &NLLS, int max_cost_function_calls, double dx_tol_abs, double dx_tol_rel, double g_tol, bool vrbs)