TimedArray
TimedArray(
rates=None,
geometry=None,
schedule=0.0,
period=-1.0,
name=None,
copied=False,
net_id=0,
)Data structure holding sequential inputs for a rate-coded network.
The input values are stored in the (recordable) attribute r, without any further processing.
By default, the firing rate of this population will iterate over the different values step by step:
inputs = np.array(
[
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
]
)
net = ann.Network()
inp = net.create(ann.TimedArray(rates=inputs))
pop = net.create(10, ann.LeakyIntegrator)
proj = net.connect(inp, pop, 'exc')
proj.one_to_one(1.0)
net.compile()
net.simulate(10.)This creates a population of 10 neurons whose activity will change during the first 10*dt milliseconds of the simulation. After that delay, the last input will be kept (i.e. 1 for the last neuron).
If you want the TimedArray to “loop” over the different input vectors, you can specify a period for the inputs:
inp = net.create(ann.TimedArray(rates=inputs, period=10.))If the period is smaller than the length of the rates, the last inputs will not be set.
If you do not want the inputs to be set at every step, but every 10 ms for example, you can use the schedule argument:
inp = net.create(ann.TimedArray(rates=inputs, schedule=10.))The input [1, 0, 0,…] will stay for 10 ms, then [0, 1, 0, …] for the next 10 ms, etc…
If you need a less regular schedule, you can specify it as a list of times:
inp = ann.TimedArray(rates=inputs, schedule=[10., 20., 50., 60., 100., 110.])The first input is set at t = 10 ms (r = 0.0 in the first 10 ms), the second at t = 20 ms, the third at t = 50 ms, etc.
If you specify less times than in the array of rates, the last ones will be ignored.
Scheduling can be combined with periodic cycling. Note that you can use the reset() method to manually reinitialize the TimedArray, times becoming relative to that call:
ann.simulate(100.) # ten inputs are shown with a schedule of 10 ms
inp.reset()
ann.simulate(100.) # the same ten inputs are presented again.Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| rates | np.ndarray | array of firing rates. The first axis corresponds to time, the others to the desired dimensions of the population. | None |
| geometry | int | tuple | desired dimensions of the population. This argument will be considered if rates is None. | None |
| schedule | float | either a single value or a list of time points where inputs should be set. Default: every timestep. | 0.0 |
| period | float | time when the timed array will be reset and start again, allowing cycling over the inputs. Default: no cycling (-1.). | -1.0 |
Methods
| Name | Description |
|---|---|
| update | Set a new array of inputs. |
update
update(rates, schedule=None, period=None, reset=False)Set a new array of inputs.
The first axis corresponds to time, the others to the desired dimensions of the population. Note, the geometry is set during construction phase of the object.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| schedule | float | either a single value or a list of time points where inputs should be set. Note that this will set reset=True automatically. Default: the initial schedule remains. | None |
| period | float | time when the timed array will be reset and start again, allowing cycling over the inputs. Default: the initial period remains. | None |
| reset | bool | whether to reset the internal timers before updating. If True the simulation will continue with the first elements provided by rates. If False, the simulation will continue with values of the provided rates at the position of the current internal timers. Default: False. Example: Set an input for the next 10 time steps: python inp = ann.TimedArray(rates=inputs_a) # inputs_a shape = (10, N) Simulate for 5 ms (dt = 1 ms, using inputs_a[0] to inputs_a[4]): python ann.simulate(5.) Now either update the TimedArray with new inputs for 10 time steps, without resetting the internal timers (the next input will be inputs_b[5]): python inp.update(rates=inputs_b) # inputs_b shape = (10, N) Or update the TimedArray with new inputs for the next 10 time steps, and reset the internal timers (the next input will be inputs_b[0]): python inp.update(rates=inputs_b, reset=True) # inputs_b shape = (10, N) If the internalt timers are reset, one can also redefine the schedule and period parameters, e.g. providing input for the next 20 ms with a schedule of 2 ms and afterwards cycling over this input: python inp.update(rates=inputs_b, schedule=2., period=20., reset=True) # inputs_b shape = (10, N) |
False |