# Neuron reset after spike event and synaptic update

**URL:** <https://brian.discourse.group/t/neuron-reset-after-spike-event-and-synaptic-update/751>\
**Category:** Support\
**Created:** [22 July 2022 14:56 UTC](https://brian.discourse.group/t/neuron-reset-after-spike-event-and-synaptic-update/751 "2022-07-22T14:56:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rth](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/rth/32/16_2.png) [@rth](https://brian.discourse.group/u/rth)\
**Post date:** [22 July 2022 14:56 UTC](https://brian.discourse.group/t/neuron-reset-after-spike-event-and-synaptic-update/751/1 "2022-07-22T14:56:34Z")

</div>

Hi everyone,

## General description

I’m playing a with minimal [triple-STDP learning rule](https://pubmed.ncbi.nlm.nih.gov/16988038/).  
For each postsynaptic and presynaptic neuron, there are low-pass filters of spikes, which contribute to the change of synaptic plasticity.

\begin{array}{rl} r\_1' &= -r\_1/\tau\_{+} + S\_{pre} \\ o\_1' &= -o\_1/\tau\_{1-} + S\_{post} \\ o\_2' &= -o\_2/\tau\_{2+} + S\_{post} \\ w' &= r\_1(t) o\_2(t-\epsilon)A^{+}S\_{post}-o\_1(t)A^{-}S\_{pre} \end{array}

where S\_{pre} and S\_{post} are presynaptic and postsynaptic firing rates.  
The small constant \epsilon is added to indicate that synaptic weight w is updated **before** update o\_2.

### 1. Looks like the most efficient implementation

The most efficient way is to implement r\_1, o\_1, and o\_2 equations on the neuron side:

```auto
equ ="""
dv/dt = ....
dr1/dt = -r1/tau1p : 1
do1/dt = -o1/tau1m : 1
do2/dt = -o2/tau2p : 1
"""
npop = NeuronGroup(... equ, reset='v=vres; r1+=1; o1+=1; o2+=1' ....)

```

and then use these variables in synaptic equations.

```auto
s = Synapses( 'w:1', 
    on_pre='w = w-o1_post*Am',
    on_post='w = w+r1_pre*o2_post*Ap', ....)

```

But it wasn’t clear to me whether the neuron reset will be done after the synaptic update or not.

### 2.Very slow implementation but with the persistent result

I fixed this by moving equations for r\_1, o\_1, and o\_2, on the synaptic side and updating all variables after the synaptic weight update.

```auto
s = Synapses( """
    w : 1 
    dr1/dt = -r1/tau1p : 1 (event-driven)
    do1/dt = -o1/tau1m : 1 (event-driven)
    do2/dt = -o2/tau2p : 1 (event-driven)
    """, 
    on_pre="""
         w = w-o1_post*Am
         r1+= 1""",
    on_post="""
         w = w+r1_pre*o2_post*Ap
         o1+=1
         o2+=1""", ....)

```

However, this implementation is _VERY_ slow because instead of a few thousand differential equations, I got a few million.

### Finally question

Is there any way to ask Brian to do

1. Update all neurons
2. Trigger all events
3. update all synapses
4. reset all neurons.

---

<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:** [22 July 2022 15:33 UTC](https://brian.discourse.group/t/neuron-reset-after-spike-event-and-synaptic-update/751/2 "2022-07-22T15:33:16Z")

</div>

The default schedule is `['start', 'groups', 'thresholds', 'synapses', 'resets', 'end']`, where `'groups'` refers to the update of variables defined by differential equations, and `'synapses'` refers to the `on_pre` and `on_post` statements. So e.g. `on_pre` will be executed before the `reset`. You can verify this with [`scheduling_summary`](https://brian2.readthedocs.io/en/stable/reference/brian2.core.network.scheduling_summary.html). If you need to change this, you can either change the global schedule, or move individual objects around. For example, `s.pre.when = 'after_resets'` would move the `on_pre` execution to the slot following the `reset`.

> [@rth](#):
>
> Is there any way to ask Brian to do
> 
> 1. Update all neurons
> 2. Trigger all events
> 3. update all synapses
> 4. reset all neurons.

I’m not quite sure I understand – you mean without running a simulation? In principle, you could trigger the individual `code_objects` responsible for doing the tasks, but I’m not sure whether that’s what you have in mind?

---

<div class="post-metadata">

**Author:** ![rth](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/rth/32/16_2.png) [@rth](https://brian.discourse.group/u/rth)\
**Post date:** [22 July 2022 15:35 UTC](https://brian.discourse.group/t/neuron-reset-after-spike-event-and-synaptic-update/751/3 "2022-07-22T15:35:47Z")

</div>

Thank you, @mstimberg. It’s much clearer now.
