From 1f4a944064bc42284c33e6b755353d191cf288e8 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Mon, 15 Dec 2008 07:26:12 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@1 ed2142bd-67ad-457f-ba7c-d818d4011675 --- statistics/cstat.hpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 statistics/cstat.hpp (limited to 'statistics/cstat.hpp') diff --git a/statistics/cstat.hpp b/statistics/cstat.hpp new file mode 100644 index 0000000..b6b401d --- /dev/null +++ b/statistics/cstat.hpp @@ -0,0 +1,66 @@ +#ifndef CSTAT_HPP +#define CSTAT_HPP +#include +#include + +using std::cout;using std::endl; +namespace opt_utilities +{ + template + class cstat_poisson + :public statistic + { + private: + bool verb; + int n; + + Ty lnfrac(Ty y)const + { + return y*log(y)-y; + } + + public: + void verbose(bool v) + { + verb=v; + } + public: + + statistic* do_clone()const + { + // return const_cast*>(this); + return new cstat_poisson(*this); + } + + Ts do_eval(const Tp& p) + { + Ts result(0); + for(int i=(this->datas()).size()-1;i>=0;--i) + { + Ty model_y=eval_model(this->datas().get_data(i).get_x(),p); + result+=model_y-this->datas().get_data(i).get_y()*log(model_y)+lnfrac(this->datas().get_data(i).get_y()); + } + + if(verb) + { + n++; + if(n%10==0) + { + cout<p_fitter->get_dof()<<"\t"; + for(int i=0;i