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 Equations objects, or a list of strings and Equations objects. 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=0 looks in the namespace of the function where the Equations object was created, level=1 would look in the namespace of the function that called the function where the Equations object was created, etc. Normally you can just leave this out.
keywords
Any sequence of keyword pairs key=value where the string key in the string equations will be replaced with value which can be either a string, value or None, 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 Equations to a new Equations object, or by adding Equations objects together (the usage is similar to that of a Python list).

String equations

String equations can be of any of the following forms:

  1. dx/dt = f : unit (differential equation)
  2. x = f : unit (equation)
  3. x = y (alias)
  4. x : unit (parameter)

Here each of x and y can be any valid Python variable name, f can be any valid Python expression, and unit should be the unit of the corresponding x. 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 x which has physical units unit. The variable x will become one of the state variables of the model.
Equation
An equation defining the meaning of x can be used for building systems of complicated differential equations.
Alias
The variable x becomes equivalent to the variable y, useful for connecting two separate systems of equations together.
Parameter
The variable x will have physical units unit and 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 xi for 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 Equations object, a string defining an Equations object, a StateUpdater object, or a list or tuple of Equations and strings.
threshold=None
A Threshold object, a function, a scalar quantity or a string. If threshold is a function with one argument, it will be converted to a SimpleFunThreshold, otherwise it will be a FunThreshold. If threshold is 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 of V, Vm, v or vm it will be used. If threshold is a string then the appropriate threshold type will be chosen, for example you could do threshold='V>10*mV'. The string must be a one line string.
reset=None
A Reset object, a function, a scalar quantity or a string. If it’s a function, it will be converted to a FunReset object. 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 of V, Vm, v or vm it will be used. If reset is 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 involving if constructions 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 reset value 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 specify min_refractory (optional) and max_refractory (required).
level=0
See Equations for 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 compile and freeze should be set to True for 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 False to bypass unit-checking.

Methods

subgroup(N)

Returns the next sequential subgroup of N neurons. 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 i to j.
len(G)
Returns the number of neurons in G.
G.x
For any valid Python variable name x corresponding to a state variable of the the NeuronGroup, this returns the array of values for the state variable x, as for the state() method above. Writing G.x = arr for arr a TimedArray will set the values of variable x to be arr(t) at time t. See TimedArraySetter for 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 the Network object.

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) for P a NeuronGroup and spikes a 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 variable state on the group P for the spikes with indices spikes. The values assigned by the custom reset function are stored by this object, and they are clamped at these values for period. This object does not introduce refractoriness for more than the one specified variable state or for spike indices other than those in the variable spikes passed 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) for P a NeuronGroup and spikes a list of neurons that fired spikes.
refracfunc
The custom refractoriness function refracfunc(P, indices) for P a NeuronGroup and indices a 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) where G is the NeuronGroup and spikes is 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 useweave is set to True then this function will use a C++ 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 x is the value of state variable threshold_state on neuron i and y is the value of state variable state on neuron i then neuron i will fire if y>x.

Typically, using this class is more time efficient than writing a custom thresholding operation.

Compilation

Note that if the global variable useweave is set to True then this function will use a C++ 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>=Vt but 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 the NoReset object.

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 NeuronGroup which 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 thresholdfun is 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 SimpleFunThreshold object instead.

class brian.NoThreshold

No thresholding mechanism.

Initialised as:

NoThreshold()