def loglike(self,data): warn('untested') if len(self.states_list) > 0: s = self.states_list[0] # any state sequence object will work else: # we have to create a temporary one just for its methods, though the # details of the actual state sequence are never used s = states.hmm_states(len(data),self.state_dim,self.obs_distns,self.trans_distn, self.init_state_distn,stateseq=np.zeros(len(data),dtype=np.uint8)) aBl = s.get_aBl(data) betal = s.messages_backwards(aBl) return np.logaddexp.reduce(np.log(self.initial_distn.pi_0) + betal[0] + aBl[0])
def generate(self,T,keep=True): ''' Generates a forward sample using the current values of all parameters. Returns an observation sequence and a state sequence of length T. If keep is True, the states object created is appended to the states_list. This is mostly useful for generating synthetic data and keeping it around in an HSMM object as the latent truth. To construct a posterior sample, one must call both the add_data and resample methods first. Then, calling generate() will produce a sample from the posterior (as long as the Gibbs sampling has converged). In these cases, the keep argument should be False. ''' tempstates = states.hmm_states(T,self.state_dim,self.obs_distns,self.trans_distn, self.init_state_distn) return self._generate(tempstates,keep)
def add_data(self,data,stateseq=None): self.states_list.append(states.hmm_states(len(data),self.state_dim,self.obs_distns,self.trans_distn, self.init_state_distn,data=data,stateseq=stateseq))