neuroprob/filters.py
def sample(self, rate, neuron=None, XZ=None):
        """
        Assumes all neurons outside neuron are observed for spike filtering.
        """
        neuron = self.likelihood._validate_neuron(neuron)
        #ini_train = 
        

        steps = rate.shape[1]
        spikes = []
        spiketrain = torch.empty((*ini_train.shape[:2], self.history_len), device=self.likelihood.tbin.device)

        iterator = tqdm(range(steps), leave=False) # AR sampling
        rate = []
        for t in iterator:
            if t == 0:
                spiketrain[..., :-1] = torch.tensor(ini_train, device=self.likelihood.tbin.device)
            else:
                spiketrain[..., :-2] = spiketrain[..., 1:-1].clone() # shift in time
                spiketrain[..., -2] = torch.tensor(spikes[-1], device=self.likelihood.tbin.device)

            with torch.no_grad(): # spiketrain last time element is dummy, [:-1] used
                hist, hist_var = self.spike_filter(spiketrain, cov_[:, t:t+self.history_len, :])

            rate_ = self.likelihood.f(F_mu[..., t].view(MC_samples, -1, F_mu.shape[1]) + \
                                      hist[None, ..., 0]).mean(0).cpu().numpy() # (trials, neuron)

            ddisp = disp_f(disp.data)[..., t:t+1].view(MC_samples, -1, disp.shape[1], 
                                                       1).mean(0).cpu().numpy() if disp is not None else None
            if obs_spktrn is None:
                spikes.append(self.likelihood.sample(rate_[..., None], n_, XZ=XZ)[..., 0])
                #spikes.append(point_process.gen_IBP(1. - np.exp(-rate_*self.likelihood.tbin.item())))
            else: # condition on observed spike train partially
                spikes.append(obs_spktrn[..., t])
                spikes[-1][:, neuron] = self.likelihood.sample(rate_[..., None], neuron, XZ=XZ)[..., 0]
                #spikes[-1][:, neuron] = point_process.gen_IBP(1. - np.exp(-rate_[:, neuron]*self.likelihood.tbin.item()))
            rate.append(rate_)

        rate = np.stack(rate, axis=-1) # trials, neurons, timesteps
        spktrain = np.transpose(np.array(spikes), (1, 2, 0)) # trials, neurons, timesteps
        
        return spktrain, rate

        Assumes all neurons outside neuron are observed for spike filtering.
        
Assumes all neurons outside neuron are observed for spike filtering.
Assumes all neurons outside neuron are observed for spike filtering .
def sample(self, rate, neuron=None, XZ=None):
        neuron = self.likelihood._validate_neuron(neuron)
        steps = rate.shape[1]
        spikes = []
        spiketrain = torch.empty((*ini_train.shape[:2], self.history_len), device=self.likelihood.tbin.device)
        iterator = tqdm(range(steps), leave=False) 
        rate = []
        for t in iterator:
            if t == 0:
                spiketrain[..., :-1] = torch.tensor(ini_train, device=self.likelihood.tbin.device)
            else:
                spiketrain[..., :-2] = spiketrain[..., 1:-1].clone() 
                spiketrain[..., -2] = torch.tensor(spikes[-1], device=self.likelihood.tbin.device)
            with torch.no_grad(): 
                hist, hist_var = self.spike_filter(spiketrain, cov_[:, t:t+self.history_len, :])
            rate_ = self.likelihood.f(F_mu[..., t].view(MC_samples, -1, F_mu.shape[1]) + \
                                      hist[None, ..., 0]).mean(0).cpu().numpy() 
            ddisp = disp_f(disp.data)[..., t:t+1].view(MC_samples, -1, disp.shape[1], 
                                                       1).mean(0).cpu().numpy() if disp is not None else None
            if obs_spktrn is None:
                spikes.append(self.likelihood.sample(rate_[..., None], n_, XZ=XZ)[..., 0])
            else: 
                spikes.append(obs_spktrn[..., t])
                spikes[-1][:, neuron] = self.likelihood.sample(rate_[..., None], neuron, XZ=XZ)[..., 0]
            rate.append(rate_)
        rate = np.stack(rate, axis=-1) 
        spktrain = np.transpose(np.array(spikes), (1, 2, 0)) 
        return spktrain, rate
def sample ( self , rate , neuron = None , XZ = None ) : neuron = self . likelihood . _validate_neuron ( neuron ) steps = rate . shape [ 1 ] spikes = [ ] spiketrain = torch . empty ( ( * ini_train . shape [ : 2 ] , self . history_len ) , device = self . likelihood . tbin . device ) iterator = tqdm ( range ( steps ) , leave = False ) rate = [ ] for t in iterator : if t == 0 : spiketrain [ ... , : - 1 ] = torch . tensor ( ini_train , device = self . likelihood . tbin . device ) else : spiketrain [ ... , : - 2 ] = spiketrain [ ... , 1 : - 1 ] . clone ( ) spiketrain [ ... , - 2 ] = torch . tensor ( spikes [ - 1 ] , device = self . likelihood . tbin . device ) with torch . no_grad ( ) : hist , hist_var = self . spike_filter ( spiketrain , cov_ [ : , t : t + self . history_len , : ] ) rate_ = self . likelihood . f ( F_mu [ ... , t ] . view ( MC_samples , - 1 , F_mu . shape [ 1 ] ) + hist [ None , ... , 0 ] ) . mean ( 0 ) . cpu ( ) . numpy ( ) ddisp = disp_f ( disp . data ) [ ... , t : t + 1 ] . view ( MC_samples , - 1 , disp . shape [ 1 ] , 1 ) . mean ( 0 ) . cpu ( ) . numpy ( ) if disp is not None else None if obs_spktrn is None : spikes . append ( self . likelihood . sample ( rate_ [ ... , None ] , n_ , XZ = XZ ) [ ... , 0 ] ) else : spikes . append ( obs_spktrn [ ... , t ] ) spikes [ - 1 ] [ : , neuron ] = self . likelihood . sample ( rate_ [ ... , None ] , neuron , XZ = XZ ) [ ... , 0 ] rate . append ( rate_ ) rate = np . stack ( rate , axis = - 1 ) spktrain = np . transpose ( np . array ( spikes ) , ( 1 , 2 , 0 ) ) return spktrain , rate
Assumes all neurons outside neuron are observed for spike filtering.
Assumes all neurons outside neuron are observed for spike filtering .
"""
        Assumes all neurons outside neuron are observed for spike filtering.
        """ #ini_train =  # AR sampling # shift in time # spiketrain last time element is dummy, [:-1] used # (trials, neuron) #spikes.append(point_process.gen_IBP(1. - np.exp(-rate_*self.likelihood.tbin.item()))) # condition on observed spike train partially #spikes[-1][:, neuron] = point_process.gen_IBP(1. - np.exp(-rate_[:, neuron]*self.likelihood.tbin.item())) # trials, neurons, timesteps # trials, neurons, timesteps
self
rate
neuron
XZ