Exemplo n.º 1
0
 double HmmFilter::initialize(const Data * dp){
   uint S = state_space_size();
   pi = markov_->pi0();
   if(dp->missing()) logp = 0;
   else for(uint s=0; s<S; ++s) logp[s] = models_[s]->pdf(dp, true);
   pi = log(pi) + logp;
   double m = max(pi);
   pi = exp(pi-m);
   double nc = sum(pi);
   double loglike = m + log(nc);
   pi/=nc;
   return loglike;
 }
Exemplo n.º 2
0
 //------------------------------------------------------------
 void HmmEmFilter::bkwd_smoothing(const std::vector<Ptr<Data> > & dv){
   // pi was set by fwd;
   uint n = dv.size();
   uint S = state_space_size();
   for(uint i=n-1; i!=0; --i){
     for(uint s=0; s<S; ++s) models_[s]->add_mixture_data(dv[i], pi[s]);
     markov_->suf()->add_transition_distribution(P[i]);
     bkwd_1(pi, P[i], logp, one);
   }
   pi = P[1] * one;
   for(uint s=0; s<S; ++s) models_[s]->add_mixture_data(dv[0], pi[s]);
   markov_->suf()->add_initial_distribution(pi);
 }
Exemplo n.º 3
0
  double MarkovModel::loglike(const Vector &serialized_params)const{
    const Vec &icount(suf()->init());
    const Mat &tcount(suf()->trans());

    int S = state_space_size();
    TransitionProbabilityMatrix transition_probabilities(S);

    Vec logpi0(log(pi0()));
    Mat logQ(log(Q()));

    double ans= icount.dot(logpi0);
    ans+= el_mult_sum(tcount, logQ);
    return ans;
  }
Exemplo n.º 4
0
 double HmmFilter::fwd(const std::vector<Ptr<Data> > &dv){
   logQ = log(markov_->Q() );
   uint n = dv.size();
   uint S = state_space_size();
   if(logp.size()!=S) logp.resize(S);
   if(P.size() < n) P.resize(n);
   double loglike = initialize(dv[0].get());
   for(uint i=1; i<n; ++i){
     if(dv[i]->missing()) logp = 0;
     else for(uint s=0; s<S; ++s) logp[s] = models_[s]->pdf(dv[i].get(), true);
     loglike += fwd_1(pi, P[i], logQ, logp, one);
   }
   return loglike;
 }
Exemplo n.º 5
0
 void MarkovModel::fix_pi0_uniform(){
   uint S = state_space_size();
   set_pi0(Vec(S, 1.0/S));
   pi0_status=Uniform;  }
Exemplo n.º 6
0
 void MarkovSuf::resize(uint p){
   if(state_space_size()!=p){
     trans_ = Mat(p,p, 0.0);
     init_ = Vec(p, 0.0);}}