From c785b27355ccf0f1cc33b30b1ac088983c314ff2 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Wed, 6 Jul 2011 14:29:53 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@212 ed2142bd-67ad-457f-ba7c-d818d4011675 --- statistics/cstat.hpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/statistics/cstat.hpp b/statistics/cstat.hpp index f0bd529..1d845e3 100644 --- a/statistics/cstat.hpp +++ b/statistics/cstat.hpp @@ -81,6 +81,71 @@ namespace opt_utilities return result; } }; + + /** + \brief c-statistic, max-likelihood method + \tparam Ty the return type of model + \tparam Tx the type of the self-var + \tparam Tp the type of model parameter + \tparam Ts the type of the statistic + \tparam Tstr the type of the string used + */ + template + class cstat1 + :public statistic + { + private: + bool verb; + int n; + public: + cstat1() + :verb(true) + {} + + void verbose(bool v) + { + verb=v; + } + + const char* do_get_type_name()const + { + return "maximum likelihood"; + } + + public: + + statistic* do_clone()const + { + // return const_cast*>(this); + return new cstat1(*this); + } + + Ts do_eval(const Tp& p) + { + Ts result(0); + for(int i=(this->get_data_set()).size()-1;i>=0;--i) + { + Ty model_y=eval_model(this->get_data_set().get_data(i).get_x(),p); + result-=contract1(this->get_data_set().get_data(i).get_y(),std::log(model_y),result); + } + + if(verb) + { + n++; + if(n%10==0) + { + cout<<"a:"<