Go to the documentation of this file.
23 #ifndef O2SCL_FIT_BASE_H
24 #define O2SCL_FIT_BASE_H
32 #include <o2scl/jacobian.h>
33 #include <o2scl/mm_funct.h>
35 #ifndef DOXYGEN_NO_O2NS
42 typedef std::function<
57 template<
class vec_
string_t=std::vector<std::
string> >
64 for (
int i=0;i<np;i++) {
80 template<
class vec_t=boost::numeric::ublas::vector<
double> >
83 for(
size_t i=0;i<np;i++) {
95 #ifndef DOXYGEN_INTERNAL
103 std::map<std::string,double>
vars;
118 std::string var,
int nauxp=0, std::string auxp=
"");
135 template<
class vec_t=boost::numeric::ublas::vector<
double>,
136 class mat_t=boost::numeric::ublas::matrix<
double> >
148 virtual void operator()(
size_t np,
const vec_t &p,
size_t nd,
154 virtual void jac(
size_t np, vec_t &p,
size_t nd, vec_t &f,
160 #ifndef DOXYGEN_INTERNAL
199 template<
class vec_t=boost::numeric::ublas::vector<
double>,
200 class mat_t=boost::numeric::ublas::matrix<
double>,
210 const vec_t &yerr, fit_func_t &fun) {
217 mfm=std::bind(std::mem_fn<
int(
size_t,
const vec_t &,vec_t &)>
219 std::placeholders::_1,std::placeholders::_2,
220 std::placeholders::_3);
229 void set_data(
size_t ndat,
const vec_t &xdat,
const vec_t &ydat,
247 virtual double chi2(
size_t np,
const vec_t &p) {
249 for(
size_t i=0;i<ndat_;i++) {
250 double yi=((*fun_)(np,p,(*xdat_)[i])-(*ydat_)[i])/((*yerr_)[i]);
259 virtual void operator()(
size_t np,
const vec_t &p,
size_t nd, vec_t &f) {
261 for(
size_t i=0;i<nd;i++) {
262 double yi=(*fun_)(np,p,(*xdat_)[i]);
263 f[i]=(yi-(*ydat_)[i])/((*yerr_)[i]);
271 virtual void jac(
size_t np, vec_t &p,
size_t nd, vec_t &f,
285 jacobian_gsl<std::function<int(
size_t,
const vec_t &,vec_t &)>,
288 #ifndef DOXYGEN_INTERNAL
299 std::function<int(
size_t,
const vec_t &,vec_t &)>
mfm;
360 virtual int print_iter(
size_t nv, vec_t &x,
double y,
int iter,
361 double value=0.0,
double limit=0.0) {
367 std::cout <<
"Iteration: " << iter << std::endl;
369 for(i=0;i<nv;i++) std::cout << x[i] <<
" ";
370 std::cout << std::endl;
371 std::cout <<
"y: " << y <<
" Val: " << value <<
" Lim: " << limit
374 std::cout <<
"Press a key and type enter to continue. ";
388 virtual int fit(
size_t npar, vec_t &parms, mat_t &covar,
389 double &chi2, func_t &fitfun)=0;
396 virtual const char *
type() {
return "fit_base"; }
407 #ifndef DOXYGEN_NO_O2NS
Standard fitting function based on one-dimensional data with a numerical Jacobian.
jacobian_gsl< std::function< int(size_t, const vec_t &, vec_t &)>, vec_t, mat_t > auto_jac
Automatic Jacobian object.
double tol_rel
(default 1.0e-4)
calculator calc
The function parser.
virtual void jac(size_t np, vec_t &p, size_t nd, vec_t &f, mat_t &J)
Using parameters in p, compute the Jacobian in J.
virtual void operator()(size_t np, const vec_t &p, size_t nd, vec_t &f)=0
Using parameters in p, compute the relative deviations in f.
int set_function(std::string expr, std::string parms, std::string var, int nauxp=0, std::string auxp="")
Specify the strings which define the fitting function.
virtual const char * type()
Return string denoting type ("fit_base")
std::string st_var
The variable.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
std::string st_form
The expression.
size_t n_dat
The number of data points.
double tol_abs
Absolute tolerance (default 1.0e-4)
virtual double chi2(size_t np, const vec_t &p)
Return .
void compile(const char *expr, std::map< std::string, double > *vars=0, bool debug=false, std::map< std::string, int > opPrec=opPrecedence)
Compile expression expr using variables specified in vars and return an integer to indicate success o...
virtual int fit(size_t npar, vec_t &parms, mat_t &covar, double &chi2, func_t &fitfun)=0
Fit function fitfun using parameters in parms as initial guesses.
virtual int print_iter(size_t nv, vec_t &x, double y, int iter, double value=0.0, double limit=0.0)
Print out iteration information.
std::vector< std::string > st_parms
The parameters.
int set_aux_parm(std::string name, double val)
Set the values of the auxilliary parameters that were specified in auxp in the constructor.
Generalized fitting function [abstract base].
double operator()(size_t np, const vec_t &p, double x)
Using parameters in p, predict y given x.
Evaluate a mathematical expression in a string.
virtual size_t get_ndata()
Return the number of data points.
chi_fit_funct(size_t ndat, const vec_t &xdat, const vec_t &ydat, const vec_t &yerr, fit_func_t &fun)
Create an object with specified data and specified fitting function.
std::function< double(size_t, const boost::numeric::ublas::vector< double > &, double)> fit_funct
Array of multi-dimensional functions typedef (C++11 version) in src/fit/fit_base.h.
std::map< std::string, double > vars
Desc.
size_t n_par
The number of parameters.
Simple automatic Jacobian.
Non-linear least-squares fitting [abstract base].
size_t ntrial
Maximum number of iterations (default 500)
fit_func_t * fun_
Fitting function.
int jac_mm_funct(size_t np, const vec_t &p, vec_t &f)
Reformulate operator() into a mm_funct object.
fit_funct_strings(std::string expr, vec_string_t &parms, std::string var)
Specify a fitting function through a string.
virtual void operator()(size_t np, const vec_t &p, size_t nd, vec_t &f)
Using parameters in p, compute the relative deviations in f.
void set_func(fit_func_t &fun)
Set the fitting function.
double eval(std::map< std::string, double > *vars=0)
Evalate the previously compiled expression using variables specified in vars.
int verbose
An integer describing the verbosity of the output.
virtual size_t get_ndata()=0
Return the number of data points.
void set_data(size_t ndat, const vec_t &xdat, const vec_t &ydat, const vec_t &yerr)
Set the data to be fit.
virtual void jac(size_t np, vec_t &p, size_t nd, vec_t &f, mat_t &J)=0
Using parameters in p, compute the Jacobian in J.
std::function< int(size_t, const vec_t &, vec_t &)> mfm
Function object for Jacobian object.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).