neuroprob/parametrics.py
def objective(self, nll):
        """
        Compute the marginalized likelihood over discrete states.
        """
        if self.hmm_obs:
            time = torch.arange(nll.shape[1]).to(state.device)
            nll_term = nll[self.hmm_state[b].to(d_.device), time].sum()
        else: # HMM inference
            if b == 0:
                lp = self.logp_0
            else: # continuation between batches with graph cut
                lp = self.logp_hmm

            if enumerate_z: # marginalize the latent z, direct ML fitting, E-step
                nll_term, lp_0 = self.forward_hmm(nll, lp)
                self.logp_hmm = lp_0.data # cut from computational graph
            else: # Welch-Baum algorithm, M-step
                state = self.sample_hmm(nll.shape[1], lp, trials=1, cond_nll=nll, viterbi=True)
                time = torch.arange(state.shape[0]).to(state.device)
                nll_term = nll[state, time].sum() # use MAP latents

                D = self.maps-1
                self.logp_hmm = -12.*torch.ones(self.maps).to(state.device) # set starting point for next batch
                self.logp_hmm[state[-1]] = np.log(1.-D*1e-12)

        Compute the marginalized likelihood over discrete states.
        
Compute the marginalized likelihood over discrete states.
Compute the marginalized likelihood over discrete states .
def objective(self, nll):
        if self.hmm_obs:
            time = torch.arange(nll.shape[1]).to(state.device)
            nll_term = nll[self.hmm_state[b].to(d_.device), time].sum()
        else: 
            if b == 0:
                lp = self.logp_0
            else: 
                lp = self.logp_hmm
            if enumerate_z: 
                nll_term, lp_0 = self.forward_hmm(nll, lp)
                self.logp_hmm = lp_0.data 
            else: 
                state = self.sample_hmm(nll.shape[1], lp, trials=1, cond_nll=nll, viterbi=True)
                time = torch.arange(state.shape[0]).to(state.device)
                nll_term = nll[state, time].sum() 
                D = self.maps-1
                self.logp_hmm = -12.*torch.ones(self.maps).to(state.device) 
                self.logp_hmm[state[-1]] = np.log(1.-D*1e-12)
def objective ( self , nll ) : if self . hmm_obs : time = torch . arange ( nll . shape [ 1 ] ) . to ( state . device ) nll_term = nll [ self . hmm_state [ b ] . to ( d_ . device ) , time ] . sum ( ) else : if b == 0 : lp = self . logp_0 else : lp = self . logp_hmm if enumerate_z : nll_term , lp_0 = self . forward_hmm ( nll , lp ) self . logp_hmm = lp_0 . data else : state = self . sample_hmm ( nll . shape [ 1 ] , lp , trials = 1 , cond_nll = nll , viterbi = True ) time = torch . arange ( state . shape [ 0 ] ) . to ( state . device ) nll_term = nll [ state , time ] . sum ( ) D = self . maps - 1 self . logp_hmm = - 12. * torch . ones ( self . maps ) . to ( state . device ) self . logp_hmm [ state [ - 1 ] ] = np . log ( 1. - D * 1e-12 )
Compute the marginalized likelihood over discrete states.
Compute the marginalized likelihood over discrete states .
"""
        Compute the marginalized likelihood over discrete states.
        """ # HMM inference # continuation between batches with graph cut # marginalize the latent z, direct ML fitting, E-step # cut from computational graph # Welch-Baum algorithm, M-step # use MAP latents # set starting point for next batch
self
nll