# Issues with SpikeGeneratorGroup

**URL:** <https://brian.discourse.group/t/issues-with-spikegeneratorgroup/626>\
**Category:** Support\
**Created:** [11 March 2022 14:31 UTC](https://brian.discourse.group/t/issues-with-spikegeneratorgroup/626 "2022-03-11T14:31:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rihana](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/rihana/32/369_2.png) [@Rihana](https://brian.discourse.group/u/Rihana)\
**Post date:** [11 March 2022 14:31 UTC](https://brian.discourse.group/t/issues-with-spikegeneratorgroup/626/1 "2022-03-11T14:31:35Z")

</div>

# Description of problem

I have 3 frequencies for 3 inputs and I’ve generated 3 poisson spikes using PoissonGroup for each of them. an example for the first input is :

> P1 = PoissonGroup(1, rates=rate1)  
> MP = SpikeMonitor(P)  
> run(500\*ms)  
> spikes\_i1 = MP.i  
> spikes\_t 1= MP.t

So I have spikes\_t1, spikes\_t2,spikes\_t3 and also for their indices. because I wanted these generated poisson spikes to remain fixed, I used ‘’’ SGG = SpikeGeneratorGroup(1, spikes\_i1, spikes\_t1) ‘’’ to give the spikes to a NeuronGroup.  
my goal is to give these 3 poisson inputs to my network consecutively during 3 continuous runs.  
Since spikes\_t1, spikes\_t2 and spikes\_t3 have generated over 500 _ms, Since time continues but the spikes time were generated over 500_ms , I don’t know how to set spikes\_time for SpikeGeneratorGroup ( my weights are changing after each input so I want them not to reset). In fact, the only thing should change is spikes\_times for SpikeGeneratorGroup .  
SGG is connected to a NeuronGroup using a synapse.

---

<div class="post-metadata">

**Author:** ![Rihana](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/rihana/32/369_2.png) [@Rihana](https://brian.discourse.group/u/Rihana)\
**Post date:** [15 March 2022 08:30 UTC](https://brian.discourse.group/t/issues-with-spikegeneratorgroup/626/2 "2022-03-15T08:30:41Z")

</div>

I could solve this issue with adding an offset to each poisson input over run simulation.  
this is an example :

> def addSegmentToPoissonSpikes(spikes\_t,addSegment):  
> for index in np.arange(len(spikes\_t)):  
> spikes\_t[index] += addSegment  
> return spikes\_t

> segment\_offset=0_ms  
> for i in np.arange(inputNum):  
> print("spikes\_t\_before "+str(i),poissonInput[i]ms)  
> run(500ms)  
> segment\_offset=segment\_offset+500_ms  
> spikes\_t=addSegmentToPoissonSpikes(poissonSpikeInput[i]\*ms,segment\_offset)  
> SGG.set\_spikes(np.zeros(len(poissonSpikeInput[i])),spikes\_t)  
> print("spikes\_t\_after "+str(i),spikes\_t)

---

<div class="post-metadata">

**Author:** ![Rihana](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/rihana/32/369_2.png) [@Rihana](https://brian.discourse.group/u/Rihana)\
**Post date:** [16 March 2022 06:48 UTC](https://brian.discourse.group/t/issues-with-spikegeneratorgroup/626/3 "2022-03-16T06:48:39Z")

</div>

**Second Issue**

I want to apply a 100 ms interval time between 2 consecutive inputs. (input is fed into my network through SpikeGeneratorGroup: each neuron with one input from SGG)  
neuron equation is :

> dv/dt = (g\_l\*(E\_l-v) + g\_e\*(E\_e-v) +g\_i\*(E\_i-v)+I\_ex\*Input) /C\_m : volt (unless refractory)  
> dg\_e/dt = -g\_e/tau\_e : siemens  
> dg\_i/dt = -g\_i/tau\_i : siemens  
> Input=stimulus(t-segment\_offset):1

> SGG = SpikeGeneratorGroup(1, np.zeros(100), np.zeros(100)\*ms)  
> input\_exc\_syn = Synapses(SGG, exc\_neurons, on\_pre=‘v += w\_input\_e’)  
> input\_inh\_syn = Synapses(SGG, inh\_neurons, on\_pre=‘v += w\_input\_i’)  
> input\_exc\_syn.connect()  
> input\_inh\_syn.connect()

Considering SpikeGeneratorGroup gets only different spike times and I can’t apply 0 for 100 ms continously, over runs, I applied ’

> stimulus = TimedArray(np.zeros(100), dt=1_ms)  
> I\_ex=1_pA  
> SGG.active=False

But after plotting v , I’ve noticed this doesn’t work and seems no 100 ms intervals between inputs. How can I correct it?

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [16 March 2022 10:49 UTC](https://brian.discourse.group/t/issues-with-spikegeneratorgroup/626/4 "2022-03-16T10:49:28Z")

</div>

Hi again. I don’t quite understand what you want to do. The code for the `SpikeGeneratorGroup` SGG above uses indices `[0, 0, ..., 0]` and spike times `[0*ms, 0*ms, ..., 0*ms]`, i.e. it asks for the neuron in the `SpikeGeneratorGroup` to spike 100 times within the first time step – this cannot work, a neuron cannot spike more than once within a time step.  
The `TimedArray` creates a stimulus that is 0 for the 100ms in which it is specified, but it will stay at 0 also afterwards (since `TimedArray` will continue to use its last value if you go beyond its length).  
Do you want to switch `I_ex` off for 100ms and then switch it on for 100ms? Or do you want to have `I_ex` switched on for one time step every 100ms? Please be specific what your input is and what you want to achieve.  
For example, with something like

```nohighlight
stimulus = TimedArray([0, 1, 0], dt=100*ms)

```

the value of `stimulus` will be 0 for the first 100ms, then 1 for the next 100ms, and then 0 for the remaining time.
