aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-08-29 10:26:50 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-08-29 10:26:50 +0000
commite1be7dc1247d604ea8c914ee1ec01b0b009cdb98 (patch)
tree5d944579807f2e9dbd5265113120bf73da415467
parent13c74917ecea5c151120678aff05edcc4ea682d5 (diff)
downloadopt-utilities-e1be7dc1247d604ea8c914ee1ec01b0b009cdb98.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@56 ed2142bd-67ad-457f-ba7c-d818d4011675
-rw-r--r--core/fitter.hpp2
-rw-r--r--example/Makefile9
-rw-r--r--example/test_fitter.cpp59
-rw-r--r--methods/aga/aga.hpp1
4 files changed, 68 insertions, 3 deletions
diff --git a/core/fitter.hpp b/core/fitter.hpp
index 119c930..874e4d0 100644
--- a/core/fitter.hpp
+++ b/core/fitter.hpp
@@ -1455,9 +1455,9 @@ namespace opt_utilities
//return start_point;
return p_model->get_all_params();
}
- optengine.set_start_point(start_point);
optengine.set_lower_limit(lower_limits);
optengine.set_upper_limit(upper_limits);
+ optengine.set_start_point(start_point);
Tp result;
opt_eq(result,optengine.optimize());
diff --git a/example/Makefile b/example/Makefile
index 24fc4f0..dc05276 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -1,8 +1,13 @@
-target=test_optimizer
+target=test_optimizer test_fitter
+
+all:$(target)
test_optimizer:test_optimizer.cpp
- g++ -o $@ $< -I ../ -O2
+ g++ -o $@ $< -I ../ -O2 -g
+
+test_fitter:test_fitter.cpp
+ g++ -o $@ $< -I ../ -O2 -g
clean:
rm -f $(target)
diff --git a/example/test_fitter.cpp b/example/test_fitter.cpp
new file mode 100644
index 0000000..48c4d8c
--- /dev/null
+++ b/example/test_fitter.cpp
@@ -0,0 +1,59 @@
+#include <core/optimizer.hpp>
+#include <methods/powell/powell_method.hpp>
+#include <methods/aga/aga.hpp>
+#include <core/fitter.hpp>
+#include <vector>
+#include <iostream>
+#include <data_sets/default_data_set.hpp>
+#include <statistics/chisq.hpp>
+
+using namespace opt_utilities;
+//declear a class derived from func_obj
+class lin1d
+ :public opt_utilities::model<double,double,std::vector<double>,std::string>
+ {
+ private:
+ model<double,double,std::vector<double> >* do_clone()const
+ {
+ return new lin1d(*this);
+ }
+ public:
+ lin1d()
+ {
+ this->push_param_info(param_info<std::vector<double> >("k",1,-10,10));
+ this->push_param_info(param_info<std::vector<double> >("b",0,-10,10));
+ }
+
+ public:
+ double do_eval(const double& x,const std::vector<double>& param)
+ {
+ return x*get_element(param,0)+get_element(param,1);
+ }
+
+ private:
+ std::string do_to_string()const
+ {
+ return "linear model\n"
+ "y=k*x+b\n";
+ }
+ };
+
+
+int main()
+{
+ fitter<double,double,std::vector<double>,double,std::string> f;
+ f.set_model(lin1d());
+ //f.set_method(powell_method<double,std::vector<double> >());
+ f.set_method(aga_method<double,std::vector<double> >());
+ default_data_set<double,double> ds;
+
+ for(int i=0;i<100;++i)
+ {
+ ds.add_data(data<double,double>(i,i*3+5,.1,.1,0,0));
+ }
+ f.load_data(ds);
+ f.set_statistic(chisq<double,double,std::vector<double>,double,std::string>());
+ f.fit();
+ cout<<f.get_param_value("k")<<endl;
+ cout<<f.get_param_value("b")<<endl;
+}
diff --git a/methods/aga/aga.hpp b/methods/aga/aga.hpp
index 577e526..eda6e07 100644
--- a/methods/aga/aga.hpp
+++ b/methods/aga/aga.hpp
@@ -140,6 +140,7 @@ namespace opt_utilities
{
// cout<<i<<" ";
resize(samples[i].p,get_size(p));
+ // std::cout<<samples[i].p.size()<<std::endl;;
for(int j=0;j<get_size(p);++j)
{
set_element(samples[i].p,j,