brainpy.encoding.LatencyEncoder#
- class brainpy.encoding.LatencyEncoder(min_val, max_val, num_period, method='linear')[source]#
Encode the rate input as the spike train.
The latency encoder will encode
x
(normalized into[0, 1]
according to \(x_{\text{normalize}} = \frac{x-\text{min_val}}{\text{max_val} - \text{min_val}}\)) to spikes whose firing time is \(0 \le t_f \le \text{num_period}-1\). A largerx
will cause the earlier firing time.- Parameters:
min_val (float) – The minimal value in the given data x, used to the data normalization.
max_val (float) – The maximum value in the given data x, used to the data normalization.
num_period (int) – The periodic firing time step.
method (str) –
How to convert intensity to firing time. Currently, we support linear or log.
If
method='linear'
, the firing rate is calculated as \(t_f(x) = (\text{num_period} - 1)(1 - x)\).If
method='log'
, the firing rate is calculated as \(t_f(x) = (\text{num_period} - 1) - ln(\alpha * x + 1)\), where \(\alpha\) satisfies \(t_f(1) = \text{num_period} - 1\).
Methods
__init__
(min_val, max_val, num_period[, method])cpu
()Move all variable into the CPU device.
cuda
()Move all variables into the GPU device.
load_state_dict
(state_dict[, warn, compatible])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[, var_cls])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)Unflatten the data to construct an object of this class.
unique_name
([name, type_])Get the unique name for this object.
vars
([method, level, include_self, ...])Collect all variables in this node and the children nodes.
Attributes
name
Name of the model.