Skip to main content

ModulatedEncoder

Trait ModulatedEncoder 

Source
pub trait ModulatedEncoder: Encoder {
    // Required method
    fn encode_with_gains(
        &mut self,
        input: &[f32],
        gains: EncodingGains,
    ) -> EncodedOutput;

    // Provided methods
    fn encode_step_with_gains(
        &mut self,
        input: &[f32],
        gains: EncodingGains,
    ) -> EncodedOutput { ... }
    fn encode_with_modulators(
        &mut self,
        input: &[f32],
        modulators: &NeuroModulators,
        gain_curves: &NeuromodulatorGainCurves,
    ) -> EncodedOutput { ... }
    fn encode_step_with_modulators(
        &mut self,
        input: &[f32],
        modulators: &NeuroModulators,
        gain_curves: &NeuromodulatorGainCurves,
    ) -> EncodedOutput { ... }
}
Expand description

Encoders that can apply neuromodulator-driven gain curves.

Object-safe so callers can use &mut dyn ModulatedEncoder when the concrete encoder type is not known at compile time. Implementations map the relevant component of EncodingGains to encoder-specific scaling; public modulator helpers are provided once here.

Concrete encoders also keep inherent encode_with_modulators / encode_step_with_modulators wrappers so existing call sites need not import this trait.

§Examples

Prefer the streaming path for doctests: batch encode_with_modulators is stochastic, while encode_step_with_modulators on rate encoders is deterministic.

use axon_encoder::prelude::*;
let mut enc = RateEncoder::try_new(0.0, 100.0, (0.0, 1.0), 0.01)?;
let mods = NeuroModulators {
    dopamine: 1.0,
    ..Default::default()
};
let curves = NeuromodulatorGainCurves {
    dopamine: ModulatorGainCurves {
        firing_rate: Some(GainCurve::new((0.0, 1.0), (1.0, 2.0))),
        ..Default::default()
    },
    ..Default::default()
};
// Accumulates rate_hz * dt; at unit input with elevated gain, a spike fires soon.
let mut saw_spike = false;
for _ in 0..20 {
    if !enc
        .encode_step_with_modulators(&[1.0], &mods, &curves)
        .spikes
        .is_empty()
    {
        saw_spike = true;
        break;
    }
}
assert!(saw_spike);

Required Methods§

Source

fn encode_with_gains( &mut self, input: &[f32], gains: EncodingGains, ) -> EncodedOutput

Encodes input using already evaluated encoding gains.

Implementations must sanitize gains (or the component they use) before applying them.

Provided Methods§

Source

fn encode_step_with_gains( &mut self, input: &[f32], gains: EncodingGains, ) -> EncodedOutput

Encodes one streaming step using already evaluated encoding gains.

Stateful encoders should override this when streaming requires distinct state handling from the batch path.

Source

fn encode_with_modulators( &mut self, input: &[f32], modulators: &NeuroModulators, gain_curves: &NeuromodulatorGainCurves, ) -> EncodedOutput

Encodes input using neuromodulator-driven gain curves.

Source

fn encode_step_with_modulators( &mut self, input: &[f32], modulators: &NeuroModulators, gain_curves: &NeuromodulatorGainCurves, ) -> EncodedOutput

Encodes one streaming step using neuromodulator-driven gain curves.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§