PopulationEncoder

PopulationEncoder#

class braintools.spike.PopulationEncoder(n_neurons, min_val=0.0, max_val=1.0, sigma=None, max_rate=100.0)#

Encode scalar values using population coding.

Each input value is encoded by a population of neurons with overlapping Gaussian receptive fields whose preferred values (centers) are evenly spaced over [min_val, max_val]. Neuron \(i\) fires with rate \(\text{max_rate} \cdot e^{-(x - c_i)^2 / 2\sigma^2}\) (Hz), i.e. with probability \(\text{rate} \cdot dt\) per time step, so the population response forms a bell curve centered on the input value.

Parameters:
  • n_neurons (int) – Number of neurons in the population.

  • min_val (float) – Minimum input value (preferred value of the first neuron).

  • max_val (float) – Maximum input value (preferred value of the last neuron).

  • sigma (float | None) – Width of the receptive fields (standard deviation). Defaults to the spacing between neighbouring centers, (max_val - min_val) / (n_neurons - 1).

  • max_rate (float) – Peak firing rate of a neuron in Hz.

See also

RateEncoder

One neuron per feature, rate proportional to the input.

Examples

>>> import brainstate
>>> import brainunit as u
>>> import braintools
>>> brainstate.environ.set(dt=1. * u.ms)
>>> brainstate.random.seed(0)
>>> encoder = braintools.spike.PopulationEncoder(n_neurons=11, min_val=0., max_val=1.)
>>> spikes = encoder(0.5, n_time=1000)  # neuron 5 (center 0.5) fires most
>>> spikes.shape
(1000, 11)