How to record only certain neurons from a group by SpikeMonitor?

Description of problem

Differently from StateMonitor where the record argument can be boolean or a vector of indices, SpikeMonitor only allows for boolean record values: that is either I record spikes from all my neurons in a given NeuronGroup or none. Is there a simple way to bypass this? This could also be lumped into ‘Features requests’. The reason for this is that when I deal with large networks of neurons which I want to simulate for a long time, 'SpikeMonitor` easily sucks up all my memory resources.

Minimal code to reproduce problem

import numpy as np
from brian2 import *
N = 5000
F = 10*Hz
neu_group = PoissonGroup(N, rates=F)
mon = SpikeMonitor(neurons,record=True)
run(duration=3600*second)

What you have aready tried

The reply should tell me how I can for example select the first K<N neurons out my neu_group or say neurons in idx = np.arange(0,N,K).

Expected output (if relevant)

N/A

Actual output (if relevant)

N/A

Full traceback of error (if relevant)

N/A

You can use subgroups for this, as follows:

import numpy as np
from brian2 import *
N = 5000
K, L = 100, 500
F = 10*Hz
neu_group = PoissonGroup(N, rates=F)
subgroup = neu_group[K:L]
mon = SpikeMonitor(subgroup, record=True)
run(duration=3600*second)

However, note that mon.i records the indices of neurons within the subgroup, rather than within the parent PoissonGroup.
Also, at the moment, subgroups must be contiguous, but this may change soon, see https://github.com/brian-team/brian2/pull/1229

2 Likes

Hi @kernfel. Thanks, much appreciated. I indeed thought of some sort of solution of this kind. I bet “subgrouping” is somewhere bulked deep in the online docs, the contiguity requirement is slightly constraining. One additional remark. What about if I am adding my neu_group by the network.append(neu_group) method? subgroup is automatically added too, isn’t it? So I just have to network.append(mon): could you confirm it please?

I don’t see any reason to add the subgroup (running the minimal example with an explicit Network containing only neu_group and mon works fine), but there may be subtleties I’ve missed - I’m by no means an experienced user. :slight_smile:

Yeah at the moment subgrouping is the only way, and there is a contiguity requirement. The PR that @kernfel linked will eliminate this requirement but it’ll be a little while before it gets merged. @mdepitta maybe submit a ticket on the issue tracker for this feature request? It ought to be supported, indeed.

@dan Thanks. I would follow the advice, if only you kindly teach me how to “submit a ticket” on the “issue tracker” starting from where I can find the latter – that’s a bit of jargon for me at the moment, sorry for the ignorance :slight_smile:

Hi, you shall post the same question in github.com/brian-team/brian2/issues and that will help you to track the work

No need, I added it myself, here: https://github.com/brian-team/brian2/issues/1236

3 Likes

Thanks @Vigneswaran for showing the way… and thanks @dan for paving it! :relieved:

Great, happiness all around :slight_smile: @mdepitta could you mark your question as answered by clicking the “…” under @kernfel’s post and select “:ballot_box_with_check: Solution”? Thanks!

@mstimberg @dan Has there been any progress since this post on the issue of subgrouping? I thought to ask it because I found a situation where this issue is critical: that is, the case of clustered random networks, in standalone mode, and specifying random connections a priori. Take, for example, two clusters made of Brunel-type EI networks. Up to here, there is no problem. You create the NeuronGroups Ex and Ix of the two networks (where x is the network’s ID: 1 or 2 in this example). Then create the relevant Synapses connections passing the vectors of random connections between the different neurons. But when you want to connect the two clusters, you are in trouble: in the case of random inter-cluster connections, in fact, it is unlikely that you can get contiguous neuron indexes in the source and target populations. Take, for example, neuron group E1 in the first cluster. Within the cluster, this neuron group is connected to itself and I1. Now, you want to randomly connect neurons in E1 with those in E2 AND I2. If we limited only to E2 (or I2), chances are we can re-arrange indexes of the neurons in E1 to make those connecting with E2 contiguous. But there is no obvious reason why those same neurons could also be connected to I1. And it seems that the only way to implement this in Brian is creating individual Synapses connections, subgrouping individual neurons, which is not really optimal. Alternatively, I consider the full Ex and Ix groups and specify only the intercluster connections through a separate Synapses group. Any other ideas?

I am confused now, is this is still about recording the neurons with a SpikeMonitor? Can you give a concrete example what you want to do? Above you talk about connecting neurons, but you can connect things in any way you want, there is no requirement for things to be contiguous.

@mstimberg yes indeed. Sorry I got confused. The two things are independent. And the clustering can be achieved as I want. Still, if the issue of contiguity remains, if I aim to record spikes for example from the first n neurons in E1 which project to E2 and also monitor m of E1 that project to I2 when I assign connections randomly.