diff options
author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2011-07-06 14:29:53 +0000 |
---|---|---|
committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2011-07-06 14:29:53 +0000 |
commit | c785b27355ccf0f1cc33b30b1ac088983c314ff2 (patch) | |
tree | 05484be0f585f5c37a20d22c904df35e767191c7 /statistics | |
parent | 950e398812bf553311ef40b59c33be42e39ec026 (diff) | |
download | opt-utilities-c785b27355ccf0f1cc33b30b1ac088983c314ff2.tar.bz2 |
git-svn-id: file:///home/svn/opt_utilities@212 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'statistics')
-rw-r--r-- | statistics/cstat.hpp | 65 |
1 files changed, 65 insertions, 0 deletions
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<typename Ty,typename Tx,typename Tp,typename Ts,typename Tstr>
+ class cstat1
+ :public statistic<Ty,Tx,Tp,Ts,Tstr>
+ {
+ 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<Ty,Tx,Tp,Ts,Tstr>* do_clone()const
+ {
+ // return const_cast<statistic<Ty,Tx,Tp>*>(this);
+ return new cstat1<Ty,Tx,Tp,Ts,Tstr>(*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:"<<result<<"\t";
+ for(size_t i=0;i<get_size(p);++i)
+ {
+ cout<<get_element(p,i)<<",";
+ }
+ cout<<endl;
+ }
+
+ }
+ return result;
+ }
+ };
}
#endif
|