diff options
author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2009-04-01 16:09:42 +0000 |
---|---|---|
committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2009-04-01 16:09:42 +0000 |
commit | 4954b5638ced13c2f9d2f0ec4dca77b03f7e89d0 (patch) | |
tree | 142353657c1858f02f9f121c564538257a7da26e | |
parent | 22e026dac6c0a2225e3adb3c9ee336fafaa2e366 (diff) | |
download | opt-utilities-4954b5638ced13c2f9d2f0ec4dca77b03f7e89d0.tar.bz2 |
git-svn-id: file:///home/svn/opt_utilities@11 ed2142bd-67ad-457f-ba7c-d818d4011675
-rw-r--r-- | interface/opt.cc | 1 | ||||
-rw-r--r-- | makefile | 1 | ||||
-rw-r--r-- | statistics/leastsq.hpp | 71 | ||||
-rw-r--r-- | utilities/opt_types.hpp | 2 |
4 files changed, 75 insertions, 0 deletions
diff --git a/interface/opt.cc b/interface/opt.cc index 51762f5..585d2e9 100644 --- a/interface/opt.cc +++ b/interface/opt.cc @@ -19,6 +19,7 @@ struct fit_space { fit.set_method(dopt::powell_method()); dopt::chisq cq; + dopt::leastsq lsq; // cq.verbose(true); fit.set_statistic(cq); } @@ -1,5 +1,6 @@ OPT_HEADS=models/beta1d.hpp statistics/chisq.hpp models/lin1d.hpp\ models/pl1d.hpp models/bl1d.hpp\ + statistics/leastsq.hpp\ core/fitter.hpp models/models.hpp\ core/opt_traits.hpp\ methods/powell/powell_method.hpp models/bpl1d.hpp\ diff --git a/statistics/leastsq.hpp b/statistics/leastsq.hpp new file mode 100644 index 0000000..fa76fa2 --- /dev/null +++ b/statistics/leastsq.hpp @@ -0,0 +1,71 @@ +#ifndef LEAST_SQ_HPP
+#define LeAST_SQ_HPP
+#include <core/fitter.hpp>
+#include <iostream>
+#include <vector>
+#include <cmath>
+using std::cerr;using std::endl;
+
+namespace opt_utilities
+{
+ template<typename Ty,typename Tx,typename Tp,typename Ts,typename Tstr>
+ class leastsq
+ :public statistic<Ty,Tx,Tp,Ts,Tstr>
+ {
+ private:
+ bool verb;
+ int n;
+
+
+ statistic<Ty,Tx,Tp,Ts,Tstr>* do_clone()const
+ {
+ // return const_cast<statistic<Ty,Tx,Tp>*>(this);
+ return new leastsq<Ty,Tx,Tp,Ts,Tstr>(*this);
+ }
+ public:
+ void verbose(bool v)
+ {
+ verb=v;
+ }
+ public:
+ leastsq()
+ :verb(false)
+ {}
+
+
+
+ Ts do_eval(const Tp& p)
+ {
+ Ts result(0);
+ for(int i=(this->datas()).size()-1;i>=0;--i)
+ {
+ Ty chi=(this->datas().get_data(i).get_y()-eval_model(this->datas().get_data(i).get_x(),p));
+ result+=chi*chi;
+
+ }
+ if(verb)
+ {
+ n++;
+ if(n%10==0)
+ {
+
+ cerr<<result<<"\t";
+ for(size_t i=0;i<get_size(p);++i)
+ {
+ cerr<<get_element(p,i)<<",";
+ }
+ cerr<<endl;
+ }
+
+ }
+
+ return result;
+ }
+ };
+
+}
+
+#endif
+//EOF
+
+
diff --git a/utilities/opt_types.hpp b/utilities/opt_types.hpp index 1559ffd..46846cd 100644 --- a/utilities/opt_types.hpp +++ b/utilities/opt_types.hpp @@ -5,6 +5,7 @@ #include <core/default_data_set.hpp> #include <methods/powell/powell_method.hpp> #include <statistics/chisq.hpp> +#include <statistics/leastsq.hpp> #include <vector> namespace opt_utilities @@ -15,6 +16,7 @@ namespace opt_utilities public: typedef fitter<Ty,Tx,Tp,Ts,Tstr> fitter; typedef chisq<Ty,Tx,Tp,Ts,Tstr> chisq; + typedef leastsq<Ty,Tx,Tp,Ts,Tstr> leastsq; typedef powell_method<Ty,Tp> powell_method; typedef model<Ty,Tx,Tp,Tstr> model; typedef default_data_set<Ty,Ty> data_set; |