I have a variable ‘k’ set equal to time t. In the threshold argument, I want brian to register a spike every x milliseconds, (where x is an integer, 10ms in example below), for which I check k’s remainder with x. However, brian is missing the condition sometimes (attached plot). The StateMonitor on the other hand shows the values of k modulo x as expected, as shown in the output.
from brian2 import * eqs = ''' k = t : second ''' G = NeuronGroup(1, eqs, method = 'euler', threshold = 'k/ms % 10. == 0.') S = StateMonitor(G, variables = True, record = True) M = SpikeMonitor(source = G, variables = 'k') run(120*ms) plot(M.t/ms, M.i, 'k.') show() for i in S.k: if i/ms % 10. == 0.: print(i)
Different values of x (all miss the condition at some point. there seems to be no pattern at which the condition is missed, but the time points at which condition is missed seems to be the same for given x)
running on a different machine, and a colab instance : gives same output.
using ‘exact’ instead of ‘euler’ as method passed in NeuronGroup : gives same output.
no difference on changing to different backends
using a differential equation instead : something like
dk/dt = 10/(1*ms): this works perfectly and as expected. However, the question is still valid, because in theory k is taking the same values.
Spike should be registered every time the condition is true
StateMonitor values whenever same condition is true: (from the for-loop)
0. s 10. ms 20. ms 30. ms 40. ms 50. ms 60. ms 70. ms 80. ms 100. ms 110. ms
(StateMonitor misses 90ms, but that is happening because of rounding errors - 90.0ms is not exactly reached by our variable k. The problem is that 30.0 and 60.0 ms exist as values that k takes but SpikeMonitor isn’t picking them up)
(t = 30, 60 ms are missed)
Sorry, I am not familiar with the internals of the way threshold is implemented, except that it evaluates a boolean. What is the cause of this behavior then? Is it a bug, or a result of the way threshold works? Maybe I’m missing something obvious, but I haven’t been able to solve this. Thank you for your time!