# Variable updating¶

## Timed Arrays¶

class brian.TimedArray(arr, times=None, clock=None, start=None, dt=None)

An array where each value has an associated time.

Initialisation arguments:

arr
The values of the array. The first index is the time index. Any array shape works in principle, but only 1D/2D arrays are supported (other shapes may work, but may not). The idea is to, have the shapes (T,) or (T, N) for T the number of time steps and N the number of neurons.
times
A 1D array of times whose length should be the same as the first dimension of arr. Usually it is preferable to specify a clock rather than an array of times, but this doesn’t work in the case where the time intervals are not fixed.
clock
Specify the times corresponding to array values by a clock. The t attribute of the clock is the time of the first value in the array, and the time interval is the dt attribute of the clock. If neither times nor clock is specified, a clock will be guessed in the usual way (see Clock).
start, dt
Rather than specifying a clock, you can specify the start time and time interval explicitly. Technically, this is useful because it doesn’t create a Clock object which can lead to ambiguity about which clock is the default. If dt is specified and start is not, start is assumed to be 0.

Note that if the clock, or start time and dt, of the array should be the default clock values, then you should not specify clock, start or dt (see Technical notes below).

Arbitrary slicing of the array is supported, but the clock will only be preserved where the intervals can be guaranteed to be fixed, that is except for the case where lists or numpy arrays are used on the time index.

Timed arrays can be called as if they were a function of time if the array times are based on a clock (but not if the array times are arbitrary as the look up costs would be excessive). If x(t) is called where times[i]<=t<times[i]+dt for some index i then x(t) will have the value x[i]. You can also call x(t) with t a 1D array. If x is 1D then x(t)[i]=x(t[i]), if x is 2D then x(t)[i]=x(t[i])[i].

Has one method:

Technical notes

Note that specifying a new clock, or values of start and dt, will mean that if you use this TimedArray to set the value of a NeuronGroup variable, it will be updated on the schedule of this clock, which can (due to floating point errors) induce some timing problems. This rarely happens, but if an occasional inaccuracy of order dt might conceivably be critical for your simulation, you should use RegularClock objects instead of Clock objects.

class brian.TimedArraySetter(group, var, arr, times=None, clock=None, start=None, dt=None, when='start')

Sets NeuronGroup values with a TimedArray.

At the beginning of each update step, this object will set the values of a given state variable of a group with the value from the array corresponding to the current simulation time.

Initialisation arguments:

group
The NeuronGroup to which the variable belongs.
var
The name or index of the state variable in the group.
arr
The array of values used to set the variable in the group. Can be an array or a TimedArray. If it is an array, you should specify the times or clock arguments, or leave them blank to use the default clock.
times
Times corresponding to the array values, see TimedArray for more details.
clock
The clock for the NetworkOperation. If none is specified, use the group’s clock. If arr is not a TimedArray then this clock will be used to initialise it too.
start, dt
Can specify these instead of a clock (see TimedArray for details).
when
The standard NetworkOperation when keyword, although note that the default value is ‘start’.
brian.set_group_var_by_array(group, var, arr, times=None, clock=None, start=None, dt=None)

Sets NeuronGroup values with a TimedArray.

Creates a TimedArraySetter, see that class for details.

Used for linking one NeuronGroup variable to another.

Sample usage:

G = NeuronGroup(...)
H = NeuronGroup(...)

In this scenario, the variable V in group G will always be updated with the values from variable W in group H. The groups G and H must be the same size (although subgroups can be used if they are not the same size).

Arguments:

source
The group from which values will be taken.
var
The state variable of the source group to take values from.
func
An additional function of one argument to pass the source variable values through, e.g. func=lambda x:clip(x,0,Inf) to half rectify the values.
when
The time in the main Brian loop at which the copy operation is performed, as explained in Network.
clock
The update clock for the copy operation, by default it will use the clock of the target group.