LatencyEncoder#
- class braintools.LatencyEncoder(min_val=None, max_val=None, method='log', threshold=0.01, clip=False, tau=Quantity(1., 'ms'), normalize=False, first_spk_time=Quantity(0., 'ms'), epsilon=1e-07)#
Encode the rate input as the spike train using the latency encoding.
Use input features to determine time-to-first spike.
Expected inputs should be between 0 and 1. If not, 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 largerxwill cause the earlier firing time.Example:
>>> import jax >>> a = jax.numpy.array([0.02, 0.5, 1]) >>> encoder = LatencyEncoder(method='linear', normalize=True) >>> encoder(a, n_time=5) Array([[0., 0., 1.], [0., 0., 0.], [0., 1., 0.], [0., 0., 0.], [1., 0., 0.]])
- Parameters:
min_val (
float) – float. The minimal value in the given data x, used to the data normalization.max_val (
float) – float. The maximum value in the given data x, used to the data normalization.method (
str) –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\).
threshold (
float) – float. Input features below the threhold will fire at the final time step unlessclip=Truein which case they will not fire at all, defaults to0.01.clip (
bool) – bool. Option to remove spikes from features that fall below the threshold, defaults toFalse.tau (
float) – float. RC Time constant for LIF model used to calculate firing time, defaults to1.normalize (
bool) – bool. Option to normalize the latency code such that the final spike(s) occur within num_steps, defaults toFalse.epsilon (
float) – float. A tiny positive value to avoid rounding errors when using torch.arange, defaults to1e-7.