# STDP with pre-synaptic activity updated when spike arrives at postsynaptic neuron

**URL:** <https://brian.discourse.group/t/stdp-with-pre-synaptic-activity-updated-when-spike-arrives-at-postsynaptic-neuron/270>\
**Category:** Support\
**Created:** [29 January 2021 15:17 UTC](https://brian.discourse.group/t/stdp-with-pre-synaptic-activity-updated-when-spike-arrives-at-postsynaptic-neuron/270 "2021-01-29T15:17:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![patmccarthy1](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/patmccarthy1/32/138_2.png) [@patmccarthy1](https://brian.discourse.group/u/patmccarthy1)\
**Post date:** [29 January 2021 15:17 UTC](https://brian.discourse.group/t/stdp-with-pre-synaptic-activity-updated-when-spike-arrives-at-postsynaptic-neuron/270/1 "2021-01-29T15:17:04Z")

</div>

# Description of problem

I am trying to implement a form of STDP where the pre-synaptic activity variable is updated when the spike _arrives at_ the postsynaptic neuron, rather than when the spike is initiated. Up until now, I have been using the standard Brian method of defining what happens at the pre- and post-synaptic neurons using the ‘on\_pre’ and ‘on\_post’ arguments of the ‘Synapse’ class. However, this defines what happens at the time the spike occurs, whereas I need to update the pre-synaptic activity variable at the time that the pre-synaptic neuron spikes _plus_ the synaptic delay.

# Minimal code to reproduce problem

```
    # synapse equations
    eqs = '''
    dw/dt = rho*(((1*siemens-w)*C_pre-w*D_post)/tau_w) : siemens # synaptic weight 
    '''
    # action upon excitatory presynaptic spike 
    on_pre = '''
    C_pre += alpha_C*(1-C_pre)
    '''
    # action upon excitatory postsynaptic spike
    on_post = '''
    g_e_post += lamda*w
    D_post += alpha_D*(1-D_post)
    '''

```

where w is the synaptic weight, rho is the learning rate, C is the pre-synaptic activity, D is the postsynaptic activity and alpha\_C and alpha\_D are scaling factors.

To see the full equations for the type of STDP I am trying to implement, see equations 3.5 - 3.7 in the following paper: [https://www.oftnai.org/articles/Brain\_modelling\_articles/Publications/Vision/20180021.pdf](https://www.oftnai.org/articles/Brain_modelling_articles/Publications/Vision/20180021.pdf)

---

<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:** [29 January 2021 15:47 UTC](https://brian.discourse.group/t/stdp-with-pre-synaptic-activity-updated-when-spike-arrives-at-postsynaptic-neuron/270/2 "2021-01-29T15:47:48Z")

</div>

I might have misunderstood what you want to do, but if you set a [synaptic delay](https://brian2.readthedocs.io/en/stable/user/synapses.html#delays) in Brian, this will delay the execution of the `on_pre` statement and therefore execute it at spike time + delay. I think this is what you want? The `g_e_post += lambda*w` statement on the other hand should be part of `on_pre`, since it is triggered by the pre-synaptic spike as well.

The general approach for these kind of equations:

- everything that is not multiplied by a \delta-function evolves continuously and should therefore go into the equations. From a quick look at your equations, it means that you have a \frac{dC}{dt} equation in the pre-synaptic neuron equations, a \frac{dD}{dt} and a \frac{dg}{dt} equation in the post-synaptic neuron equations, and a \frac{d\Delta g}{dt} (which you call w I think) equation in the synaptic equations.
- each term that is multiplied by \delta(t - \Delta t\_{ij} - t^l\_j) needs to go into `on_pre`, to be executed at pre-synaptic spike time + delay
- each term that is multiplied by \delta(t - t^k\_i) needs to go into `on_post`, to be executed at post-synaptic spike time.

And of course you’ll have to set the delays \Delta t\_{ij} on the synapses.

---

<div class="post-metadata">

**Author:** ![patmccarthy1](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/patmccarthy1/32/138_2.png) [@patmccarthy1](https://brian.discourse.group/u/patmccarthy1)\
**Post date:** [29 January 2021 16:01 UTC](https://brian.discourse.group/t/stdp-with-pre-synaptic-activity-updated-when-spike-arrives-at-postsynaptic-neuron/270/3 "2021-01-29T16:01:56Z")

</div>

Thanks for your quick response! I didn’t realise that when you set a delay, it delays the time at which everything in the ‘on\_pre’ term is executed. What you have described is exactly what I want to do, so I will move the `g_e_post += lambda*w` statement into the ‘on\_pre’ term and everything else should be fine since I have already set delays.

Thanks again,

Patrick
