def spike_call(self, spiking_neurons): dt = self.dt t = self.step() * dt spiking_neurons = array(spiking_neurons) if len(spiking_neurons) > 0: if t >= self.onset: self.spike_count[spiking_neurons] += 1 T_spiking = array(rint((t + self.delays[spiking_neurons]) / dt), dtype=int) remaining_neurons = spiking_neurons remaining_T_spiking = T_spiking while True: remaining_indices, = ( remaining_T_spiking > self.next_spike_time[remaining_neurons]).nonzero() if len(remaining_indices): indices = remaining_neurons[remaining_indices] self.spiketime_index[indices] += 1 self.last_spike_time[indices] = self.next_spike_time[ indices] self.next_spike_time[indices] = array(rint( self.spikes_inline[self.spiketime_index[indices] + 1] / dt), dtype=int) if self.algorithm == 'exclusive': self.last_spike_allowed[ indices] = self.next_spike_allowed[indices] self.next_spike_allowed[indices] = True remaining_neurons = remaining_neurons[remaining_indices] remaining_T_spiking = remaining_T_spiking[ remaining_indices] else: break # Updates coincidences count near_last_spike = self.last_spike_time[ spiking_neurons] + self.delta >= T_spiking near_next_spike = self.next_spike_time[ spiking_neurons] - self.delta <= T_spiking last_spike_allowed = self.last_spike_allowed[spiking_neurons] next_spike_allowed = self.next_spike_allowed[spiking_neurons] I = (near_last_spike & last_spike_allowed) | (near_next_spike & next_spike_allowed) if t >= self.onset: self.coincidences[spiking_neurons[I]] += 1 if self.algorithm == 'exclusive': near_both_allowed = (near_last_spike & last_spike_allowed) & ( near_next_spike & next_spike_allowed) self.last_spike_allowed[ spiking_neurons] = last_spike_allowed & -near_last_spike self.next_spike_allowed[spiking_neurons] = ( next_spike_allowed & -near_next_spike) | near_both_allowed
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))
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')
def spike_call(self, spiking_neurons): dt = self.dt t = self.step()*dt spiking_neurons = array(spiking_neurons) if len(spiking_neurons)>0: if t >= self.onset: self.spike_count[spiking_neurons] += 1 T_spiking = array(rint((t + self.delays[spiking_neurons]) / dt), dtype=int) remaining_neurons = spiking_neurons remaining_T_spiking = T_spiking while True: remaining_indices, = (remaining_T_spiking > self.next_spike_time[remaining_neurons]).nonzero() if len(remaining_indices): indices = remaining_neurons[remaining_indices] self.spiketime_index[indices] += 1 self.last_spike_time[indices] = self.next_spike_time[indices] self.next_spike_time[indices] = array(rint(self.spikes_inline[self.spiketime_index[indices] + 1] / dt), dtype=int) if self.algorithm == 'exclusive': self.last_spike_allowed[indices] = self.next_spike_allowed[indices] self.next_spike_allowed[indices] = True remaining_neurons = remaining_neurons[remaining_indices] remaining_T_spiking = remaining_T_spiking[remaining_indices] else: break # Updates coincidences count near_last_spike = self.last_spike_time[spiking_neurons] + self.delta >= T_spiking near_next_spike = self.next_spike_time[spiking_neurons] - self.delta <= T_spiking last_spike_allowed = self.last_spike_allowed[spiking_neurons] next_spike_allowed = self.next_spike_allowed[spiking_neurons] I = (near_last_spike & last_spike_allowed) | (near_next_spike & next_spike_allowed) if t >= self.onset: self.coincidences[spiking_neurons[I]] += 1 if self.algorithm == 'exclusive': near_both_allowed = (near_last_spike & last_spike_allowed) & (near_next_spike & next_spike_allowed) self.last_spike_allowed[spiking_neurons] = last_spike_allowed & -near_last_spike self.next_spike_allowed[spiking_neurons] = (next_spike_allowed & -near_next_spike) | near_both_allowed
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')
def initialize_kernel_arguments(self): self.kernel_func_args = [ self.statevars_arr, self.I, self.I_offset, self.spikedelay_arr, self.refractory_arr, self.next_allowed_spiketime_arr ] self.kernel_func_args += self.criterion.get_kernel_arguments() if self.criterion.type == 'spikes': self.kernel_func_args += [self.spiketimes, self.spiketime_indices] if self.criterion.type == 'traces': self.kernel_func_args += [self.traces, self.traces_offset] if self.statemonitor_var is not None: self.kernel_func_args += [ self.statemonitor_values, self.statemonitor_offsets ] self.kernel_func_args += [int32(rint(self.onset / self.dt))]
def initialize_kernel_arguments(self): self.kernel_func_args = [self.statevars_arr, self.I, self.I_offset, self.spikedelay_arr, self.refractory_arr, self.next_allowed_spiketime_arr] self.kernel_func_args += self.criterion.get_kernel_arguments() if self.criterion.type == 'spikes': self.kernel_func_args += [self.spiketimes, self.spiketime_indices] if self.criterion.type == 'traces': self.kernel_func_args += [self.traces, self.traces_offset] if self.statemonitor_var is not None: self.kernel_func_args += [self.statemonitor_values, self.statemonitor_offsets] self.kernel_func_args += [int32(rint(self.onset / self.dt))]
def initialize_delays(self, spikedelays): self.spikedelay_arr = gpuarray.to_gpu( array(rint(spikedelays / self.dt), dtype=int32))
def initialize_spikes(self, spiketimes, spiketimes_indices): self.spiketimes = gpuarray.to_gpu( array(rint(spiketimes / self.dt), dtype=int32)) self.spiketime_indices = gpuarray.to_gpu( array(spiketimes_indices, dtype=int32))
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))
def initialize_delays(self, spikedelays): self.spikedelay_arr = gpuarray.to_gpu(array(rint(spikedelays / self.dt), dtype=int32))
def initialize_spikes(self, spiketimes, spiketimes_indices): self.spiketimes = gpuarray.to_gpu(array(rint(spiketimes / self.dt), dtype=int32)) self.spiketime_indices = gpuarray.to_gpu(array(spiketimes_indices, dtype=int32))