Example #1
0
 def initialize_refractory(self, refractory):
     if isinstance(refractory, float):
         refractory = refractory * ones(self.N)
     self.refractory_arr = gpuarray.to_gpu(
         array(rint(refractory / self.dt), dtype=int32))
     self.next_allowed_spiketime_arr = gpuarray.to_gpu(
         -ones(self.N, dtype=int32))
Example #2
0
    def run(self, **param_values):
        delays = param_values.pop('delays', zeros(self.neurons))
        
#        print self.refractory,self.max_refractory
        if self.max_refractory is not None:
            refractory = param_values.pop('refractory', zeros(self.neurons))
        else:
            refractory = self.refractory*ones(self.neurons)
            
        tau_metric = param_values.pop('tau_metric', zeros(self.neurons))
        self.update_neurongroup(**param_values)

        # repeat spike delays and refractory to take slices into account
        delays = kron(delays, ones(self.slices))
        refractory = kron(refractory, ones(self.slices))
        tau_metric = kron(tau_metric, ones(self.slices))
        # TODO: add here parameters to criterion_params if a criterion must use some parameters
        criterion_params = dict(delays=delays)

        if self.criterion.__class__.__name__ == 'Brette':
            criterion_params['tau_metric'] = tau_metric
    
        
        self.update_neurongroup(**param_values)
        self.initialize_criterion(**criterion_params)
        
        if self.use_gpu:
            # Reinitializes the simulation object
            self.mf.reinit_vars(self.criterion_object,
                                self.inputs_inline, self.inputs_offset,
                                self.spikes_inline, self.spikes_offset,
                                self.traces_inline, self.traces_offset,
                                delays, refractory
                                )
            # LAUNCHES the simulation on the GPU
            self.mf.launch(self.sliced_duration, self.stepsize)
            # Synchronize the GPU values with a call to gpuarray.get()
            self.criterion_object.update_gpu_values()
        else:
            # set the refractory period
            if self.max_refractory is not None:
                self.group.refractory = refractory
            # Launch the simulation on the CPU
            self.group.clock.reinit()
            net = Network(self.group, self.criterion_object)
            if self.statemonitor_var is not None:
                self.statemonitors = []
                for state in self.statemonitor_var:
                    monitor = StateMonitor(self.group, state, record=True)
                    self.statemonitors.append(monitor)
                    net.add(monitor)
            net.run(self.sliced_duration)
        
        sliced_values = self.criterion_object.get_values()
        combined_values = self.combine_sliced_values(sliced_values)
        values = self.criterion_object.normalize(combined_values)
        return values
Example #3
0
    def initialize(self, delta, coincidence_count_algorithm):
        self.algorithm = coincidence_count_algorithm
        self.delta = int(rint(delta / self.dt))
        
        self.spike_count = zeros(self.N, dtype='int')
        self.coincidences = zeros(self.N, dtype='int')
        self.spiketime_index = self.spikes_offset
        self.last_spike_time = array(rint(self.spikes_inline[self.spiketime_index] / self.dt), dtype=int)
        self.next_spike_time = array(rint(self.spikes_inline[self.spiketime_index + 1] / self.dt), dtype=int)

        # First target spikes (needed for the computation of 
        #   the target train firing rates)
#        self.first_target_spike = zeros(self.N)

        self.last_spike_allowed = ones(self.N, dtype='bool')
        self.next_spike_allowed = ones(self.N, dtype='bool')
Example #4
0
 def transform_traces(self, traces):
     # from standard structure to inline structure
     K, T = traces.shape
     traces_inline = traces.flatten()
     traces_offset = array(kron(arange(K), T * ones(self.subpopsize)),
                           dtype=int)
     return traces_inline, traces_offset
Example #5
0
    def evaluate(self, **param_values):
        """
        Use fitparams['delays'] to take delays into account
        Use fitparams['refractory'] to take refractory into account
        """
        delays = param_values.pop('delays', zeros(self.neurons))
        refractory = param_values.pop('refractory', zeros(self.neurons))
        tau_metric = param_values.pop('tau_metric', zeros(self.neurons))

        # repeat spike delays and refractory to take slices into account
        delays = kron(delays, ones(self.slices))
        refractory = kron(refractory, ones(self.slices))
        tau_metric = kron(tau_metric, ones(self.slices))
        
        self.update_neurongroup(**param_values)
        if self.criterion.__class__.__name__ == 'Brette':
            self.initialize_criterion(delays,tau_metric)
        else:
            self.initialize_criterion(delays)
        
        if self.use_gpu:
            pass
            #########
            # TODO
            #########
#            # Reinitializes the simulation object
#            self.mf.reinit_vars(self.input, self.I_offset, self.spiketimes, self.spiketimes_offset, delays, refractory)
#            # LAUNCHES the simulation on the GPU
#            self.mf.launch(self.duration, self.stepsize)
#            coincidence_count = self.mf.coincidence_count
#            spike_count = self.mf.spike_count
        else:
            # set the refractory period
            if self.max_refractory is not None:
                self.group.refractory = refractory
            
            # Launch the simulation on the CPU
            self.group.clock.reinit()
            net = Network(self.group, self.criterion_object)
            net.run(self.duration)
        
        sliced_values = self.criterion_object.get_values()
        combined_values = self.combine_sliced_values(sliced_values)
        values = self.criterion_object.normalize(combined_values)
        return values
