aboutsummaryrefslogtreecommitdiffstats
path: root/interface
diff options
context:
space:
mode:
Diffstat (limited to 'interface')
-rw-r--r--interface/opt.cc37
-rw-r--r--interface/opt.h2
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);