neuroprob/likelihoods.py
def objective(self, F_mu, F_var, XZ, b, neuron, samples, mode='MC'):        
        """
        Gaussian likelihood for activity train
        samples introduces a sample dimension from the left
        F_mu has shape (samples, neuron, timesteps)
        if F_var = 0, we don't expand by samples in the sample dimension
        """
        spikes = self.spikes[b][None, neuron, self.filter_len-1:].to(self.tbin.device) # activity
        batch_size = F_mu.shape[-1]
        
        if self.inv_link == 'identity': # exact
            noise_var = (self.L @ self.L.t())[None, neuron, None] + F_var[:, neuron, :]
            
            nll = .5*(torch.log(noise_var) + ((spikes - F_mu)**2)/noise_var + F_var/noise_var).sum(-1) + \
                  .5*torch.log(torch.tensor(2*np.pi))*batch_size
        else:
            if F_var != 0: # MC samples
                h = dist.Rn_Normal(F_mu, F_var)((samples,)).view(-1, *F_mu.shape[1:])[:, neuron, :]
                F_var = F_var.repeat(samples, 1, 1)
            else:
                h = F_mu[:, neuron, :]

            rates = self.f(h)
            noise_var = (torch.exp(self.log_var)[None, neuron, None] + F_var[:, neuron, :])
            
            nll = .5*(torch.log(noise_var) + ((spikes - rates)**2)/noise_var).sum(-1) + \
                  .5*torch.log(torch.tensor(2*np.pi))*batch_size

        ws = torch.tensor(1./nll.shape[0])
        return nll.sum(1), ws

        Gaussian likelihood for activity train
        samples introduces a sample dimension from the left
        F_mu has shape (samples, neuron, timesteps)
        if F_var = 0, we don't expand by samples in the sample dimension
        
Gaussian likelihood for activity train
samples introduces a sample dimension from the left
F_mu has shape (samples, neuron, timesteps)
if F_var = 0, we don't expand by samples in the sample dimension
Gaussian likelihood for activity train samples introduces a sample dimension from the left F_mu has shape ( samples neuron timesteps ) if F_var = 0 we don ' t expand by samples in the sample dimension
def objective(self, F_mu, F_var, XZ, b, neuron, samples, mode='MC'):        
        spikes = self.spikes[b][None, neuron, self.filter_len-1:].to(self.tbin.device) 
        batch_size = F_mu.shape[-1]
        if self.inv_link == 'identity': 
            noise_var = (self.L @ self.L.t())[None, neuron, None] + F_var[:, neuron, :]
            nll = .5*(torch.log(noise_var) + ((spikes - F_mu)**2)/noise_var + F_var/noise_var).sum(-1) + \
                  .5*torch.log(torch.tensor(2*np.pi))*batch_size
        else:
            if F_var != 0: 
                h = dist.Rn_Normal(F_mu, F_var)((samples,)).view(-1, *F_mu.shape[1:])[:, neuron, :]
                F_var = F_var.repeat(samples, 1, 1)
            else:
                h = F_mu[:, neuron, :]
            rates = self.f(h)
            noise_var = (torch.exp(self.log_var)[None, neuron, None] + F_var[:, neuron, :])
            nll = .5*(torch.log(noise_var) + ((spikes - rates)**2)/noise_var).sum(-1) + \
                  .5*torch.log(torch.tensor(2*np.pi))*batch_size
        ws = torch.tensor(1./nll.shape[0])
        return nll.sum(1), ws
def objective ( self , F_mu , F_var , XZ , b , neuron , samples , mode = 'MC' ) : spikes = self . spikes [ b ] [ None , neuron , self . filter_len - 1 : ] . to ( self . tbin . device ) batch_size = F_mu . shape [ - 1 ] if self . inv_link == 'identity' : noise_var = ( self . L @ self . L . t ( ) ) [ None , neuron , None ] + F_var [ : , neuron , : ] nll = .5 * ( torch . log ( noise_var ) + ( ( spikes - F_mu ) ** 2 ) / noise_var + F_var / noise_var ) . sum ( - 1 ) + .5 * torch . log ( torch . tensor ( 2 * np . pi ) ) * batch_size else : if F_var != 0 : h = dist . Rn_Normal ( F_mu , F_var ) ( ( samples , ) ) . view ( - 1 , * F_mu . shape [ 1 : ] ) [ : , neuron , : ] F_var = F_var . repeat ( samples , 1 , 1 ) else : h = F_mu [ : , neuron , : ] rates = self . f ( h ) noise_var = ( torch . exp ( self . log_var ) [ None , neuron , None ] + F_var [ : , neuron , : ] ) nll = .5 * ( torch . log ( noise_var ) + ( ( spikes - rates ) ** 2 ) / noise_var ) . sum ( - 1 ) + .5 * torch . log ( torch . tensor ( 2 * np . pi ) ) * batch_size ws = torch . tensor ( 1. / nll . shape [ 0 ] ) return nll . sum ( 1 ) , ws
Gaussian likelihood for activity train
samples introduces a sample dimension from the left
F_mu has shape (samples, neuron, timesteps)
if F_var = 0, we don't expand by samples in the sample dimension
Gaussian likelihood for activity train samples introduces a sample dimension from the left F_mu has shape ( samples neuron timesteps ) if F_var = 0 we don ' t expand by samples in the sample dimension
"""
        Gaussian likelihood for activity train
        samples introduces a sample dimension from the left
        F_mu has shape (samples, neuron, timesteps)
        if F_var = 0, we don't expand by samples in the sample dimension
        """ # activity # exact # MC samples
self
F_mu
F_var
XZ
b
neuron
samples
mode