neuroprob/parametrics.py
def forward_hmm(self, nll, logp_0):
        """
        Discrete variable, forward algorithm or message passing to marginalize efficiently.
        
        :param torch.tensor nll: the objective function for each latent state of shape (state, time)
        :param torch.tensor logp_0: the initial log probabilities of the states at start of the chain
        :returns: negative log probability after marginalizing hidden states and log p(z_t|X})
        :rtype: tuple of torch.tensor
        """
        trans_logp = torch.log(self.hmm_T + 1e-12)
        for t in range(nll.shape[1]):
            if t == 0:
                logp = logp_0 - nll[:, 0] # p(z_0) * p(x_0|z_0)
            else:
                logp = (logp.unsqueeze(0) - nll[:, t].unsqueeze(1) + trans_logp).logsumexp(dim=1)
                # \sum_{z_{t-1}} p(z_{t-1}|x_{<t}) * p(z_t|z_{t-1}) * p(x_t|z_t)
            
        return -logp.sum(), (logp.unsqueeze(0) + trans_logp).logsumexp(dim=1)

        Discrete variable, forward algorithm or message passing to marginalize efficiently.
        
        :param torch.tensor nll: the objective function for each latent state of shape (state, time)
        :param torch.tensor logp_0: the initial log probabilities of the states at start of the chain
        :returns: negative log probability after marginalizing hidden states and log p(z_t|X})
        :rtype: tuple of torch.tensor
        
Discrete variable, forward algorithm or message passing to marginalize efficiently.
Discrete variable forward algorithm or message passing to marginalize efficiently .
def forward_hmm(self, nll, logp_0):
        trans_logp = torch.log(self.hmm_T + 1e-12)
        for t in range(nll.shape[1]):
            if t == 0:
                logp = logp_0 - nll[:, 0] 
            else:
                logp = (logp.unsqueeze(0) - nll[:, t].unsqueeze(1) + trans_logp).logsumexp(dim=1)
        return -logp.sum(), (logp.unsqueeze(0) + trans_logp).logsumexp(dim=1)
def forward_hmm ( self , nll , logp_0 ) : trans_logp = torch . log ( self . hmm_T + 1e-12 ) for t in range ( nll . shape [ 1 ] ) : if t == 0 : logp = logp_0 - nll [ : , 0 ] else : logp = ( logp . unsqueeze ( 0 ) - nll [ : , t ] . unsqueeze ( 1 ) + trans_logp ) . logsumexp ( dim = 1 ) return - logp . sum ( ) , ( logp . unsqueeze ( 0 ) + trans_logp ) . logsumexp ( dim = 1 )
Discrete variable, forward algorithm or message passing to marginalize efficiently.
Discrete variable forward algorithm or message passing to marginalize efficiently .
"""
        Discrete variable, forward algorithm or message passing to marginalize efficiently.
        
        :param torch.tensor nll: the objective function for each latent state of shape (state, time)
        :param torch.tensor logp_0: the initial log probabilities of the states at start of the chain
        :returns: negative log probability after marginalizing hidden states and log p(z_t|X})
        :rtype: tuple of torch.tensor
        """ # p(z_0) * p(x_0|z_0) # \sum_{z_{t-1}} p(z_{t-1}|x_{<t}) * p(z_t|z_{t-1}) * p(x_t|z_t)
negative log probability after marginalizing hidden states and log p(z_t|X})
negative log probability after marginalizing hidden states and log p ( z_t|X } )
tuple of torch.tensor
self
nll
the objective function for each latent state of shape (state, time)
the objective function for each latent state of shape ( state time )
logp_0
the initial log probabilities of the states at start of the chain
the initial log probabilities of the states at start of the chain