aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--interface/opt.cc1
-rw-r--r--makefile1
-rw-r--r--statistics/leastsq.hpp71
-rw-r--r--utilities/opt_types.hpp2
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);
}
diff --git a/makefile b/makefile
index e40ac11..a317bc8 100644
--- a/makefile
+++ b/makefile
@@ -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;