brainpy.math.TimeDelay
brainpy.math.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 (ArrayType) – The initial delay data.
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 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.5
to approximate the delay data att-0.53
.
New in version 2.1.1.
See also
- __init__(delay_target, delay_len, before_t0=None, t0=0.0, dt=None, name=None, interp_method='linear_interp')[source]#
Methods
__init__
(delay_target, delay_len[, ...])cpu
()Move all variable into the CPU device.
cuda
()Move all variables into the GPU device.
load_state_dict
(state_dict[, warn])Copy parameters and buffers from
state_dict
into this module and its descendants.load_states
(filename[, verbose])Load the model states.
nodes
([method, level, include_self])Collect all children nodes.
register_implicit_nodes
(*nodes[, node_cls])register_implicit_vars
(*variables, ...)reset
(delay_target, delay_len[, t0, before_t0])Reset the delay variable.
save_states
(filename[, variables])Save the model states.
state_dict
()Returns a dictionary containing a whole state of the module.
to
(device)Moves all variables into the given device.
tpu
()Move all variables into the TPU device.
train_vars
([method, level, include_self])The shortcut for retrieving all trainable variables.
tree_flatten
()Flattens the object as a PyTree.
tree_unflatten
(aux, dynamic_values)New in version 2.3.1.
unique_name
([name, type_])Get the unique name for this object.
update
(value)vars
([method, level, include_self, ...])Collect all variables in this node and the children nodes.
Attributes
name
Name of the model.