neuroprob/parametrics.py
def sample_hmm(self, timesteps, logp_0, trials=1, cond_nll=None, viterbi=False):
        """
        Sample from the HMM latent variables.
        Forward-backward algorithm can perform smoothing estimate, filter is with forward algorithm.
        
        :param torch.tensor cond_data: conditioning on data via nll -log p(x|z), of shape (maps, time)
        :param bool viterbi: return the MAP if true, otherwise conventional sampling
        :returns: state tensor of shape (trials, time)
        :rtype: torch.tensor
        """
        state = torch.empty((trials, timesteps), device=self.dummy.device).long()
        cc = 0
        
        iterator = tqdm(range(timesteps), leave=False) # AR sampling
        for t in iterator:
            if cond_nll is not None:
                cc = cond_nll[None, :, t]
            
            if t == 0:
                p = (logp_0[None, :] + cc).expand(trials, self.maps)
            else:
                p = torch.log(self.hmm_T[:, state[:, t-1]].T + 1e-12) + cc
                
            if viterbi:
                state[:, t] = torch.argmax(p, dim=1)
            else:
                s = dist.Multinomial(logits=p)()
                state[:, t] = s.topk(1)[1][:, 0].long()
            
        return state

        Sample from the HMM latent variables.
        Forward-backward algorithm can perform smoothing estimate, filter is with forward algorithm.
        
        :param torch.tensor cond_data: conditioning on data via nll -log p(x|z), of shape (maps, time)
        :param bool viterbi: return the MAP if true, otherwise conventional sampling
        :returns: state tensor of shape (trials, time)
        :rtype: torch.tensor
        
Sample from the HMM latent variables.
Forward-backward algorithm can perform smoothing estimate, filter is with forward algorithm.
Sample from the HMM latent variables . Forward - backward algorithm can perform smoothing estimate filter is with forward algorithm .
def sample_hmm(self, timesteps, logp_0, trials=1, cond_nll=None, viterbi=False):
        state = torch.empty((trials, timesteps), device=self.dummy.device).long()
        cc = 0
        iterator = tqdm(range(timesteps), leave=False) 
        for t in iterator:
            if cond_nll is not None:
                cc = cond_nll[None, :, t]
            if t == 0:
                p = (logp_0[None, :] + cc).expand(trials, self.maps)
            else:
                p = torch.log(self.hmm_T[:, state[:, t-1]].T + 1e-12) + cc
            if viterbi:
                state[:, t] = torch.argmax(p, dim=1)
            else:
                s = dist.Multinomial(logits=p)()
                state[:, t] = s.topk(1)[1][:, 0].long()
        return state
def sample_hmm ( self , timesteps , logp_0 , trials = 1 , cond_nll = None , viterbi = False ) : state = torch . empty ( ( trials , timesteps ) , device = self . dummy . device ) . long ( ) cc = 0 iterator = tqdm ( range ( timesteps ) , leave = False ) for t in iterator : if cond_nll is not None : cc = cond_nll [ None , : , t ] if t == 0 : p = ( logp_0 [ None , : ] + cc ) . expand ( trials , self . maps ) else : p = torch . log ( self . hmm_T [ : , state [ : , t - 1 ] ] . T + 1e-12 ) + cc if viterbi : state [ : , t ] = torch . argmax ( p , dim = 1 ) else : s = dist . Multinomial ( logits = p ) ( ) state [ : , t ] = s . topk ( 1 ) [ 1 ] [ : , 0 ] . long ( ) return state
Sample from the HMM latent variables.
Sample from the HMM latent variables .
"""
        Sample from the HMM latent variables.
        Forward-backward algorithm can perform smoothing estimate, filter is with forward algorithm.
        
        :param torch.tensor cond_data: conditioning on data via nll -log p(x|z), of shape (maps, time)
        :param bool viterbi: return the MAP if true, otherwise conventional sampling
        :returns: state tensor of shape (trials, time)
        :rtype: torch.tensor
        """ # AR sampling
state tensor of shape (trials, time)
state tensor of shape ( trials time )
torch.tensor
self
timesteps
logp_0
trials
cond_nll
viterbi
return the MAP if true, otherwise conventional sampling
return the MAP if true otherwise conventional sampling
cond_data
conditioning on data via nll -log p(x|z), of shape (maps, time)
conditioning on data via nll - log p ( x|z ) of shape ( maps time )