Example #6
0
 def initialize_cuda_variables(self):
     """
     Initialize GPU variables to pass to the kernel
     """
     self.spike_count_gpu = gpuarray.to_gpu(zeros(self.N, dtype=int32))
     self.coincidences_gpu = gpuarray.to_gpu(zeros(self.N, dtype=int32))
     
     if self.algorithm == 'exclusive':
         self.last_spike_allowed_arr = gpuarray.to_gpu(zeros(self.N, dtype=bool))
         self.next_spike_allowed_arr = gpuarray.to_gpu(ones(self.N, dtype=bool))
Example #7
0
    def initialize(self, delta, coincidence_count_algorithm):
        self.algorithm = coincidence_count_algorithm
        self.delta = int(rint(delta / self.dt))

        self.spike_count = zeros(self.N, dtype='int')
        self.coincidences = zeros(self.N, dtype='int')
        self.spiketime_index = self.spikes_offset
        self.last_spike_time = array(rint(
            self.spikes_inline[self.spiketime_index] / self.dt),
                                     dtype=int)
        self.next_spike_time = array(rint(
            self.spikes_inline[self.spiketime_index + 1] / self.dt),
                                     dtype=int)

        # First target spikes (needed for the computation of
        #   the target train firing rates)
        #        self.first_target_spike = zeros(self.N)

        self.last_spike_allowed = ones(self.N, dtype='bool')
        self.next_spike_allowed = ones(self.N, dtype='bool')
Example #8
0
    def initialize_cuda_variables(self):
        """
        Initialize GPU variables to pass to the kernel
        """
        self.spike_count_gpu = gpuarray.to_gpu(zeros(self.N, dtype=int32))
        self.coincidences_gpu = gpuarray.to_gpu(zeros(self.N, dtype=int32))

        if self.algorithm == 'exclusive':
            self.last_spike_allowed_arr = gpuarray.to_gpu(
                zeros(self.N, dtype=bool))
            self.next_spike_allowed_arr = gpuarray.to_gpu(
                ones(self.N, dtype=bool))
Example #9
0
 def update_neurongroup(self, **param_values):
     """
     Inject fitting parameters into the NeuronGroup
     """
     # Sets the parameter values in the NeuronGroup object
     self.group.reinit()
     for param, value in param_values.iteritems():
         self.group.state(param)[:] = kron(value, ones(self.slices)) # kron param_values if slicing
     
     # Reinitializes the model variables
     if self.initial_values is not None:
         for param, value in self.initial_values.iteritems():
             self.group.state(param)[:] = value
Example #10
0
 def initialize_refractory(self, refractory):
     if isinstance(refractory, float):
         refractory = refractory*ones(self.N)
     self.refractory_arr = gpuarray.to_gpu(array(rint(refractory / self.dt), dtype=int32))
     self.next_allowed_spiketime_arr = gpuarray.to_gpu(-ones(self.N, dtype=int32))
Example #11
0
 def transform_traces(self, traces):
     # from standard structure to inline structure
     K, T = traces.shape
     traces_inline = traces.flatten()
     traces_offset = array(kron(arange(K), T*ones(self.subpopsize)), dtype=int)
     return traces_inline, traces_offset
Example #12
0
 def initialize(self,tau_metric):
     self.delay_range =max(self.delays)- min(self.delays)#delay range
     self.min_delay = abs(min(self.delays))#minimum of possible delay
     self.corr_vector=zeros(self.N) 
     self.norm_pop = zeros(self.N) 
     self.norm_target = zeros(self.N) 
     self.nbr_neurons_group = self.N/self.K
     
     eqs="""
     tau:second
     dv/dt=(-v)/tau: volt
     """
     # network to convolve target spikes with the kernel
     self.input_target=SpikeGeneratorGroup(self.K,self.spikes,clock=self.group.clock)
     self.kernel_target=NeuronGroup(self.N,model=eqs,clock=self.group.clock)
     self.C_target = DelayConnection(self.input_target, self.kernel_target, 'v', structure='sparse',  max_delay=self.min_delay)  
     self.kernel_target.tau=tau_metric
     for igroup in xrange(self.K):
         self.C_target.W[igroup,igroup*self.nbr_neurons_group:(1+igroup)*self.nbr_neurons_group] = ones(self.nbr_neurons_group)
         self.C_target.delay[igroup,igroup*self.nbr_neurons_group:(1+igroup)*self.nbr_neurons_group] =  self.min_delay * ones(self.nbr_neurons_group)
         
     # network to convolve population spikes with the kernel
     self.kernel_population=NeuronGroup(self.N,model=eqs,clock=self.group.clock)
     self.C_population = DelayConnection(self.group, self.kernel_population, 'v', structure='sparse',  max_delay=self.delay_range)
     for iN in xrange(self.N):
         self.C_population.delay[iN,iN] = diagflat(self.min_delay + self.delays[iN])
     self.C_population.connect_one_to_one(self.group,self.kernel_population)
     self.kernel_population.tau=tau_metric
     self.spikecount = SpikeCounter(self.group)
     self.contained_objects = [self.kernel_population,self.C_population,self.spikecount,self.input_target,self.C_target,self.kernel_target]