Exemple #1
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
Exemple #2
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
Exemple #3
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
Exemple #4
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
Exemple #5
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