For a single neuron the number of synapses activated at the moment

Description of problem

Hi, I have a question, if I write N_incoming in on_pre, it means the number of synapses received by this neuron, right? If N_incoming=10, but there are only 3 synapses firing at this moment, and I want to call the number of synapses firing at this moment in on_pre, is there a function I can use?

That is, I want to determine the input of different magnitudes depending on the total number of synaptic activations that a single neuron receives

Hi. Yes, N_incoming is the total number of synapses (which can be useful to normalize inputs in networks with random connectivity), not the number of received spikes during that time step. Each synapse executes the on_pre statement independently, so there is no variable that captures the total number of spikes arriving at a neuron during a time step. From a modelling standpoint, I find this also a bit problematic since it depends on the simulation time step – if you are simulating with a finer time step, you will get fewer spikes in each time step.
But in general it is possible to have and use this information, but you need to put several pieces together. Here’s a rough idea how this could work:

source = NeuronGroup(...)
target = NeuronGroup(..., '''
                          ...
                          incoming_spikes : integer
                          ''', ...)
synapses = Synapses(source, target, ...,
                    on_pre='incoming_spikes_post += 1')      
target.run_regularly('''v += int(incoming_spikes > 3)*0.1
                        incoming_spikes = 0''', when='after_synapses')

The idea is that the only action of the synapses is to update a “number of spikes during this time step” counter in the target cell. The target cell itself then acts based on this information, in the above example it increases its v variable by 0.1 if more than 3 spikes arrived, and does nothing otherwise. You’d replace this by whatever you want to do with this information. Finally, we need to make sure that the counter is reset to 0 for the next time step.

Hope that helps, best
Marcel

Hi Marcel, thanks for your reply.

It looks like a great way to do it. But I have one more question, what does after_synapses mean here, it reports an error when running to this code:

incoming_spikes = 0''', when='after_synapses')

An error occurred when preparing an object. (See above for original error message and traceback.)

after_synapses means that this run_regularly operation should be run after the synaptic updates, i.e. after the on_pre statements. See Running a simulation — Brian 2 2.5.0.1 documentation for more details.
What error do you get, can you post the full error message?

WARNING    Cannot use Cython, a test compilation failed: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ (DistutilsPlatformError) [brian2.codegen.runtime.cython_rt.cython_rt.failed_compile_test]
INFO       Cannot use compiled code, falling back to the numpy code generation target. Note that this will likely be slower than using compiled code. Set the code generation to numpy manually to avoid this message:
prefs.codegen.target = "numpy" [brian2.devices.device.codegen_fallback]
ERROR      Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at <http://brian.discourse.group/>, or to the issue tracker at <https://github.com/brian-team/brian2/issues>. Please include this file with debug information in your report: C:\Users\ADMINI~1\AppData\Local\Temp\brian_debug_5kbgoqf9.log  Additionally, you can also include a copy of the script that was run, available at: C:\Users\ADMINI~1\AppData\Local\Temp\brian_script_4o_qvvt_.py You can also include a copy of the redirected std stream outputs, available at C:\Users\ADMINI~1\AppData\Local\Temp\brian_stdout_tn2txiom.log and C:\Users\ADMINI~1\AppData\Local\Temp\brian_stderr_tt_5xzh5.log Thanks! [brian2]
Traceback (most recent call last):
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\core\network.py", line 897, in before_run
    obj.before_run(run_namespace)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\groups\group.py", line 1143, in before_run
    self.create_code_objects(run_namespace)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\groups\group.py", line 1136, in create_code_objects
    code_object = self.create_default_code_object(run_namespace)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\groups\group.py", line 1129, in create_default_code_object
    codeobj_class=self.codeobj_class
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\codegen\codeobject.py", line 396, in create_runner_codeobj
    check_units_statements(c, variables)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\equations\unitcheck.py", line 99, in check_units_statements
    expr_unit = parse_expression_dimensions(expr, variables)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\parsing\expressions.py", line 375, in parse_expression_dimensions
    raise DimensionMismatchError(error_msg)
brian2.units.fundamentalunits.DimensionMismatchError: Expression "g_ampa + int(incoming_spikes > 3) * 0.1" uses inconsistent units ("g_ampa" has unit S; "int(incoming_spikes > 3) * 0.1" has unit 1)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/brian2_demo.py", line 91, in <module>
    run(1*second)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\units\fundamentalunits.py", line 2434, in new_f
    result = f(*args, **kwds)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\core\magic.py", line 374, in run
    namespace=namespace, profile=profile, level=2+level)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\core\magic.py", line 232, in run
    namespace=namespace, profile=profile, level=level+1)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\core\base.py", line 278, in device_override_decorated_function
    return func(*args, **kwds)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\units\fundamentalunits.py", line 2434, in new_f
    result = f(*args, **kwds)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\core\network.py", line 1008, in run
    self.before_run(namespace)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\core\base.py", line 278, in device_override_decorated_function
    return func(*args, **kwds)
  File "F:\Anaconda3\envs\mybrain\lib\site-packages\brian2\core\network.py", line 899, in before_run
    raise BrianObjectException("An error occurred when preparing an object.", obj) from ex
brian2.core.base.BrianObjectException: Error encountered with object named "synapses_run_regularly".
Object was created here (most recent call only, full details in debug log):
  File "C:/Users/Administrator/Desktop/brian2_demo.py", line 53, in <module>
    incoming_spikes = 0''', when='after_synapses')

An error occurred when preparing an object. (See above for original error message and traceback.)

Process finished with exit code 1

It looks like the problem is with the run()

to me it looks like

Expression "g_ampa + int(incoming_spikes > 3) * 0.1" uses inconsistent units ("g_ampa" has unit S; "int(incoming_spikes > 3) * 0.1" has unit 1)

might be the root cause.changing to

g_ampa + int(incoming_spikes > 3) * 0.1 * S

might fix it, but make sure that corresponds to the scale you want to use

1 Like

yea :joy:, I made a stupid mistake… Thanks for all your help! :smiley:

2 Likes