Is there a way to monitor the _average_ membrane potential of a group of neurons?

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!

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), 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:

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)')
# Monitor recording the average membrane potential
vm_mon = StateMonitor(vm_container, 'average_vm', record=0)
1 Like