Hi. As I mentioned in my earlier post, using a custom function to deal with this is a bit complicated, using a network_operation
would be easier. You are getting the error message because the model code is translated into Cython code, and you only provide a Python implementation for your function. But again, this complicates things here, since functions are meant to do calculations for a single neuron/synapse, not across neurons as your np.argmax
here. Your second variant cannot run, since code you provide in the strings is not Python code, it is “Brian code” in a special syntax (a subset of Python syntax) that later gets translated into Cython code.
Here’s a simple example (without the inhibition etc.), that shows how you can use a network_operation
to restrict spiking to a single neuron in each time step:
tau_m = 50*ms
neurons = NeuronGroup(2, '''dv/dt = -v/tau_m : 1
is_winner : boolean''',
threshold='v > 1 and is_winner',
reset='v=0')
@network_operation(when='before_thresholds')
def determine_winner():
neurons.is_winner[:] = (neurons.i[:] == np.argmax(neurons.v_[:]))