TimeDelay#
- class brainpy.math.TimeDelay(delay_target, delay_len, before_t0=None, t0=0.0, dt=None, name=None, interp_method='linear_interp')[source]#
Delay variable which has a fixed delay time length.
For example, we create a delay variable which has a maximum delay length of 1 ms
>>> import brainpy.math as bm >>> delay = bm.TimeDelay(bm.zeros(3), delay_len=1., dt=0.1) >>> delay(-0.5) [-0. -0. -0.]
This function supports multiple dimensions of the tensor. For example,
the one-dimensional delay data
>>> delay = bm.TimeDelay(bm.zeros(3), delay_len=1., dt=0.1, before_t0=lambda t: t) >>> delay(-0.2) [-0.2 -0.2 -0.2]
the two-dimensional delay data
>>> delay = bm.TimeDelay(bm.zeros((3, 2)), delay_len=1., dt=0.1, before_t0=lambda t: t) >>> delay(-0.6) [[-0.6 -0.6] [-0.6 -0.6] [-0.6 -0.6]]
the three-dimensional delay data
>>> delay = bm.TimeDelay(bm.zeros((3, 2, 1)), delay_len=1., dt=0.1, before_t0=lambda t: t) >>> delay(-0.8) [[[-0.8] [-0.8]] [[-0.8] [-0.8]] [[-0.8] [-0.8]]]
- Parameters:
delay_target (
Union[Array,Array]) – The initial delay data.before_t0 (
Union[Callable,Array,Array,float,int]) –The delay data before ::math`t_0`. - when before_t0 is a function, it should receive a time argument t - when before_to is a tensor, it should be a tensor with shape
of \((num_delay, ...)\), where the longest delay data is aranged in the first index.
name (
str) – The delay instance name.interp_method (
str) –The way to deal with the delay at the time which is not integer times of the time step. For exameple, if the time step
dt=0.1, the time delay lengthdelay\_len=1., when users require the delay data att-0.53, we can deal this situation with the following methods:"linear_interp": using linear interpolation to get the delay value at the required time (default)."round": round the time to make it is the integer times of the time step. For the above situation, we will use the time att-0.5to approximate the delay data att-0.53.
Added in version 2.1.1.
See also
- reset(delay_target, delay_len, t0=0.0, before_t0=None)[source]#
Reset the delay variable.
- Parameters:
delay_target (
ArrayType) – The delay target.delay_len (
float,int) – The maximum delay length. The unit is the time.before_t0 (
callable,int,float,ArrayType) –The data before t0. - when
before_t0is a function, it should receive a time argumentt(mirroring the behaviour of
__init__).when
before_t0is a tensor / numerical value, it is broadcast into the delay data beforet0.