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 --- statistics/leastsq.hpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 statistics/leastsq.hpp (limited to 'statistics') 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<