TemporalEncoder#
- class braintools.spike.TemporalEncoder(n_patterns, pattern_length=10, jitter=0.1)#
Encode temporal patterns using synchronized spike timing.
Encodes a sequence of integer symbols. Each symbol occupies a slot of
pattern_lengthtime steps; during that slot the neuron with the symbol’s index fires a fixed pattern of spikes (about 30 % of the slot, shifted by twice the symbol index), with Gaussian jitter. Symbols outside[0, n_patterns)leave their slot silent.- Parameters:
Examples
>>> import brainstate >>> import jax.numpy as jnp >>> import braintools >>> brainstate.random.seed(0) >>> encoder = braintools.spike.TemporalEncoder(n_patterns=3, pattern_length=10, jitter=0.0) >>> sequence = jnp.array([0, 1, 2, 1, 0]) >>> spikes = encoder(sequence) >>> spikes.shape (50, 3) >>> # The active neuron in each slot decodes the symbol. >>> jnp.argmax(spikes.reshape(5, 10, 3).sum(axis=1), axis=1) Array([0, 1, 2, 1, 0], dtype=int32)