Neuron models and groups¶
The Equations object¶
-
class
brian.Equations(expr='', level=0, **kwds)¶ Container that stores equations from which models can be created
Initialised as:
Equations(expr[,level=0[,keywords...]])
with arguments:
expr- An expression, which can each be a string representing equations,
an
Equationsobjects, or a list of strings andEquationsobjects. See below for details of the string format. level- Indicates how many levels back in the stack the namespace for string
equations is found, so that e.g.
level=0looks in the namespace of the function where theEquationsobject was created,level=1would look in the namespace of the function that called the function where theEquationsobject was created, etc. Normally you can just leave this out. keywords- Any sequence of keyword pairs
key=valuewhere the stringkeyin the string equations will be replaced withvaluewhich can be either a string, value orNone, in the latter case a unique name will be generated automatically (but it won’t be pretty).
Systems of equations can be defined by passing lists of
Equationsto a newEquationsobject, or by addingEquationsobjects together (the usage is similar to that of a Pythonlist).String equations
String equations can be of any of the following forms:
dx/dt = f : unit(differential equation)x = f : unit(equation)x = y(alias)x : unit(parameter)
Here each of
xandycan be any valid Python variable name,fcan be any valid Python expression, andunitshould be the unit of the correspondingx. You can also include multi-line expressions by appending a\character at the end of each line which is continued on the next line (following the Python standard), or comments by including a#symbol.These forms mean:
- Differential equation
- A differential equation with variable
xwhich has physical unitsunit. The variablexwill become one of the state variables of the model. - Equation
- An equation defining the meaning of
xcan be used for building systems of complicated differential equations. - Alias
- The variable
xbecomes equivalent to the variabley, useful for connecting two separate systems of equations together. - Parameter
- The variable
xwill have physical unitsunitand will be one of the state variables of the model (but will not evolve dynamically, instead it should be set by the user).
Noise
String equations can also use the reserved term
xifor a Gaussian white noise with mean 0 and variance 1.Example usage
eqs=Equations(''' dv/dt=(u-v)/tau : volt u=3*v : volt w=v ''')
Details
For more details, see More on equations in the user manual.
For information on integration methods, and the StateUpdater
class, see Integration.
The NeuronGroup object¶
-
class
brian.NeuronGroup(N, model=None, threshold=None, reset=NoReset(), init=None, refractory=0.0 * second, level=0, clock=None, order=1, implicit=False, unit_checking=True, max_delay=0.0 * second, compile=False, freeze=False, method=None, max_refractory=None)¶ Group of neurons
Initialised with arguments:
N- The number of neurons in the group.
model- An object defining the neuron model. It can be
an
Equationsobject, a string defining anEquationsobject, aStateUpdaterobject, or a list or tuple ofEquationsand strings. threshold=None- A
Thresholdobject, a function, a scalar quantity or a string. Ifthresholdis a function with one argument, it will be converted to aSimpleFunThreshold, otherwise it will be aFunThreshold. Ifthresholdis a scalar, then a constant single valued threshold with that value will be used. In this case, the variable to apply the threshold to will be guessed. If there is only one variable, or if you have a variable named one ofV,Vm,vorvmit will be used. Ifthresholdis a string then the appropriate threshold type will be chosen, for example you could dothreshold='V>10*mV'. The string must be a one line string. reset=None- A
Resetobject, a function, a scalar quantity or a string. If it’s a function, it will be converted to aFunResetobject. If it’s a scalar, then a constant single valued reset with that value will be used. In this case, the variable to apply the reset to will be guessed. If there is only one variable, or if you have a variable named one ofV,Vm,vorvmit will be used. Ifresetis a string it should be a series of expressions which are evaluated for each neuron that is resetting. The series of expressions can be multiline or separated by a semicolon. For example,reset=`Vt+=5*mV; V=Vt'. Statements involvingifconstructions will often not work because the code is automatically vectorised. For such constructions, use a function instead of a string. refractory=0*ms,min_refractory,max_refractory- A refractory period, used in combination with the
resetvalue if it is a scalar. For constant resets only, you can specify refractory as an array of length the number of elements in the group, or as a string, giving the name of a state variable in the group. In the case of these variable refractory periods, you should specifymin_refractory(optional) andmax_refractory(required). level=0- See
Equationsfor details. clock- A clock to use for scheduling this
NeuronGroup, if omitted the default clock will be used. order=1- The order to use for nonlinear differential equation solvers. TODO: more details.
implicit=False- Whether to use an implicit method for solving the differential equations. TODO: more details.
max_delay=0*ms- The maximum allowable delay (larger values use more memory). This doesn’t usually need to be specified because Connections will update it.
compile=False- Whether or not to attempt to compile the differential equation
solvers (into Python code). Typically, for best performance, both
compileandfreezeshould be set toTruefor nonlinear differential equations. freeze=False- If True, parameters are replaced by their values at the time of initialization.
method=None- If not None, the integration method is forced. Possible values are linear, nonlinear, Euler, exponential_Euler (overrides implicit and order keywords).
unit_checking=True- Set to
Falseto bypass unit-checking.
Methods
-
subgroup(N)¶ Returns the next sequential subgroup of
Nneurons. See the section on subgroups below.
-
state(var)¶ Returns the array of values for state variable
var, with length the number of neurons in the group.
-
rest()¶ Sets the neuron state values at rest for their differential equations.
The following usages are also possible for a group
G:G[i:j]- Returns the subgroup of neurons from
itoj. len(G)- Returns the number of neurons in
G. G.x- For any valid Python variable name
xcorresponding to a state variable of the theNeuronGroup, this returns the array of values for the state variablex, as for thestate()method above. WritingG.x = arrforarraTimedArraywill set the values of variable x to bearr(t)at time t. SeeTimedArraySetterfor details.
Subgroups
A subgroup is a view on a group. It isn’t a new group, it’s just a convenient way of referring to a subset of the neurons in an already defined group. The subset has to be a continguous set of neurons. They can be overlapping if defined with the slice notation, or consecutive if defined with the
subgroup()method. Subgroups can themselves be subgrouped. Subgroups can be used in almost all situations exactly as if they were groups, except that they cannot be passed to theNetworkobject.Details
TODO: details of other methods and properties for people wanting to write extensions?
Resets¶
Reset objects are called each network update step to reset specified state variables of neurons that have fired.
-
class
brian.Reset(resetvalue=0.0 * volt, state=0)¶ Resets specified state variable to a fixed value
Initialise as:
R = Reset([resetvalue=0*mvolt[, state=0]])
with arguments:
resetvalue- The value to reset to.
state- The name or number of the state variable to reset.
This will reset all of the neurons that have just spiked. The given state variable of the neuron group will be set to value
resetvalue.
-
class
brian.StringReset(expr, level=0)¶ Reset defined by a string
Initialised with arguments:
expr- The string expression used to reset. This can include
multiple lines or statements separated by a semicolon.
For example,
'V=-70*mV'or'V=-70*mV; Vt+=10*mV'. Some standard functions are provided, see below. level- How many levels up in the calling sequence to look for names in the namespace. Usually 0 for user code.
Standard functions for expressions:
rand()- A uniform random number between 0 and 1.
randn()- A Gaussian random number with mean 0 and standard deviation 1.
For example, these could be used to implement an adaptive model with random reset noise with the following string:
E -= 1*mV V = Vr+rand()*5*mV
-
class
brian.VariableReset(resetvaluestate=1, state=0)¶ Resets specified state variable to the value of another state variable
Initialised with arguments:
resetvaluestate- The state variable which contains the value to reset to.
state- The name or number of the state variable to reset.
This will reset all of the neurons that have just spiked. The given state variable of the neuron group will be set to the value of the state variable
resetvaluestate.
-
class
brian.Refractoriness(resetvalue=0.0 * volt, period=5.0 * msecond, state=0)¶ Holds the state variable at the reset value for a fixed time after a spike.
Initialised with arguments:
resetvalue- The value to reset and hold to.
period- The length of time to hold at the reset value. If using variable refractoriness, this is the maximum period.
state- The name or number of the state variable to reset and hold.
-
class
brian.SimpleCustomRefractoriness(resetfun, period=5.0 * msecond, state=0)¶ Holds the state variable at the custom reset value for a fixed time after a spike.
Initialised as:
SimpleCustomRefractoriness(resetfunc[,period=5*ms[,state=0]])
with arguments:
resetfun- The custom reset function
resetfun(P, spikes)forPaNeuronGroupandspikesa list of neurons that fired spikes. period- The length of time to hold at the reset value.
state- The name or number of the state variable to reset and hold, it is your responsibility to check that this corresponds to the custom reset function.
The assumption is that
resetfun(P, spikes)will reset the state variablestateon the groupPfor the spikes with indicesspikes. The values assigned by the custom reset function are stored by this object, and they are clamped at these values forperiod. This object does not introduce refractoriness for more than the one specified variablestateor for spike indices other than those in the variablespikespassed to the custom reset function.
-
class
brian.CustomRefractoriness(resetfun, period=5.0 * msecond, refracfunc=None)¶ Holds the state variable at the custom reset value for a fixed time after a spike.
Initialised as:
CustomRefractoriness(resetfunc[,period=5*ms[,refracfunc=resetfunc]])
with arguments:
resetfunc- The custom reset function
resetfunc(P, spikes)forPaNeuronGroupandspikesa list of neurons that fired spikes. refracfunc- The custom refractoriness function
refracfunc(P, indices)forPaNeuronGroupandindicesa list of neurons that are in their refractory periods. In some cases, you can choose not to specify this, and it will use the reset function. period- The length of time to hold at the reset value.
-
class
brian.FunReset(resetfun)¶ A reset with a user-defined function.
Initialised as:
FunReset(resetfun)
with argument:
resetfun- A function
f(G,spikes)whereGis theNeuronGroupandspikesis an array of the indexes of the neurons to be reset.
-
class
brian.NoReset¶ Absence of reset mechanism.
Initialised as:
NoReset()
Thresholds¶
A threshold mechanism checks which neurons have fired a spike.
-
class
brian.Threshold(threshold=1.0 * mvolt, state=0)¶ All neurons with a specified state variable above a fixed value fire a spike.
Initialised as:
Threshold([threshold=1*mV[,state=0])
with arguments:
threshold- The value above which a neuron will fire.
state- The state variable which is checked.
Compilation
Note that if the global variable
useweaveis set toTruethen this function will use aC++accelerated version which runs approximately 3x faster.
-
class
brian.StringThreshold(expr, level=0)¶ A threshold specified by a string expression.
Initialised with arguments:
expr- The expression used to test whether a neuron has fired a spike.
Should be a single statement that returns a value. For example,
'V>50*mV'or'V>Vt'. level- How many levels up in the calling sequence to look for names in the namespace. Usually 0 for user code.
-
class
brian.VariableThreshold(threshold_state=1, state=0)¶ Threshold mechanism where one state variable is compared to another.
Initialised as:
VariableThreshold([threshold_state=1[,state=0]])
with arguments:
threshold_state- The state holding the lower bound for spiking.
state- The state that is checked.
If
xis the value of state variablethreshold_stateon neuroniandyis the value of state variablestateon neuronithen neuroniwill fire ify>x.Typically, using this class is more time efficient than writing a custom thresholding operation.
Compilation
Note that if the global variable
useweaveis set toTruethen this function will use aC++accelerated version.
-
class
brian.EmpiricalThreshold(threshold=1.0 * mvolt, refractory=1.0 * msecond, state=0, clock=None)¶ Empirical threshold, e.g. for Hodgkin-Huxley models.
In empirical models such as the Hodgkin-Huxley method, after a spike neurons are not instantaneously reset, but reset themselves as part of the dynamical equations defining their behaviour. This class can be used to model that. It is a simple threshold mechanism that checks e.g.
V>=Vtbut it only does so for neurons that haven’t recently fired (giving the dynamical equations time to reset the values naturally). It should be used in conjunction with theNoResetobject.Initialised as:
EmpiricalThreshold([threshold=1*mV[,refractory=1*ms[,state=0[,clock]]]])
with arguments:
threshold- The lower bound for the state variable to induce a spike.
refractory- The time to wait after a spike before checking for spikes again.
state- The name or number of the state variable to check.
clock- If this object is being used for a
NeuronGroupwhich doesn’t use the default clock, you need to specify its clock here.
-
class
brian.SimpleFunThreshold(thresholdfun, state=0)¶ Threshold mechanism with a user-specified function.
Initialised as:
FunThreshold(thresholdfun[,state=0])
with arguments:
thresholdfun- A function with one argument, the array of values for the specified state variable. For efficiency, this is a numpy array, and there is no unit checking.
state- The name or number of the state variable to pass to the threshold function.
Sample usage:
FunThreshold(lambda V:V>=Vt,state='V')
-
class
brian.FunThreshold(thresholdfun)¶ Threshold mechanism with a user-specified function.
Initialised as:
FunThreshold(thresholdfun)
where
thresholdfunis a function with one argument, the 2d state value array, where each row is an array of values for one state, of length N for N the number of neurons in the group. For efficiency, data are numpy arrays and there is no unit checking.Note: if you only need to consider one state variable, use the
SimpleFunThresholdobject instead.
-
class
brian.NoThreshold¶ No thresholding mechanism.
Initialised as:
NoThreshold()