From 412f4f074e758b4889a41a32af571e6f6b0a3701 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Wed, 13 Apr 2011 16:42:47 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@187 ed2142bd-67ad-457f-ba7c-d818d4011675 --- statistics/leastsq.hpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/statistics/leastsq.hpp b/statistics/leastsq.hpp index 3b5ab37..f23f0d1 100644 --- a/statistics/leastsq.hpp +++ b/statistics/leastsq.hpp @@ -8,6 +8,7 @@ #define LEAST_SQ_HPP #define OPT_HEADER #include +#include #include #include #include @@ -84,9 +85,72 @@ namespace opt_utilities return result; } }; + + template + class leastsq,optvec,optvec,Ts,Tstr> + :public statistic,optvec,optvec,Ts,Tstr> + { + private: + bool verb; + int n; + + typedef optvec Tx; + typedef optvec Ty; + typedef optvec Tp; + statistic* do_clone()const + { + // return const_cast*>(this); + return new leastsq(*this); + } + + const char* do_get_type_name()const + { + return "least square statistic"; + } + + public: + void verbose(bool v) + { + verb=v; + } + public: + leastsq() + :verb(false) + {} + + + + Ts do_eval(const Tp& p) + { + Ts result(0); + for(int i=(this->get_data_set()).size()-1;i>=0;--i) + { + Ty chi(this->get_data_set().get_data(0).get_y().size()); + for(int j=0;jget_data_set().get_data(i).get_x(),p)); + if(model_y[j]>this->get_data_set().get_data(i).get_y()[j]) + { + chi[j]=(this->get_data_set().get_data(i).get_y()[j]-model_y[j]); + } + else + { + chi[j]=(this->get_data_set().get_data(i).get_y()[j]-model_y[j]); + } + } + result+=sum(chi*chi); + + } + return result; + } + }; + + } + + #endif //EOF -- cgit v1.2.2