How can I simulate my network by diferent stimulus being applied in a consecutive manner with a time delay

Description of problem

I have some different stimulus in my neuron model created by timedArray class.
I want to simulate the network by these stimulus consecutively with a 100-ms delay.
The important point is that I want to use the changed state variables for next stimulus not with primary values.
how can I do it ?

Hi Rihana, I’m still having some trouble understanding exactly what you’re trying to accomplish


are you looking to do something like this?
is the length of the stimulus segment 100ms (i.e. T2-T1 = 100ms) ? or do you want 100ms of no-stimulus in between stimulus segments (i.e. t_gap = 100ms).

Either way, it sounds like one way to achieve this is to call run() multiple times and keep track of a time offset for each stimulus segment:

from brian2 import *
#set up the neuron groups
start_scope()
tau = 10*ms
eqs = '''
dv/dt = (I-v)/tau : 1
I = I_stimulus(t-segment_offset) : 1
'''
G = NeuronGroup(1, eqs)

#set up a TimedArray for each stimulus
stim_duration = 900*ms
t_gap = 100*ms
segment_duration = stim_length + t_gap
stim0 = TimedArray(...)
stim1 = TimedArray(...)
stim2 = TimedArray(...)

all_stimulus_segments = [stim0, stim1, stim2]

#set up a monitor
spike_mon = SpikeMonitor(G)

# Iterate across the segments
segment_offset = 0*ms
for I_stimulus in all_stimulus_segments:
    run(segment_duration)
    segment_offset += segment_duration
    #this segment offset makes sure each stimulus starts from the beginning
    # of its TimedArray, even though the simulation time keeps increasing

Perhaps a simpler way to accomplish this would be to create a single TimedArray that represents all the stimulus segments concatenated together, and then you could just call run(len(all_stimulus_segments) * segment_duration) once to execute the whole simulation

1 Like

Thank you very much for all your support and help.
That is what I meant.