Commit 0092ae2c authored by Laurent Belcour's avatar Laurent Belcour

Updating the fitter interface

parent de1d814b
...@@ -20,12 +20,11 @@ class fitter ...@@ -20,12 +20,11 @@ class fitter
//! \brief static function to fit a data set d with the underling //! \brief static function to fit a data set d with the underling
//! function class. Return the best fit (along with fitting //! function class. Return the best fit (along with fitting
//! information ?) //! information ?)
virtual bool fit_data(const ptr<data> d, function* f, const arguments& args) = 0 ; virtual bool fit_data(const ptr<data>& d, ptr<function>& f, const arguments& args) = 0 ;
//! \brief parse the command line arguments to setup some general //! \brief parse the command line arguments to setup some general
//! options before any fit. Those options should be resilient to //! options before any fit. Those options should be resilient to
//! multiple call to the fit_data procedure //! multiple call to the fit_data procedure
virtual void set_parameters(const arguments& args) = 0 ; virtual void set_parameters(const arguments& args) = 0 ;
} ; } ;
...@@ -38,7 +38,7 @@ template<typename T> T open_library(const std::string& filename, const char* fun ...@@ -38,7 +38,7 @@ template<typename T> T open_library(const std::string& filename, const char* fun
} }
#else #else
void* handle = dlopen(filename.c_str(), RTLD_GLOBAL | RTLD_LAZY); void* handle = dlopen(filename.c_str(), RTLD_GLOBAL | RTLD_LAZY);
if(handle != NULL) if(handle != NULL)
{ {
void (*res)(); void (*res)();
...@@ -79,7 +79,7 @@ function* plugins_manager::get_function(const std::string& filename) ...@@ -79,7 +79,7 @@ function* plugins_manager::get_function(const std::string& filename)
// Parameters of the function object // Parameters of the function object
int nX, nY; int nX, nY;
params::input param_in = params::UNKNOWN_INPUT; params::input param_in = params::UNKNOWN_INPUT;
params::output param_out = params::UNKNOWN_OUTPUT; params::output param_out = params::UNKNOWN_OUTPUT;
arguments args; arguments args;
...@@ -170,7 +170,7 @@ function* plugins_manager::get_function(const arguments& args) ...@@ -170,7 +170,7 @@ function* plugins_manager::get_function(const arguments& args)
//! create a <em>compound</em> class to store multiple //! create a <em>compound</em> class to store multiple
//! functions in it. //! functions in it.
compound_function* compound = new compound_function(); compound_function* compound = new compound_function();
//! For each args_vec element, create a function object and add //! For each args_vec element, create a function object and add
//! it to the compound one. //! it to the compound one.
for(unsigned int i=0; i<args_vec.size(); ++i) for(unsigned int i=0; i<args_vec.size(); ++i)
...@@ -268,14 +268,14 @@ function* plugins_manager::get_function(const arguments& args) ...@@ -268,14 +268,14 @@ function* plugins_manager::get_function(const arguments& args)
func = new product_function(cosine, dynamic_cast<nonlinear_function*>(func)); func = new product_function(cosine, dynamic_cast<nonlinear_function*>(func));
} }
// End of correction // End of correction
*/ */
return func; return func;
} }
ptr<data> plugins_manager::get_data(const std::string& n) ptr<data> plugins_manager::get_data(const std::string& n)
{ {
if(n.empty()) if(n.empty())
{ {
#ifdef DEBUG #ifndef DEBUG
std::cout << "<<DEBUG>> no data plugin specified, returning a vertial_segment loader" << std::endl; std::cout << "<<DEBUG>> no data plugin specified, returning a vertial_segment loader" << std::endl;
#endif #endif
return new vertical_segment(); return new vertical_segment();
...@@ -320,7 +320,7 @@ ptr<fitter> plugins_manager::get_fitter(const std::string& n) ...@@ -320,7 +320,7 @@ ptr<fitter> plugins_manager::get_fitter(const std::string& n)
} }
} }
void plugins_manager::check_compatibility(ptr<data>& d, function*& f, void plugins_manager::check_compatibility(ptr<data>& d, const ptr<function>& f,
const arguments& args) const arguments& args)
{ {
if(d->input_parametrization() == params::UNKNOWN_INPUT && if(d->input_parametrization() == params::UNKNOWN_INPUT &&
...@@ -344,8 +344,8 @@ void plugins_manager::check_compatibility(ptr<data>& d, function*& f, ...@@ -344,8 +344,8 @@ void plugins_manager::check_compatibility(ptr<data>& d, function*& f,
{ {
std::cout << "<<INFO>> has to change the parametrization of the input data " << params::get_name(d->input_parametrization()) << std::endl; std::cout << "<<INFO>> has to change the parametrization of the input data " << params::get_name(d->input_parametrization()) << std::endl;
std::cout << "<<INFO>> to " << params::get_name(f->input_parametrization()) << std::endl; std::cout << "<<INFO>> to " << params::get_name(f->input_parametrization()) << std::endl;
data_params* dd = new data_params(d, f->input_parametrization()); ptr<data_params> dd = new data_params(d, f->input_parametrization());
d = dd ; d = dynamic_pointer_cast<data>(dd) ;
} }
else else
{ {
...@@ -367,7 +367,7 @@ void plugins_manager::check_compatibility(ptr<data>& d, function*& f, ...@@ -367,7 +367,7 @@ void plugins_manager::check_compatibility(ptr<data>& d, function*& f,
} }
*/ */
} }
// \todo implement the Darwin (MACOS) version. // \todo implement the Darwin (MACOS) version.
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
......
...@@ -26,11 +26,11 @@ class plugins_manager ...@@ -26,11 +26,11 @@ class plugins_manager
//! \brief load a function from the ALTA input file. //! \brief load a function from the ALTA input file.
static function* get_function(const std::string& filename); static function* get_function(const std::string& filename);
//! \brief get an instance of the data that is defined in the plugin with //! \brief get an instance of the data that is defined in the plugin with
//! filename n. Return null if no one exist. //! filename n. Return null if no one exist.
static ptr<data> get_data(const std::string& n) ; static ptr<data> get_data(const std::string& n) ;
//! \brief get an instance of the fitter that is defined in the plugin with //! \brief get an instance of the fitter that is defined in the plugin with
//! filename n. Return null if no one exist. //! filename n. Return null if no one exist.
static ptr<fitter> get_fitter(const std::string& n) ; static ptr<fitter> get_fitter(const std::string& n) ;
...@@ -40,7 +40,7 @@ class plugins_manager ...@@ -40,7 +40,7 @@ class plugins_manager
//! this has to be done before fitting to ensure that the //! this has to be done before fitting to ensure that the
//! parametrizations spaces are the same. //! parametrizations spaces are the same.
//! \todo specify an output parametrization for the function ? //! \todo specify an output parametrization for the function ?
static void check_compatibility(ptr<data>& d, function*& f, static void check_compatibility(ptr<data>& d, const ptr<function>& f,
const arguments& args) ; const arguments& args) ;
......
...@@ -20,7 +20,7 @@ ALTA_DLL_EXPORT fitter* provide_fitter() ...@@ -20,7 +20,7 @@ ALTA_DLL_EXPORT fitter* provide_fitter()
class CeresFunctor : public ceres::CostFunction class CeresFunctor : public ceres::CostFunction
{ {
public: public:
CeresFunctor(nonlinear_function* f, const vec& xi, const arguments& args) : _f(f), _xi(xi) CeresFunctor(const ptr<nonlinear_function>& f, const vec& xi, const arguments& args) : _f(f), _xi(xi)
{ {
set_num_residuals(f->dimY()); set_num_residuals(f->dimY());
mutable_parameter_block_sizes()->push_back(f->nbParameters()); mutable_parameter_block_sizes()->push_back(f->nbParameters());
...@@ -28,7 +28,7 @@ class CeresFunctor : public ceres::CostFunction ...@@ -28,7 +28,7 @@ class CeresFunctor : public ceres::CostFunction
_log_fit = args.is_defined("log-fit"); _log_fit = args.is_defined("log-fit");
} }
virtual bool Evaluate(double const* const* x, double* y, double** dy) const virtual bool Evaluate(double const* const* x, double* y, double** dy) const
{ {
// Check that the parameters used are within the bounds defined // Check that the parameters used are within the bounds defined
// by the function // by the function
...@@ -91,21 +91,21 @@ class CeresFunctor : public ceres::CostFunction ...@@ -91,21 +91,21 @@ class CeresFunctor : public ceres::CostFunction
protected: protected:
// Data point and function to optimize // Data point and function to optimize
nonlinear_function* _f; const ptr<nonlinear_function>& _f;
const vec _xi; const vec _xi;
// Arguments of the fitting procedure // Arguments of the fitting procedure
bool _log_fit; bool _log_fit;
}; };
nonlinear_fitter_ceres::nonlinear_fitter_ceres() nonlinear_fitter_ceres::nonlinear_fitter_ceres()
{ {
} }
nonlinear_fitter_ceres::~nonlinear_fitter_ceres() nonlinear_fitter_ceres::~nonlinear_fitter_ceres()
{ {
} }
bool nonlinear_fitter_ceres::fit_data(const ptr<data> d, function* fit, const arguments &args) bool nonlinear_fitter_ceres::fit_data(const ptr<data>& d, const ptr<function>& fit, const arguments &args)
{ {
// I need to set the dimension of the resulting function to be equal // I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem // to the dimension of my fitting problem
...@@ -115,12 +115,13 @@ bool nonlinear_fitter_ceres::fit_data(const ptr<data> d, function* fit, const ar ...@@ -115,12 +115,13 @@ bool nonlinear_fitter_ceres::fit_data(const ptr<data> d, function* fit, const ar
fit->setMax(d->max()) ; fit->setMax(d->max()) ;
// Convert the function and bootstrap it with the data // Convert the function and bootstrap it with the data
if(dynamic_cast<nonlinear_function*>(fit) == NULL) ptr<nonlinear_function> nf = dynamic_pointer_cast<nonlinear_function>(fit);
if(!nf)
{ {
std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl; std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl;
return false; return false;
} }
nonlinear_function* nf = dynamic_cast<nonlinear_function*>(fit);
#ifndef DEBUG #ifndef DEBUG
std::cout << "<<DEBUG>> number of parameters: " << nf->nbParameters() << std::endl; std::cout << "<<DEBUG>> number of parameters: " << nf->nbParameters() << std::endl;
......
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
* *
* \details * \details
* <h3>Third party requirements</h3> * <h3>Third party requirements</h3>
* *
* You will need three external libraries to compile this plugin: * You will need three external libraries to compile this plugin:
* <ul> * <ul>
* <li><a href="https://ceres-solver.googlesource.com/ceres-solver">CERES</a> * <li><a href="https://ceres-solver.googlesource.com/ceres-solver">CERES</a>
* library, version 1.5.0</li> * library, version 1.5.0</li>
* <li><a href="http://code.google.com/p/google-glog">Google glog</a> library * <li><a href="http://code.google.com/p/google-glog">Google glog</a> library
* version 0.3.1</li> * version 0.3.1</li>
* <li><a href="http://eigen.tuxfamily.org/">Eigen library</a> version 3</li> * <li><a href="http://eigen.tuxfamily.org/">Eigen library</a> version 3</li>
* </ul> * </ul>
...@@ -61,7 +61,7 @@ class nonlinear_fitter_ceres: public fitter ...@@ -61,7 +61,7 @@ class nonlinear_fitter_ceres: public fitter
// Fitting a data object // Fitting a data object
// //
virtual bool fit_data(const ptr<data> d, function* fit, const arguments& args) ; virtual bool fit_data(const ptr<data>& d, const ptr<function>& fit, const arguments& args) ;
// Provide user parameters to the fitter // Provide user parameters to the fitter
// //
...@@ -72,4 +72,3 @@ class nonlinear_fitter_ceres: public fitter ...@@ -72,4 +72,3 @@ class nonlinear_fitter_ceres: public fitter
// Fitter options // Fitter options
ceres::Solver::Options options; ceres::Solver::Options options;
} ; } ;
...@@ -20,7 +20,7 @@ ALTA_DLL_EXPORT fitter* provide_fitter() ...@@ -20,7 +20,7 @@ ALTA_DLL_EXPORT fitter* provide_fitter()
struct EigenFunctor: Eigen::DenseFunctor<double> struct EigenFunctor: Eigen::DenseFunctor<double>
{ {
EigenFunctor(nonlinear_function* f, const ptr<data> d, bool use_cosine) : EigenFunctor(const ptr<nonlinear_function>& f, const ptr<data> d, bool use_cosine) :
Eigen::DenseFunctor<double>(f->nbParameters(), d->dimY()*d->size()), _f(f), _d(d), _cosine(use_cosine) Eigen::DenseFunctor<double>(f->nbParameters(), d->dimY()*d->size()), _f(f), _d(d), _cosine(use_cosine)
{ {
#ifndef DEBUG #ifndef DEBUG
...@@ -73,7 +73,7 @@ struct EigenFunctor: Eigen::DenseFunctor<double> ...@@ -73,7 +73,7 @@ struct EigenFunctor: Eigen::DenseFunctor<double>
_di[i] = _x[_f->dimX() + i]; _di[i] = _x[_f->dimX() + i];
// Should add the resulting vector completely // Should add the resulting vector completely
vec _y = _di - cos*(*_f)(x); vec _y = _di - cos*_f->value(x);
for(int i=0; i<_f->dimY(); ++i) for(int i=0; i<_f->dimY(); ++i)
y(i*_d->size() + s) = _y[i]; y(i*_d->size() + s) = _y[i];
...@@ -129,7 +129,7 @@ struct EigenFunctor: Eigen::DenseFunctor<double> ...@@ -129,7 +129,7 @@ struct EigenFunctor: Eigen::DenseFunctor<double>
} }
nonlinear_function* _f; const ptr<nonlinear_function>& _f;
const ptr<data> _d; const ptr<data> _d;
// Flags // Flags
...@@ -139,7 +139,7 @@ struct EigenFunctor: Eigen::DenseFunctor<double> ...@@ -139,7 +139,7 @@ struct EigenFunctor: Eigen::DenseFunctor<double>
struct CompoundFunctor: Eigen::DenseFunctor<double> struct CompoundFunctor: Eigen::DenseFunctor<double>
{ {
CompoundFunctor(compound_function* f, int index, const ptr<data> d, bool use_cosine) : CompoundFunctor(compound_function* f, int index, const ptr<data> d, bool use_cosine) :
Eigen::DenseFunctor<double>((*f)[index]->nbParameters(), d->dimY()*d->size()), _f(f), _index(index), _d(d), _cosine(use_cosine) Eigen::DenseFunctor<double>((*f)[index]->nbParameters(), d->dimY()*d->size()), _f(f), _d(d), _index(index), _cosine(use_cosine)
{ {
#ifndef DEBUG #ifndef DEBUG
std::cout << "<<DEBUG>> constructing an EigenFunctor for n=" << inputs() << " parameters and m=" << values() << " points" << std::endl ; std::cout << "<<DEBUG>> constructing an EigenFunctor for n=" << inputs() << " parameters and m=" << values() << " points" << std::endl ;
...@@ -275,7 +275,7 @@ nonlinear_fitter_eigen::~nonlinear_fitter_eigen() ...@@ -275,7 +275,7 @@ nonlinear_fitter_eigen::~nonlinear_fitter_eigen()
{ {
} }
bool nonlinear_fitter_eigen::fit_data(const ptr<data> d, function* fit, const arguments &args) bool nonlinear_fitter_eigen::fit_data(const ptr<data>& d, const ptr<function>& fit, const arguments &args)
{ {
// I need to set the dimension of the resulting function to be equal // I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem // to the dimension of my fitting problem
...@@ -285,12 +285,12 @@ bool nonlinear_fitter_eigen::fit_data(const ptr<data> d, function* fit, const ar ...@@ -285,12 +285,12 @@ bool nonlinear_fitter_eigen::fit_data(const ptr<data> d, function* fit, const ar
fit->setMax(d->max()) ; fit->setMax(d->max()) ;
// Convert the function and bootstrap it with the data // Convert the function and bootstrap it with the data
if(dynamic_cast<nonlinear_function*>(fit) == NULL) if(!dynamic_pointer_cast<nonlinear_function>(fit))
{ {
std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl; std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl;
return false; return false;
} }
nonlinear_function* nf = dynamic_cast<nonlinear_function*>(fit); ptr<nonlinear_function> nf = dynamic_pointer_cast<nonlinear_function>(fit);
nf->bootstrap(d, args); nf->bootstrap(d, args);
#ifndef DEBUG #ifndef DEBUG
...@@ -305,17 +305,16 @@ bool nonlinear_fitter_eigen::fit_data(const ptr<data> d, function* fit, const ar ...@@ -305,17 +305,16 @@ bool nonlinear_fitter_eigen::fit_data(const ptr<data> d, function* fit, const ar
vec nf_x = nf->parameters(); vec nf_x = nf->parameters();
int info; int info;
#ifdef OLD
if(args.is_defined("fit-compound")) if(args.is_defined("fit-compound"))
{ {
if(dynamic_cast<compound_function*>(nf) == NULL) ptr<compound_function> compound = dynamic_pointer_cast<compound_function>(nf);
if(!compound_function)
{ {
std::cerr << "<<ERROR>> you should use --fit-compound with a compound function" << std::endl; std::cerr << "<<ERROR>> you should use --fit-compound with a compound function" << std::endl;
return false; return false;
} }
compound_function* compound = dynamic_cast<compound_function*>(nf);
// Register how many parameter are already fitted // Register how many parameter are already fitted
int already_fit = 0; int already_fit = 0;
...@@ -363,6 +362,7 @@ bool nonlinear_fitter_eigen::fit_data(const ptr<data> d, function* fit, const ar ...@@ -363,6 +362,7 @@ bool nonlinear_fitter_eigen::fit_data(const ptr<data> d, function* fit, const ar
} }
} }
else else
#endif
{ {
Eigen::VectorXd x(nf->nbParameters()); Eigen::VectorXd x(nf->nbParameters());
for(int i=0; i<nf->nbParameters(); ++i) for(int i=0; i<nf->nbParameters(); ++i)
......
...@@ -45,7 +45,7 @@ class nonlinear_fitter_eigen: public fitter ...@@ -45,7 +45,7 @@ class nonlinear_fitter_eigen: public fitter
// Fitting a data object // Fitting a data object
// //
virtual bool fit_data(const ptr<data> d, function* fit, const arguments& args) ; virtual bool fit_data(const ptr<data>& d, const ptr<function>& fit, const arguments& args) ;
// Provide user parameters to the fitter // Provide user parameters to the fitter
// //
......
...@@ -23,7 +23,7 @@ ALTA_DLL_EXPORT fitter* provide_fitter() ...@@ -23,7 +23,7 @@ ALTA_DLL_EXPORT fitter* provide_fitter()
class altaNLP : public Ipopt::TNLP class altaNLP : public Ipopt::TNLP
{ {
public: public:
altaNLP(nonlinear_function* f, const ptr<data> d) : TNLP(), _f(f), _d(d) altaNLP(const ptr<nonlinear_function>& f, const ptr<data>& d) : TNLP(), _f(f), _d(d)
{ {
} }
...@@ -209,8 +209,8 @@ class altaNLP : public Ipopt::TNLP ...@@ -209,8 +209,8 @@ class altaNLP : public Ipopt::TNLP
protected: protected:
const ptr<data> _d; const ptr<data>& _d;
nonlinear_function* _f; const ptr<nonlinear_function>& _f;
}; };
nonlinear_fitter_ipopt::nonlinear_fitter_ipopt() nonlinear_fitter_ipopt::nonlinear_fitter_ipopt()
...@@ -220,7 +220,7 @@ nonlinear_fitter_ipopt::~nonlinear_fitter_ipopt() ...@@ -220,7 +220,7 @@ nonlinear_fitter_ipopt::~nonlinear_fitter_ipopt()
{ {
} }
bool nonlinear_fitter_ipopt::fit_data(const ptr<data> d, function* fit, const arguments &args) bool nonlinear_fitter_ipopt::fit_data(const ptr<data>& d, ptr<function>& fit, const arguments &args)
{ {
// I need to set the dimension of the resulting function to be equal // I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem // to the dimension of my fitting problem
...@@ -230,12 +230,12 @@ bool nonlinear_fitter_ipopt::fit_data(const ptr<data> d, function* fit, const ar ...@@ -230,12 +230,12 @@ bool nonlinear_fitter_ipopt::fit_data(const ptr<data> d, function* fit, const ar
fit->setMax(d->max()) ; fit->setMax(d->max()) ;
// Convert the function and bootstrap it with the data // Convert the function and bootstrap it with the data
if(dynamic_cast<nonlinear_function*>(fit) == NULL) ptr<nonlinear_function> nf = dynamic_pointer_cast<nonlinear_function>(fit);
if(!nf)
{ {
std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl; std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl;
return false; return false;
} }
nonlinear_function* nf = dynamic_cast<nonlinear_function*>(fit);
nf->bootstrap(d, args); nf->bootstrap(d, args);
#ifndef DEBUG #ifndef DEBUG
......
...@@ -54,7 +54,7 @@ class nonlinear_fitter_ipopt: public fitter ...@@ -54,7 +54,7 @@ class nonlinear_fitter_ipopt: public fitter
// Fitting a data object // Fitting a data object
// //
virtual bool fit_data(const ptr<data> d, function* fit, const arguments& args) ; virtual bool fit_data(const ptr<data>& d, ptr<function>& fit, const arguments& args) ;
// Provide user parameters to the fitter // Provide user parameters to the fitter
// //
......
...@@ -34,7 +34,7 @@ void print_nlopt_error(nlopt_result res, const std::string& string) ...@@ -34,7 +34,7 @@ void print_nlopt_error(nlopt_result res, const std::string& string)
// The parameter of the function _f should be set prior to this function // The parameter of the function _f should be set prior to this function
// call. If not it will produce undesirable results. // call. If not it will produce undesirable results.
void df(double* fjac, const nonlinear_function* f, const ptr<data> d) void df(double* fjac, const nonlinear_function* f, const data* d)
{ {
// Clean memory // Clean memory
memset(fjac, 0.0, f->nbParameters()*sizeof(double)); memset(fjac, 0.0, f->nbParameters()*sizeof(double));
...@@ -77,7 +77,7 @@ void df(double* fjac, const nonlinear_function* f, const ptr<data> d) ...@@ -77,7 +77,7 @@ void df(double* fjac, const nonlinear_function* f, const ptr<data> d)
double f(unsigned n, const double* x, double* dy, void* dat) double f(unsigned n, const double* x, double* dy, void* dat)
{ {
nonlinear_function* _f = (nonlinear_function*)(((void**)dat)[0]); nonlinear_function* _f = (nonlinear_function*)(((void**)dat)[0]);
const ptr<data> _d = *(const ptr<data>*)(((void**)dat)[1]); const data* _d = (const data*)(((void**)dat)[1]);
// Update the parameters vector // Update the parameters vector
vec _p(_f->nbParameters()); vec _p(_f->nbParameters());
...@@ -125,7 +125,7 @@ nonlinear_fitter_nlopt::~nonlinear_fitter_nlopt() ...@@ -125,7 +125,7 @@ nonlinear_fitter_nlopt::~nonlinear_fitter_nlopt()
{ {
} }
bool nonlinear_fitter_nlopt::fit_data(const ptr<data> d, function* fit, const arguments &args) bool nonlinear_fitter_nlopt::fit_data(const ptr<data>& d, ptr<function>& fit, const arguments &args)
{ {
// I need to set the dimension of the resulting function to be equal // I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem // to the dimension of my fitting problem
...@@ -135,12 +135,12 @@ bool nonlinear_fitter_nlopt::fit_data(const ptr<data> d, function* fit, const ar ...@@ -135,12 +135,12 @@ bool nonlinear_fitter_nlopt::fit_data(const ptr<data> d, function* fit, const ar
fit->setMax(d->max()) ; fit->setMax(d->max()) ;
// Convert the function and bootstrap it with the data // Convert the function and bootstrap it with the data
if(dynamic_cast<nonlinear_function*>(fit) == NULL) ptr<nonlinear_function> nf = dynamic_pointer_cast<nonlinear_function>(fit);
if(!nf)
{ {
std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl; std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl;
return false; return false;
} }
nonlinear_function* nf = dynamic_cast<nonlinear_function*>(fit);
nf->bootstrap(d, args); nf->bootstrap(d, args);
#ifndef DEBUG #ifndef DEBUG
...@@ -233,8 +233,8 @@ bool nonlinear_fitter_nlopt::fit_data(const ptr<data> d, function* fit, const ar ...@@ -233,8 +233,8 @@ bool nonlinear_fitter_nlopt::fit_data(const ptr<data> d, function* fit, const ar
// Create the problem // Create the problem
void* dat[2]; void* dat[2];
dat[0] = (void*)nf; dat[0] = (void*)nf.get();
dat[1] = (void*)&d; dat[1] = (void*)d.get();
res = nlopt_set_min_objective(opt, f, dat); res = nlopt_set_min_objective(opt, f, dat);
if(res < 0) if(res < 0)
{ {
......
...@@ -46,7 +46,7 @@ class nonlinear_fitter_nlopt: public fitter ...@@ -46,7 +46,7 @@ class nonlinear_fitter_nlopt: public fitter
// Fitting a data object // Fitting a data object
// //
virtual bool fit_data(const ptr<data> d,</