# From QIF equations to a working Brian2 implementation

**URL:** <https://brian.discourse.group/t/from-qif-equations-to-a-working-brian2-implementation/614>\
**Category:** Science, Projects, and Showcases\
**Created:** [24 February 2022 16:13 UTC](https://brian.discourse.group/t/from-qif-equations-to-a-working-brian2-implementation/614 "2022-02-24T16:13:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvar](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@nvar](https://brian.discourse.group/u/nvar)\
**Post date:** [24 February 2022 16:13 UTC](https://brian.discourse.group/t/from-qif-equations-to-a-working-brian2-implementation/614/1 "2022-02-24T16:13:29Z")

</div>

Hello everyone! I started reproducing [this model](https://www.frontiersin.org/articles/10.3389/fncom.2020.00047/full) using Brian2. I am using the QIF equations that they have quoted in the figure below:  
 ![image](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/e53445d692cc1056034fcfec3f9b0aab9089474e.png)

The details, including the parameter selection, are posted in the paper, but the values are not as important for this post as the actual implementation (which is an elegant way of saying that I struggled to make a complete table and eventually gave up).

My questions are as follows:

1. How would you implement the neurons? The QIF equations in the provided examples are different and with a different set of variables. Also, using `Vm**2` gives back units in voltage squared (expected).
2. The refractory period is set in the paper as `2/Vk` where `Vk` is the voltage of the neuron right before the spike. How would you write something like that? I tried using `refractory='2/Vm'` but it is obviously not working.
3. Lastly, how would you write the synaptic equations and the `on_pre` statement? `J_ln` is the weight to add/subtract to the membrane voltage, like in the simple LIF examples.

Thanks everyone! Looking forward to reading your ideas!

---

<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:** [9 March 2022 15:05 UTC](https://brian.discourse.group/t/from-qif-equations-to-a-working-brian2-implementation/614/2 "2022-03-09T15:05:56Z")

</div>

Hi @nvar. This is a very abstract model that is convenient for analytical results, but not so much for simulation. For example, the membrane potential is supposed to be reset to -∞, and a spike happens when it goes to +∞… From a quick look at the [paper they cite](https://doi.org/10.1103/PhysRevX.5.021028), it seems that as if for actual simulations they use values of ±100 instead of ∞. The “refractory period” is the time it takes from 100 to ∞ and from -∞ to -100, which apparently is 2/Vk “time units”. I discussed abstract equations that do not have actual time quantities in seconds in this post: [Coupled Van der Pol oscillators - #2 by mstimberg](https://brian.discourse.group/t/coupled-van-der-pol-oscillators/230/2)  
The same applies here. In models like this, the membrane potential would not be in volt, but just a dimensionless quantity – a number of Brian examples use this approach as well: [Example: non\_reliability — Brian 2 2.5.0.3 documentation](https://brian2.readthedocs.io/en/stable/examples/non_reliability.html) Having the value squared is not a problem then.  
Regarding the refractoriness, this is also expressed relative to some time unit. In principle there’d be ways to make this dependent on the exact value of the membrane potential when it crossed the threshold, but I guess just using the value of the threshold should be good enough (I think the 2/Vk kind of assumes this, in fact).

The `on_pre` statement is the most straightforward: this is actually the same as in the simple LIF examples, each spike makes the membrane potential jump up by the given amount. There is an additional normalization term, but you could simply include this in the weight.

Hope that helps a bit!

---

<div class="post-metadata">

**Author:** ![nvar](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@nvar](https://brian.discourse.group/u/nvar)\
**Post date:** [10 March 2022 09:10 UTC](https://brian.discourse.group/t/from-qif-equations-to-a-working-brian2-implementation/614/3 "2022-03-10T09:10:11Z")

</div>

Yes, it helps quite a lot, thank you for your reply and the references, on point as always!
