Synapses class¶
(Shortest import: from brian2 import Synapses)
- class brian2.synapses.synapses.Synapses(*args, **kw)[source]¶
Bases:
GroupClass representing synaptic connections.
Creating a new
Synapsesobject does by default not create any synapses, you have to call theSynapses.connectmethod for that.- Parameters
source :
SpikeSourceThe source of spikes, e.g. a
NeuronGroup.target :
Group, optionalThe target of the spikes, typically a
NeuronGroup. If none is given, the same assource()model :
str,Equations, optionalThe model equations for the synapses.
on_pre : str, dict, optional
The code that will be executed after every pre-synaptic spike. Can be either a single (possibly multi-line) string, or a dictionary mapping pathway names to code strings. In the first case, the pathway will be called
preand made available as an attribute of the same name. In the latter case, the given names will be used as the pathway/attribute names. Each pathway has its own code and its own delays.pre : str, dict, optional
Deprecated. Use
on_preinstead.on_post : str, dict, optional
The code that will be executed after every post-synaptic spike. Same conventions as for
on_pre`, the default name for the pathway ispost.post : str, dict, optional
Deprecated. Use
on_postinstead.delay :
Quantity, dict, optionalThe delay for the “pre” pathway (same for all synapses) or a dictionary mapping pathway names to delays. If a delay is specified in this way for a pathway, it is stored as a single scalar value. It can still be changed afterwards, but only to a single scalar value. If you want to have delays that vary across synapses, do not use the keyword argument, but instead set the delays via the attribute of the pathway, e.g.
S.pre.delay = ...(orS.delay = ...as an abbreviation),S.post.delay = ..., etc.on_event : str or dict, optional
Define the events which trigger the pre and post pathways. By default, both pathways are triggered by the
'spike'event, i.e. the event that is triggered by thethresholdcondition in the connected groups.multisynaptic_index : str, optional
The name of a variable (which will be automatically created) that stores the “synapse number”. This number enumerates all synapses between the same source and target so that they can be distinguished. For models where each source-target pair has only a single connection, this number only wastes memory (it would always default to 0), it is therefore not stored by default. Defaults to
None(no variable).namespace : dict, optional
A dictionary mapping identifier names to objects. If not given, the namespace will be filled in at the time of the call of
Network.run, with either the values from thenamespaceargument of theNetwork.runmethod or from the local context, if no such argument is given.dtype :
dtype, dict, optionalThe
numpy.dtypethat will be used to store the values, or a dictionary specifying the type for variable names. If a value is not provided for a variable (or no value is provided at all), the preference setting core.default_float_dtype is used.codeobj_class : class, optional
The
CodeObjectclass to use to run code.dt :
Quantity, optionalThe time step to be used for the update of the state variables. Cannot be combined with the
clockargument.clock :
Clock, optionalThe update clock to be used. If neither a clock, nor the
dtargument is specified, thedefaultclockwill be used.order : int, optional
The priority of of this group for operations occurring at the same time step and in the same scheduling slot. Defaults to 0.
method : str,
StateUpdateMethod, optionalThe numerical integration method to use. If none is given, an appropriate one is automatically determined.
name : str, optional
The name for this object. If none is given, a unique name of the form
synapses,synapses_1, etc. will be automatically chosen.
Attributes
The number of incoming synapses for each neuron in the post-synaptic group.
The number of outgoing synapses for each neuron in the pre-synaptic group.
remember whether connect was called to raise an error if an assignment to a synaptic variable is attempted without a preceding connect.
List of all
SynapticPathwayobjectsSet of
Variableobjects that should be resized when the number of synapses changesList of names of all updaters, e.g.
The presynaptic delay (if a pre-synaptic pathway exists).
The presynaptic delay without unit information (if apre-synaptic pathway exists).
"Events" for all the pathways
Performs numerical integration step
Update the "constant over a time step" subexpressions
"Summed variable" mechanism -- sum over all synapses of a pre-/postsynaptic target
Methods
before_run(run_namespace)Optional method to prepare the object before a run.
check_variable_write(variable)Checks that
Synapses.connecthas been called before setting a synaptic variable.connect([condition, i, j, p, n, ...])Add synapses.
register_variable(variable)Register a
DynamicArrayto be automatically resized when the size of the indices change.unregister_variable(variable)Unregister a
DynamicArrayfrom the automatic resizing mechanism.verify_dependencies(eq, eq_type, deps, ...)Helper function to verify that event-driven equations do not depend on clock-driven equations and the other way round.
Details
- N_incoming_post¶
The number of incoming synapses for each neuron in the post-synaptic group.
- N_outgoing_pre¶
The number of outgoing synapses for each neuron in the pre-synaptic group.
- _connect_called¶
remember whether connect was called to raise an error if an assignment to a synaptic variable is attempted without a preceding connect.
- _pathways¶
List of all
SynapticPathwayobjects
- _registered_variables¶
Set of
Variableobjects that should be resized when the number of synapses changes
- _synaptic_updaters¶
List of names of all updaters, e.g. [‘pre’, ‘post’]
- delay¶
The presynaptic delay (if a pre-synaptic pathway exists).
- delay_¶
The presynaptic delay without unit information (if apre-synaptic pathway exists).
- events¶
“Events” for all the pathways
- state_updater¶
Performs numerical integration step
- subexpression_updater¶
Update the “constant over a time step” subexpressions
- summed_updaters¶
“Summed variable” mechanism – sum over all synapses of a pre-/postsynaptic target
- before_run(run_namespace)[source]¶
Optional method to prepare the object before a run.
Called by
Network.after_runbefore the main simulation loop starts.
- check_variable_write(variable)[source]¶
Checks that
Synapses.connecthas been called before setting a synaptic variable.- Parameters
variable :
VariableThe variable that the user attempts to set.
Raises
TypeErrorIf
Synapses.connecthas not been called yet.
- connect(condition=None, i=None, j=None, p=1.0, n=1, skip_if_invalid=False, namespace=None, level=0)[source]¶
Add synapses.
See Synapses for details.
- Parameters
condition : str, bool, optional
A boolean or string expression that evaluates to a boolean. The expression can depend on indices
iandjand on pre- and post-synaptic variables. Can be combined with argumentsn, andpbut notiorj.i : int, ndarray of int, str, optional
The presynaptic neuron indices It can be an index or array of indices if combined with the
jargument, or it can be a string generator expression.j : int, ndarray of int, str, optional
The postsynaptic neuron indices. It can be an index or array of indices if combined with the
iargument, or it can be a string generator expression.p : float, str, optional
The probability to create
nsynapses wherever theconditionevaluates to true. Cannot be used with generator syntax forj.n : int, str, optional
The number of synapses to create per pre/post connection pair. Defaults to 1.
skip_if_invalid : bool, optional
If set to True, rather than raising an error if you try to create an invalid/out of range pair (i, j) it will just quietly skip those synapses.
namespace : dict-like, optional
A namespace that will be used in addition to the group-specific namespaces (if defined). If not specified, the locals and globals around the run function will be used.
level : int, optional
How deep to go up the stack frame to look for the locals/global (see
namespaceargument).
Examples
>>> from brian2 import * >>> import numpy as np >>> G = NeuronGroup(10, 'dv/dt = -v / tau : 1', threshold='v>1', reset='v=0') >>> S = Synapses(G, G, 'w:1', on_pre='v+=w') >>> S.connect(condition='i != j') # all-to-all but no self-connections >>> S.connect(i=0, j=0) # connect neuron 0 to itself >>> S.connect(i=np.array([1, 2]), j=np.array([2, 1])) # connect 1->2 and 2->1 >>> S.connect() # connect all-to-all >>> S.connect(condition='i != j', p=0.1) # Connect neurons with 10% probability, exclude self-connections >>> S.connect(j='i', n=2) # Connect all neurons to themselves with 2 synapses >>> S.connect(j='k for k in range(i+1)') # Connect neuron i to all j with 0<=j<=i >>> S.connect(j='i+(-1)**k for k in range(2) if i>0 and i<N_pre-1') # connect neuron i to its neighbours if it has both neighbours >>> S.connect(j='k for k in sample(N_post, p=i*1.0/(N_pre-1))') # neuron i connects to j with probability i/(N-1) >>> S.connect(j='k for k in sample(N_post, size=i//2)') # Each neuron connects to i//2 other neurons (chosen randomly)
- register_variable(variable)[source]¶
Register a
DynamicArrayto be automatically resized when the size of the indices change. Called automatically when aSynapticArrayVariablespecifier is created.
- unregister_variable(variable)[source]¶
Unregister a
DynamicArrayfrom the automatic resizing mechanism.
- static verify_dependencies(eq, eq_type, deps, should_not_depend_on, should_not_depend_on_name)[source]¶
Helper function to verify that event-driven equations do not depend on clock-driven equations and the other way round.
- Parameters
eq :
SingleEquationThe equation to verify
eq_type : str
The type of the equation (for the error message)
deps : list
A list of dependencies
should_not_depend_on : list
A list of equations to verify against the dependencies
should_not_depend_on_name : str
The name of the list of equations (for the error message)
Raises
- :exc:
EquationError If the given equation depends on something in the other set of equations.
Tutorials and examples using this¶
Tutorial 1-intro-to-brian-neurons
Tutorial 2-intro-to-brian-synapses
Tutorial 3-intro-to-brian-simulations
Example COBAHH
Example CUBA
Example adaptive_threshold
Example advanced/custom_events
Example advanced/float_32_64_benchmark
Example compartmental/lfp
Example frompapers/Brette_2012/Fig5A
Example frompapers/Brunel_2000
Example frompapers/Brunel_Hakim_1999
Example frompapers/Brunel_Wang_2001
Example frompapers/Diesmann_et_al_1999
Example frompapers/Graupner_Brunel_2012
Example frompapers/Izhikevich_2003
Example frompapers/Izhikevich_2007
Example frompapers/Stimberg_et_al_2018/example_2_gchi_astrocyte
Example frompapers/Stimberg_et_al_2018/example_6_COBA_with_astro
Example frompapers/Sturzl_et_al_2000
Example frompapers/Vogels_et_al_2011
Example standalone/STDP_standalone
Example standalone/cuba_openmp
Example synapses/STDP
Example synapses/continuous_interaction
Example synapses/gapjunctions
Example synapses/jeffress
Example synapses/licklider
Example synapses/nonlinear
Example synapses/spatial_connections
Example synapses/spike_based_homeostasis
Example synapses/state_variables
Example synapses/synapses