If you simply want to “replay” the exact spike times from one simulation as though it were an input neuron in a new simulation (maybe “option 2” in your most recent message) you can do that with SpikeGeneratorGroup
and you can specify whether that input acts as though from a single neuron, or multiple:
from brain2 import *
import numpy as np
G_output = NeuronGroup(N_output, eqs)
# set up replay input group
input_spike_times_A = [12, 16, 20.2, 26, 50.5]*second
input_spike_times_B = [10, 20, 30]*second
N_input = 2
def spike_times_to_index_array(times, idx):
return np.ones(size(times), dtype=int) * idx
# this concatenation is only necessary if you want to have multiple pre-synaptic neurons replay their spikes in parallel
all_input_spike_times = np.concatenate((input_spike_times_A, input_spike_times_B))
input_neuron_indices = np.concatenate(
(spike_times_to_index_array(input_spike_times_A, 0),
spike_times_to_index_array(input_spike_times_B, 1) ) )
G_replay = SpikeGeneratorGroup(N_input, input_neuron_indices, all_input_spike_times)
# set up output group
N_output = 10
eqs = '''
dv/dt = (I-v)/tau : 1
I : 1
tau : second
'''
#connect
S = Synapses(G_replay, G_output, 'w:1', on_pre='v_post += w')
S.connect() # connect all-to-all
S.w = 1.0 #set synaptic weight
(here's the same code as above, but without the extra complication of multiple neurons being replayed, click to expand)
from brain2 import *
import numpy as np
G_output = NeuronGroup(N_output, eqs)
# set up replay input group
input_spike_times = [12, 16, 20.2, 26, 50.5]*second
N_input = 1
def spike_times_to_index_array(times, idx):
return np.ones(size(times), dtype=int) * idx
input_neuron_indices = spike_times_to_index_array(input_spike_times, 0)
G_replay = SpikeGeneratorGroup(1, input_neuron_indices, input_spike_times)
# set up output group
N_output = 10
eqs = '''
dv/dt = (I-v)/tau : 1
I : 1
tau : second
'''
#connect
S = Synapses(G_replay, G_output, 'w:1', on_pre='v_post += w')
S.connect() # connect all-to-all
S.w = 1.0 #set synaptic weight
note that a big difference from using a PoissonGroup
is that a PoissonGroup
will generate new random spikes every time you call the script, while this SpikeGeneratorGroup
will deliver spikes at exactly the times you specify.
The documentation also gives an example of set_spikes
which can update the spike times for a generator group within a run in case that’s something you need