/** \file kmm_stat.hpp \brief maximum-liklihood statistic \author Junhua Gu */ #ifndef KMM_STAT_HPP #define KMM_STAT_HPP #define OPT_HEADER #include #include #include #include #include using std::cout;using std::endl; namespace opt_utilities { /** \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 kmm_stat :public statistic,optvec,optvec,Ts,Tstr> { private: bool verb; int n; public: kmm_stat() :verb(true) {} void verbose(bool v) { verb=v; } const char* do_get_type_name()const { return "kmm likelihood"; } public: statistic,optvec,optvec,Ts,Tstr>* do_clone()const { // return const_cast*>(this); return new kmm_stat(*this); } Ts do_eval(const optvec& p) { Ts result(0); kmm_component* kmm= dynamic_cast* >(&const_cast,optvec,optvec,std::string>&>(this->get_fitter().get_model())); if(kmm==0) { throw opt_exception("model is not a kmm component"); } for(int i=(this->get_data_set()).size()-1;i>=0;--i) { optvec unsummed_possibility(kmm->eval_unsumed(this->get_data_set().get_data(i).get_x(),p)); T maxp=*max_element(unsummed_possibility.begin(),unsummed_possibility.end()); T logp=std::log(maxp); result-=this->get_data_set().get_data(i).get_y()[0]*logp; } if(verb) { n++; if(n%10==0) { cout<<"a:"<