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,

  1. 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]
  1. 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]]
  1. 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)
  • delay_target (ArrayType) – The initial delay data.

  • t0 (float, int) – The zero time.

  • delay_len (float, int) – The maximum delay length.

  • dt (float, int) – The time precesion.

  • before_t0 (callable, bm.ndarray, jnp.ndarray, 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 length delay\_len=1., when users require the delay data at t-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 at t-0.5 to approximate the delay data at t-0.53.

    New in version 2.1.1.

See also


reset(delay_target, delay_len, t0=0.0, before_t0=None)[source]#

Reset the delay variable.

  • delay_target (ArrayType) – The delay target.

  • delay_len (float, int) – The maximum delay length. The unit is the time.

  • t0 (int, float) – The zero time.

  • before_t0 (int, float, ArrayType) – The data before t0.