# Stdp like rule implementation

**URL:** <https://brian.discourse.group/t/stdp-like-rule-implementation/606>\
**Category:** Science, Projects, and Showcases\
**Created:** [10 February 2022 00:09 UTC](https://brian.discourse.group/t/stdp-like-rule-implementation/606 "2022-02-10T00:09:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![serge25](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@serge25](https://brian.discourse.group/u/serge25)\
**Post date:** [10 February 2022 00:09 UTC](https://brian.discourse.group/t/stdp-like-rule-implementation/606/1 "2022-02-10T00:09:46Z")

</div>

Hello, everybody!

Can anybody help me with understanding of implementation of this stdp-like rule at brian.

```auto
w=Aplus* th[((-deltat-aplus)/tauplus) +1] +bplus* deltat>=0

w=Aminus* th[((deltat-aminus)/tauminus)+1] +bminus* deltat<0

```

---

<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:** [10 February 2022 15:57 UTC](https://brian.discourse.group/t/stdp-like-rule-implementation/606/2 "2022-02-10T15:57:47Z")

</div>

Hi @serge25 Could you give some more information about where these equations come from? They are not in Brian syntax, and I am not quite clear what e.g. `th` means.

---

<div class="post-metadata">

**Author:** ![serge25](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@serge25](https://brian.discourse.group/u/serge25)\
**Post date:** [10 February 2022 17:38 UTC](https://brian.discourse.group/t/stdp-like-rule-implementation/606/3 "2022-02-10T17:38:59Z")

</div>

Hi @mstimberg . This is not from somewhere. It is some kind of reflection about this dependence. Th - hyperbolic tangent.

---

<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:** [14 February 2022 16:56 UTC](https://brian.discourse.group/t/stdp-like-rule-implementation/606/4 "2022-02-14T16:56:37Z")

</div>

> [@serge25](#):
>
> This is not from somewhere.

Even more reason to give details 😉 ! I guess that `deltat` is the time difference between the pre- and post-synaptic spike, but I’m having trouble following the rest: there are two different equations for `w`, do you mean to apply one for `deltat <0` and one for `deltat>=0`? The equations are given as `w = ...`, but I guess you rather mean something like `w += ...` to update the weight?

All that said, the following should be helpful: if the pre- and post-synaptic neurons use refractoriness, then they automatically provide a `lastspike` variable that you can use. If not, you can simply add `lastspike : second` to their equations, and `lastspike = t` to their reset statement. Then you can use something like this in `on_pre`:

```auto
deltat = lastspike_post - t

```

and this in `on_post`:

```auto
deltat = t - lastspike_pre

```

You then can update your weight as a function of `deltat`, the difference between the pre and postsynaptic spike (i.e. negative when post spikes before pre). Note that if you want to add something under a certain condition, rather use an expression like `int(deltat>=0)` instead of `deltat>=0` to not confuse Brian’s/sympy’s equation parsing. Finally, the hyperbolic tangent function is available as `tanh`.

---

<div class="post-metadata">

**Author:** ![serge25](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@serge25](https://brian.discourse.group/u/serge25)\
**Post date:** [14 February 2022 17:58 UTC](https://brian.discourse.group/t/stdp-like-rule-implementation/606/5 "2022-02-14T17:58:25Z")

</div>

@mstimberg , thank you very much for your answer.
