neuroprob/likelihoods.py
def nll(self, l_rates, rISI, neuron):
        """
        Gamma case, approximates the spiketrain NLL (takes tbin into account for NLL).
        
        :param np.array neuron: fit over given neurons, must be an array
        :param torch.tensor F_mu: F_mu product with shape (samples, neurons, timesteps)
        :param torch.tensor F_var: variance of the F_mu values, same shape
        :param int b: batch number
        :param np.array neuron: neuron indices that are used
        :param int samples: number of MC samples for likelihood evaluation
        :returns: NLL array over sample dimensions
        :rtype: torch.tensor
        """
        samples_ = l_rates.shape[0] # ll_samplesxcov_samples, in case of trials trial_num=cov_samples
        shape_ = self.shape.expand(1, self.F_dims)[:, neuron]
        
        # Ignore the end points of the spike train
        # d_Lambda_i = rates[:self.spiketimes[0]].sum()*self.tbin
        # d_Lambda_f = rates[self.spiketimes[ii]:].sum()*self.tbin
        # l_start = torch.empty((len(neuron)), device=self.tbin.device)
        # l_end = torch.empty((len(neuron)), device=self.tbin.device)
        # l_start[n_enu] = torch.log(sps.gammaincc(self.shape.item(), d_Lambda_i))
        # l_end[n_enu] = torch.log(sps.gammaincc(self.shape.item(), d_Lambda_f))
        
        intervals = torch.zeros((samples_, len(neuron)), device=self.tbin.device)
        T = torch.empty((samples_, len(neuron)), device=self.tbin.device) # MC samples, neurons
        l_Lambda = torch.empty((samples_, len(neuron)), device=self.tbin.device)
        for tr, isis in enumerate(rISI): # over trials
            for n_enu, isi in enumerate(isis): # over neurons
                if len(isi) > 0: # nonzero number of ISIs
                    intervals[tr::self.trials, n_enu] = isi.shape[-1]
                    T[tr::self.trials, n_enu] = isi.sum(-1)
                    l_Lambda[tr::self.trials, n_enu] = torch.log(isi+1e-12).sum(-1)
                else:
                    T[tr::self.trials, n_enu] = 0 # TODO: minibatching ISIs approximate due to b.c.
                    l_Lambda[tr::self.trials, n_enu] = 0

        nll = -(shape_-1)*l_Lambda - l_rates + T + intervals[None, :]*torch.lgamma(shape_)
        return nll.sum(1, keepdims=True)

        Gamma case, approximates the spiketrain NLL (takes tbin into account for NLL).
        
        :param np.array neuron: fit over given neurons, must be an array
        :param torch.tensor F_mu: F_mu product with shape (samples, neurons, timesteps)
        :param torch.tensor F_var: variance of the F_mu values, same shape
        :param int b: batch number
        :param np.array neuron: neuron indices that are used
        :param int samples: number of MC samples for likelihood evaluation
        :returns: NLL array over sample dimensions
        :rtype: torch.tensor
        
Gamma case, approximates the spiketrain NLL (takes tbin into account for NLL).
Gamma case approximates the spiketrain NLL ( takes tbin into account for NLL ) .
def nll(self, l_rates, rISI, neuron):
        samples_ = l_rates.shape[0] 
        shape_ = self.shape.expand(1, self.F_dims)[:, neuron]
        intervals = torch.zeros((samples_, len(neuron)), device=self.tbin.device)
        T = torch.empty((samples_, len(neuron)), device=self.tbin.device) 
        l_Lambda = torch.empty((samples_, len(neuron)), device=self.tbin.device)
        for tr, isis in enumerate(rISI): 
            for n_enu, isi in enumerate(isis): 
                if len(isi) > 0: 
                    intervals[tr::self.trials, n_enu] = isi.shape[-1]
                    T[tr::self.trials, n_enu] = isi.sum(-1)
                    l_Lambda[tr::self.trials, n_enu] = torch.log(isi+1e-12).sum(-1)
                else:
                    T[tr::self.trials, n_enu] = 0 
                    l_Lambda[tr::self.trials, n_enu] = 0
        nll = -(shape_-1)*l_Lambda - l_rates + T + intervals[None, :]*torch.lgamma(shape_)
        return nll.sum(1, keepdims=True)
def nll ( self , l_rates , rISI , neuron ) : samples_ = l_rates . shape [ 0 ] shape_ = self . shape . expand ( 1 , self . F_dims ) [ : , neuron ] intervals = torch . zeros ( ( samples_ , len ( neuron ) ) , device = self . tbin . device ) T = torch . empty ( ( samples_ , len ( neuron ) ) , device = self . tbin . device ) l_Lambda = torch . empty ( ( samples_ , len ( neuron ) ) , device = self . tbin . device ) for tr , isis in enumerate ( rISI ) : for n_enu , isi in enumerate ( isis ) : if len ( isi ) > 0 : intervals [ tr : : self . trials , n_enu ] = isi . shape [ - 1 ] T [ tr : : self . trials , n_enu ] = isi . sum ( - 1 ) l_Lambda [ tr : : self . trials , n_enu ] = torch . log ( isi + 1e-12 ) . sum ( - 1 ) else : T [ tr : : self . trials , n_enu ] = 0 l_Lambda [ tr : : self . trials , n_enu ] = 0 nll = - ( shape_ - 1 ) * l_Lambda - l_rates + T + intervals [ None , : ] * torch . lgamma ( shape_ ) return nll . sum ( 1 , keepdims = True )
Gamma case, approximates the spiketrain NLL (takes tbin into account for NLL).
Gamma case approximates the spiketrain NLL ( takes tbin into account for NLL ) .
"""
        Gamma case, approximates the spiketrain NLL (takes tbin into account for NLL).
        
        :param np.array neuron: fit over given neurons, must be an array
        :param torch.tensor F_mu: F_mu product with shape (samples, neurons, timesteps)
        :param torch.tensor F_var: variance of the F_mu values, same shape
        :param int b: batch number
        :param np.array neuron: neuron indices that are used
        :param int samples: number of MC samples for likelihood evaluation
        :returns: NLL array over sample dimensions
        :rtype: torch.tensor
        """ # ll_samplesxcov_samples, in case of trials trial_num=cov_samples # Ignore the end points of the spike train # d_Lambda_i = rates[:self.spiketimes[0]].sum()*self.tbin # d_Lambda_f = rates[self.spiketimes[ii]:].sum()*self.tbin # l_start = torch.empty((len(neuron)), device=self.tbin.device) # l_end = torch.empty((len(neuron)), device=self.tbin.device) # l_start[n_enu] = torch.log(sps.gammaincc(self.shape.item(), d_Lambda_i)) # l_end[n_enu] = torch.log(sps.gammaincc(self.shape.item(), d_Lambda_f)) # MC samples, neurons # over trials # over neurons # nonzero number of ISIs # TODO: minibatching ISIs approximate due to b.c.
NLL array over sample dimensions
NLL array over sample dimensions
torch.tensor
self
l_rates
rISI
neuron
neuron indices that are used
neuron indices that are used
F_mu
F_mu product with shape (samples, neurons, timesteps)
F_mu product with shape ( samples neurons timesteps )
F_var
variance of the F_mu values, same shape
variance of the F_mu values same shape
b
None
samples
number of MC samples for likelihood evaluation
number of MC samples for likelihood evaluation