pub struct PopulationEncoder { /* private fields */ }Expand description
Encodes a single analog value across a population of neurons
Each neuron in the population is “tuned” to a specific preferred value within the input range. The neuron fires based on a Gaussian-like tuning curve centered on its preferred value. This creates a distributed representation where multiple neurons contribute to encoding a single input value
§Mathematical Model
Uses a Gaussian tuning curve to determine each neuron’s firing rate:
preferred_value[i] = range_min + (i / num_neurons) * (range_max - range_min)
distance = |input - preferred_value[i]|
rate = exp(-distance² / (2 * tuning_width²))
spike if random() < rate§When to Use
- Encoding position or continuous values with distributed representation
- When multiple neurons should contribute to representing a single value
- Creating more robust encoding that doesn’t rely on a single neuron
§Parameters
num_neurons: Number of neurons in the population per input channelinput_range: Tuple of (min, max) input valuestuning_width: Controls how broadly neurons respond (larger = wider spread)
§Examples
use axon_encoder::prelude::*;
let mut enc = PopulationEncoder::try_new(8, (0.0, 1.0), 0.15)?;
// Population encoders take a single scalar in the first channel.
let out = enc.encode(&[0.5]);
assert!(out.spikes.len() <= 8);Implementations§
Source§impl PopulationEncoder
impl PopulationEncoder
Sourcepub fn new(
num_neurons: usize,
input_range: (f32, f32),
tuning_width: f32,
) -> Self
pub fn new( num_neurons: usize, input_range: (f32, f32), tuning_width: f32, ) -> Self
Creates a new PopulationEncoder, panicking if configuration is invalid.
Prefer try_new for typed validation errors.
Sourcepub fn try_new(
num_neurons: usize,
input_range: (f32, f32),
tuning_width: f32,
) -> Result<Self, EncoderError>
pub fn try_new( num_neurons: usize, input_range: (f32, f32), tuning_width: f32, ) -> Result<Self, EncoderError>
Creates a new PopulationEncoder, returning an EncoderError for invalid configuration.
Sourcepub fn num_neurons(&self) -> usize
pub fn num_neurons(&self) -> usize
Returns the number of neurons in the population
Sourcepub fn encode_with_modulators(
&mut self,
input: &[f32],
modulators: &NeuroModulators,
gain_curves: &NeuromodulatorGainCurves,
) -> EncodedOutput
pub fn encode_with_modulators( &mut self, input: &[f32], modulators: &NeuroModulators, gain_curves: &NeuromodulatorGainCurves, ) -> EncodedOutput
Encodes input using neuromodulator-driven gain curves.
Inherent wrapper so callers need not import ModulatedEncoder.
Sourcepub fn encode_step_with_modulators(
&mut self,
input: &[f32],
modulators: &NeuroModulators,
gain_curves: &NeuromodulatorGainCurves,
) -> EncodedOutput
pub fn encode_step_with_modulators( &mut self, input: &[f32], modulators: &NeuroModulators, gain_curves: &NeuromodulatorGainCurves, ) -> EncodedOutput
Step-wise variant of encode_with_modulators.
Trait Implementations§
Source§impl Clone for PopulationEncoder
impl Clone for PopulationEncoder
Source§fn clone(&self) -> PopulationEncoder
fn clone(&self) -> PopulationEncoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more