neuroprob/likelihoods.py
def objective(self, F_mu, F_var, XZ, b, neuron, samples=10, mode='MC'):
        """
        The Poisson likelihood with the log Cox process has an exact variational likelihood term.
        """
        if self.inv_link == 'exp': # exact
            if isinstance(F_var, numbers.Number) is False and len(F_var.shape) == 4: # diagonalize
                F_var = F_var.view(*F_var.shape[:2], -1)[:, :, ::F_var.shape[-1]+1]
            
            spikes = self.spikes[b][:, neuron, self.filter_len-1:].to(self.tbin.device)
            rates = self.f(F_mu + F_var/2.)[:, neuron, :] # watch out for underflow or overflow here
            l_rates = (spikes*F_mu[:, neuron, :])
            
            tfact, lfact = self.get_saved_factors(b, neuron, spikes)
            T = rates*self.tbin
            nll = (-l_rates + T - tfact + lfact)
            
            ws = torch.tensor(1./rates.shape[0])
            return nll.sum(1), ws # first dimension is summed over later (MC over Z), hence divide by shape[0]
        else:
            return super().objective(F_mu, F_var, XZ, b, neuron, 
                                     samples=samples, mode=mode)

        The Poisson likelihood with the log Cox process has an exact variational likelihood term.
        
The Poisson likelihood with the log Cox process has an exact variational likelihood term.
The Poisson likelihood with the log Cox process has an exact variational likelihood term .
def objective(self, F_mu, F_var, XZ, b, neuron, samples=10, mode='MC'):
        if self.inv_link == 'exp': 
            if isinstance(F_var, numbers.Number) is False and len(F_var.shape) == 4: 
                F_var = F_var.view(*F_var.shape[:2], -1)[:, :, ::F_var.shape[-1]+1]
            spikes = self.spikes[b][:, neuron, self.filter_len-1:].to(self.tbin.device)
            rates = self.f(F_mu + F_var/2.)[:, neuron, :] 
            l_rates = (spikes*F_mu[:, neuron, :])
            tfact, lfact = self.get_saved_factors(b, neuron, spikes)
            T = rates*self.tbin
            nll = (-l_rates + T - tfact + lfact)
            ws = torch.tensor(1./rates.shape[0])
            return nll.sum(1), ws 
        else:
            return super().objective(F_mu, F_var, XZ, b, neuron, 
                                     samples=samples, mode=mode)
def objective ( self , F_mu , F_var , XZ , b , neuron , samples = 10 , mode = 'MC' ) : if self . inv_link == 'exp' : if isinstance ( F_var , numbers . Number ) is False and len ( F_var . shape ) == 4 : F_var = F_var . view ( * F_var . shape [ : 2 ] , - 1 ) [ : , : , : : F_var . shape [ - 1 ] + 1 ] spikes = self . spikes [ b ] [ : , neuron , self . filter_len - 1 : ] . to ( self . tbin . device ) rates = self . f ( F_mu + F_var / 2. ) [ : , neuron , : ] l_rates = ( spikes * F_mu [ : , neuron , : ] ) tfact , lfact = self . get_saved_factors ( b , neuron , spikes ) T = rates * self . tbin nll = ( - l_rates + T - tfact + lfact ) ws = torch . tensor ( 1. / rates . shape [ 0 ] ) return nll . sum ( 1 ) , ws else : return super ( ) . objective ( F_mu , F_var , XZ , b , neuron , samples = samples , mode = mode )
The Poisson likelihood with the log Cox process has an exact variational likelihood term.
The Poisson likelihood with the log Cox process has an exact variational likelihood term .
"""
        The Poisson likelihood with the log Cox process has an exact variational likelihood term.
        """ # exact # diagonalize # watch out for underflow or overflow here # first dimension is summed over later (MC over Z), hence divide by shape[0]
self
F_mu
F_var
XZ
b
neuron
samples
mode