# Is there a way to monitor the \_average\_ membrane potential of a group of neurons?

**URL:** <https://brian.discourse.group/t/is-there-a-way-to-monitor-the-average-membrane-potential-of-a-group-of-neurons/658>\
**Category:** Science, Projects, and Showcases\
**Created:** [19 April 2022 13:11 UTC](https://brian.discourse.group/t/is-there-a-way-to-monitor-the-average-membrane-potential-of-a-group-of-neurons/658 "2022-04-19T13:11:54Z")\
**Posts on this page:** 2\
**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:** [19 April 2022 13:11 UTC](https://brian.discourse.group/t/is-there-a-way-to-monitor-the-average-membrane-potential-of-a-group-of-neurons/658/1 "2022-04-19T13:11:54Z")

</div>

Hi all! As the title suggests, I am looking into a way to monitor the average membrane potential for a group of neurons. The problem I am facing is the large size of the network; it is very inefficient to record from all neurons and then average in post-processing.

I thought I could add a shared variable Vm to the group equations, but I ran into the problem of how to update it at every time step with the avg value I wanted. Then I thought I would add a network operation that calculates and stores the values separately, using numpy arrays. While this works, I was wondering if anyone knows of a way to make it into a monitor, so as to keep up with the rest of the code’s style.

Thanks for your time!

---

<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:** [20 July 2022 14:59 UTC](https://brian.discourse.group/t/is-there-a-way-to-monitor-the-average-membrane-potential-of-a-group-of-neurons/658/3 "2022-07-20T14:59:05Z")

</div>

Hi @nvar. I’ve only just now realized that I never replied to this post… Although it might no longer be relevant to you, it might be to others, so let me quickly comment here:  
Having a mechanism in monitors that allows you to calculate some “reduction” of multiple values (most importantly sum/average, but something like min/max might be useful as well sometimes), is something that we have discussed for a long time (see e.g. [Code generation syntax for reductions? · Issue #180 · brian-team/brian2 · GitHub](https://github.com/brian-team/brian2/issues/180#issuecomment-66657501)), but unfortunately we never got around implementing anything. The good news, though, is that we have a general mechanism to combine information from several neurons which can be applied here: `Synapses`. While this looks a bit odd, it is also quite powerful (e.g. you can easily calculate the average membrane potential for several sub populations by setting up the connections accordingly). Here’s the general idea:

```python
group = NeuronGroup(..., 'dv/dt = ...', ...)

# Dummy group to store the average membrane potential at every time step
vm_container = NeuronGroup(1, 'average_vm : volt')
# Synapses averaging the membrane potential of all neurons
vm_averager = Synapses(group, average_vm, 'average_vm_post = v_pre/N_pre : volt (summed)')
vm_averager.connect()
# Monitor recording the average membrane potential
vm_mon = StateMonitor(vm_container, 'average_vm', record=0)

```
