diff options
author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2012-02-15 15:35:43 +0000 |
---|---|---|
committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2012-02-15 15:35:43 +0000 |
commit | cd463edb6e95e7b5eab8848e3438a8b07a6681b5 (patch) | |
tree | 70bc81d7448fd0f9995ed4c428938e8ff26343d6 /interface | |
parent | eff60a225541f400f7e52fe2d42ce5a9ec399ccc (diff) | |
download | opt-utilities-cd463edb6e95e7b5eab8848e3438a8b07a6681b5.tar.bz2 |
git-svn-id: file:///home/svn/opt_utilities@220 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'interface')
-rw-r--r-- | interface/opt.cc | 37 | ||||
-rw-r--r-- | interface/opt.h | 2 |
2 files changed, 39 insertions, 0 deletions
diff --git a/interface/opt.cc b/interface/opt.cc index 7161cca..92906a1 100644 --- a/interface/opt.cc +++ b/interface/opt.cc @@ -50,6 +50,23 @@ struct fit_space std::vector<std::string> model_names; +class func_obj_raw + :public func_obj<double,std::vector<double> > +{ +public: + double (*pfunc)(const double*); +private: + double do_eval(const std::vector<double>& x) + { + return (*pfunc)(x.data()); + } + func_obj_raw* do_clone()const + { + return new func_obj_raw(*this); + } +}; + + void regist_model(const dopt::model& m,const char* addr) { @@ -76,6 +93,26 @@ public: extern "C" { + void optimize_powell_(double (*pfunc)(const double*),const int& np,double* params,const double& precision) + { + std::vector<double> p(np); + for(int i=0;i<np;++i) + { + p[i]=params[i]; + } + func_obj_raw fo; + fo.pfunc=pfunc; + optimizer<double,std::vector<double> > opt; + opt.set_func_obj(fo); + opt.set_opt_method(powell_method<double,std::vector<double> >()); + opt.set_start_point(p); + opt.set_precision(precision); + p=opt.optimize(); + for(int i=0;i<np;++i) + { + params[i]=p[i]; + } + } int alloc_fit_(int& n) { diff --git a/interface/opt.h b/interface/opt.h index a74d693..84aad39 100644 --- a/interface/opt.h +++ b/interface/opt.h @@ -2,6 +2,7 @@ #define OPT_H //#define F77 #ifdef F77 +#define optimize_powell_ optimize_powell__ #define alloc_fit_ alloc_fit__ #define free_fit_ free_fit__ #define load_data_ load_data__ @@ -15,6 +16,7 @@ extern "C" { + void optimize_powell_(double (*pfunc)(const double*),const int& np,double* params,const double& precision); int alloc_fit_(int&); int free_fit_(const int& nxc); int load_data_(const int& nfit,const int& ndatas,double* x,double* y,double* yl,double* yu=0,double* xl=0,double* xu=0); |