neuroprob/filters.py
def forward(self, input, stimulus):
        """
        Introduces stimulus-dependent raised cosine basis. The basis function parameters are drawn from a 
        GP that depends on the stimulus values at that given time
        
        :param torch.tensor input: input spiketrain or covariates with shape (trials, neurons, timesteps) 
                                   or (samples, neurons, timesteps)
        :param torch.tensor stimulus: input stimulus of shape (trials, timesteps, dims)
        :returns: filtered input of shape (trials, neurons, timesteps)
        """
        assert stimulus is not None
        assert input.shape[0] == 1
        #assert stimulus.shape[1] == input.shape[-1]-self.history_len+1
        
        input_unfold = input.unfold(-1, self.history_len, 1) # samples, neurons, timesteps, fold_dim
        stim_ = stimulus[:, self.history_len:, :] # samples, timesteps, dims
        K = stim_.shape[0]
        T = input_unfold.shape[-2]
        
        inner_batches = np.ceil(T / self.inner_bs).astype(int)
        a_ = []
        a_var_ = []
        for b in range(inner_batches): # inner loop batching
            stim_in = stim_[:, b*self.inner_bs:(b+1)*self.inner_bs, :]
            input_in = input_unfold[..., b*self.inner_bs:(b+1)*self.inner_bs, :]
            
            h_, v_ = self.compute_filter(stim_in) # KxT, out, in, D_fold
            if h_.shape[1] == 1: # output dims
                a = (input_in*h_[:, 0, ...].view(K, -1, *h_.shape[-2:]).permute(0, 2, 1, 3)) # K, N, T, D_fold
                a_.append(a.sum(-1)) # K, N, T
            else: # neurons
                a = (input_in[..., None, :]*h_.view(K, -1, *h_.shape[-3:]).permute(0, 2, 1, 3, 4)) # K, N, T, n_in, D_fold
                a_.append(a.sum(-1).sum(-1)) # K, N, T
                
        filt_var = 0 if len(a_var_) == 0 else torch.cat(a_var_, dim=-1)
        return torch.cat(a_, dim=-1), filt_var

        Introduces stimulus-dependent raised cosine basis. The basis function parameters are drawn from a 
        GP that depends on the stimulus values at that given time
        
        :param torch.tensor input: input spiketrain or covariates with shape (trials, neurons, timesteps) 
                                   or (samples, neurons, timesteps)
        :param torch.tensor stimulus: input stimulus of shape (trials, timesteps, dims)
        :returns: filtered input of shape (trials, neurons, timesteps)
        
Introduces stimulus-dependent raised cosine basis. The basis function parameters are drawn from a
GP that depends on the stimulus values at that given time
Introduces stimulus - dependent raised cosine basis . The basis function parameters are drawn from a GP that depends on the stimulus values at that given time
def forward(self, input, stimulus):
        assert stimulus is not None
        assert input.shape[0] == 1
        input_unfold = input.unfold(-1, self.history_len, 1) 
        stim_ = stimulus[:, self.history_len:, :] 
        K = stim_.shape[0]
        T = input_unfold.shape[-2]
        inner_batches = np.ceil(T / self.inner_bs).astype(int)
        a_ = []
        a_var_ = []
        for b in range(inner_batches): 
            stim_in = stim_[:, b*self.inner_bs:(b+1)*self.inner_bs, :]
            input_in = input_unfold[..., b*self.inner_bs:(b+1)*self.inner_bs, :]
            h_, v_ = self.compute_filter(stim_in) 
            if h_.shape[1] == 1: 
                a = (input_in*h_[:, 0, ...].view(K, -1, *h_.shape[-2:]).permute(0, 2, 1, 3)) 
                a_.append(a.sum(-1)) 
            else: 
                a = (input_in[..., None, :]*h_.view(K, -1, *h_.shape[-3:]).permute(0, 2, 1, 3, 4)) , n_in, D_fold
                a_.append(a.sum(-1).sum(-1)) 
        filt_var = 0 if len(a_var_) == 0 else torch.cat(a_var_, dim=-1)
        return torch.cat(a_, dim=-1), filt_var
def forward ( self , input , stimulus ) : assert stimulus is not None assert input . shape [ 0 ] == 1 input_unfold = input . unfold ( - 1 , self . history_len , 1 ) stim_ = stimulus [ : , self . history_len : , : ] K = stim_ . shape [ 0 ] T = input_unfold . shape [ - 2 ] inner_batches = np . ceil ( T / self . inner_bs ) . astype ( int ) a_ = [ ] a_var_ = [ ] for b in range ( inner_batches ) : stim_in = stim_ [ : , b * self . inner_bs : ( b + 1 ) * self . inner_bs , : ] input_in = input_unfold [ ... , b * self . inner_bs : ( b + 1 ) * self . inner_bs , : ] h_ , v_ = self . compute_filter ( stim_in ) if h_ . shape [ 1 ] == 1 : a = ( input_in * h_ [ : , 0 , ... ] . view ( K , - 1 , * h_ . shape [ - 2 : ] ) . permute ( 0 , 2 , 1 , 3 ) ) a_ . append ( a . sum ( - 1 ) ) else : a = ( input_in [ ... , None , : ] * h_ . view ( K , - 1 , * h_ . shape [ - 3 : ] ) . permute ( 0 , 2 , 1 , 3 , 4 ) ) a_ . append ( a . sum ( - 1 ) . sum ( - 1 ) ) filt_var = 0 if len ( a_var_ ) == 0 else torch . cat ( a_var_ , dim = - 1 ) return torch . cat ( a_ , dim = - 1 ) , filt_var
Introduces stimulus-dependent raised cosine basis.
Introduces stimulus - dependent raised cosine basis .
"""
        Introduces stimulus-dependent raised cosine basis. The basis function parameters are drawn from a 
        GP that depends on the stimulus values at that given time
        
        :param torch.tensor input: input spiketrain or covariates with shape (trials, neurons, timesteps) 
                                   or (samples, neurons, timesteps)
        :param torch.tensor stimulus: input stimulus of shape (trials, timesteps, dims)
        :returns: filtered input of shape (trials, neurons, timesteps)
        """ #assert stimulus.shape[1] == input.shape[-1]-self.history_len+1 # samples, neurons, timesteps, fold_dim # samples, timesteps, dims # inner loop batching # KxT, out, in, D_fold # output dims # K, N, T, D_fold # K, N, T # neurons # K, N, T, n_in, D_fold # K, N, T
filtered input of shape (trials, neurons, timesteps)
filtered input of shape ( trials neurons timesteps )
self
input
input spiketrain or covariates with shape (trials, neurons, timesteps)
or (samples, neurons, timesteps)
input spiketrain or covariates with shape ( trials neurons timesteps ) or ( samples neurons timesteps )
stimulus
input stimulus of shape (trials, timesteps, dims)
input stimulus of shape ( trials timesteps dims )