Synapses class¶
(Shortest import: from brian2 import Synapses)
-
class
brian2.synapses.synapses.
Synapses
(*args, **kw)[source]¶ Bases:
brian2.groups.group.Group
Class representing synaptic connections.
Creating a new
Synapses
object does by default not create any synapses, you have to call theSynapses.connect
method for that.- Parameters
source :
SpikeSource
The 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
pre
and 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_pre
instead.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_post
instead.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 thethreshold
condition 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 thenamespace
argument of theNetwork.run
method or from the local context, if no such argument is given.dtype :
dtype
, dict, optionalThe
numpy.dtype
that 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
CodeObject
class 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
clock
argument.clock :
Clock
, optionalThe update clock to be used. If neither a clock, nor the
dt
argument is specified, thedefaultclock
will 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
SynapticPathway
objectsSet of
Variable
objects 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
The group-specific namespace
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.connect
has been called before setting a synaptic variable.connect
(**kwds)Add synapses.
register_variable
(variable)Register a
DynamicArray
to be automatically resized when the size of the indices change.unregister_variable
(variable)Unregister a
DynamicArray
from the automatic resizing mechanism.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
SynapticPathway
objects
-
_registered_variables
¶ Set of
Variable
objects 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
-
namespace
¶ The group-specific namespace
-
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_run
before the main simulation loop starts.
-
check_variable_write
(variable)[source]¶ Checks that
Synapses.connect
has been called before setting a synaptic variable.- Parameters
variable :
Variable
The variable that the user attempts to set.
Raises
TypeError
If
Synapses.connect
has not been called yet.
-
connect
(**kwds)¶ 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
i
andj
and on pre- and post-synaptic variables. Can be combined with argumentsn
, andp
but noti
orj
.i : int, ndarray of int, optional
The presynaptic neuron indices (in the form of an index or an array of indices). Must be combined with
j
argument.j : int, ndarray of int, str, optional
The postsynaptic neuron indices. It can be an index or array of indices if combined with the
i
argument, or it can be a string generator expression.p : float, str, optional
The probability to create
n
synapses wherever thecondition
evaluates 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
namespace
argument).
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)
Tutorials and examples using this¶
Tutorial 3-intro-to-brian-simulations
Tutorial 1-intro-to-brian-neurons
Tutorial 2-intro-to-brian-synapses
Example CUBA
Example adaptive_threshold
Example COBAHH
Example frompapers/Brunel_Wang_2001
Example frompapers/Vogels_et_al_2011
Example frompapers/Diesmann_et_al_1999
Example frompapers/Brunel_Hakim_1999
Example frompapers/Izhikevich_2007
Example frompapers/Sturzl_et_al_2000
Example frompapers/Stimberg_et_al_2018/example_6_COBA_with_astro
Example frompapers/Stimberg_et_al_2018/example_2_gchi_astrocyte
Example frompapers/Brette_2012/Fig5A
Example synapses/jeffress
Example synapses/spatial_connections
Example synapses/STDP
Example synapses/state_variables
Example synapses/synapses
Example synapses/nonlinear
Example synapses/gapjunctions
Example synapses/licklider
Example standalone/STDP_standalone
Example standalone/cuba_openmp
Example advanced/float_32_64_benchmark
Example advanced/custom_events
Example compartmental/lfp