From 4954b5638ced13c2f9d2f0ec4dca77b03f7e89d0 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Wed, 1 Apr 2009 16:09:42 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@11 ed2142bd-67ad-457f-ba7c-d818d4011675 --- interface/opt.cc | 1 + makefile | 1 + statistics/leastsq.hpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ utilities/opt_types.hpp | 2 ++ 4 files changed, 75 insertions(+) create mode 100644 statistics/leastsq.hpp 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 +#include +#include +#include +using std::cerr;using std::endl; + +namespace opt_utilities +{ + template + class leastsq + :public statistic + { + private: + bool verb; + int n; + + + statistic* do_clone()const + { + // return const_cast*>(this); + return new leastsq(*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< #include #include +#include #include namespace opt_utilities @@ -15,6 +16,7 @@ namespace opt_utilities public: typedef fitter fitter; typedef chisq chisq; + typedef leastsq leastsq; typedef powell_method powell_method; typedef model model; typedef default_data_set data_set; -- cgit v1.2.2