pub struct DeltaEncoder { /* private fields */ }Expand description
A simple delta-based encoder.
Fires a spike when the absolute difference between the current input and the last encoded value exceeds a threshold. This is useful for event-based encoding where only changes in the input signal are relevant.
§Mathematical Model
delta = |current_value - last_value|
spike if delta > threshold§When to Use
- Event-based encoding where changes are more important than absolute values
- Sensor data where baseline can drift but changes are meaningful
- Reducing power consumption by only encoding when changes occur
§Parameters
threshold: Minimum change required to trigger a spikenum_channels: Number of input channels to track
§Examples
use axon_encoder::prelude::*;
let mut enc = DeltaEncoder::try_new(0.1, 2)?;
// Baseline starts at zeros; last_values update only when a spike fires.
// A jump of 0.5 from 0 exceeds threshold 0.1 on channel 0.
let out = enc.encode(&[0.5, 0.0]);
assert!(!out.spikes.is_empty());Implementations§
Source§impl DeltaEncoder
impl DeltaEncoder
Sourcepub fn new(threshold: f32, num_channels: usize) -> Self
pub fn new(threshold: f32, num_channels: usize) -> Self
Creates a new DeltaEncoder, panicking if configuration is invalid.
Prefer try_new for typed validation errors.
Sourcepub fn try_new(
threshold: f32,
num_channels: usize,
) -> Result<Self, EncoderError>
pub fn try_new( threshold: f32, num_channels: usize, ) -> Result<Self, EncoderError>
Creates a new DeltaEncoder, returning an EncoderError for invalid configuration.
threshold == 0.0 is valid and means any nonzero change fires a spike
(delta > 0).
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 DeltaEncoder
impl Clone for DeltaEncoder
Source§fn clone(&self) -> DeltaEncoder
fn clone(&self) -> DeltaEncoder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DeltaEncoder
impl Debug for DeltaEncoder
Source§impl Encoder for DeltaEncoder
impl Encoder for DeltaEncoder
Source§fn encode(&mut self, input: &[f32]) -> EncodedOutput
fn encode(&mut self, input: &[f32]) -> EncodedOutput
Encodes a slice of analog values into spike events (batch mode).
Source§fn encode_step(&mut self, input: &[f32]) -> EncodedOutput
fn encode_step(&mut self, input: &[f32]) -> EncodedOutput
Encodes a single step incrementally (streaming mode). Read more
Source§impl ModulatedEncoder for DeltaEncoder
impl ModulatedEncoder for DeltaEncoder
Source§fn encode_with_gains(
&mut self,
input: &[f32],
gains: EncodingGains,
) -> EncodedOutput
fn encode_with_gains( &mut self, input: &[f32], gains: EncodingGains, ) -> EncodedOutput
Encodes input using already evaluated encoding gains. Read more
Source§fn encode_step_with_gains(
&mut self,
input: &[f32],
gains: EncodingGains,
) -> EncodedOutput
fn encode_step_with_gains( &mut self, input: &[f32], gains: EncodingGains, ) -> EncodedOutput
Encodes one streaming step using already evaluated encoding gains. Read more
Source§fn encode_with_modulators(
&mut self,
input: &[f32],
modulators: &NeuroModulators,
gain_curves: &NeuromodulatorGainCurves,
) -> EncodedOutput
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
fn encode_step_with_modulators( &mut self, input: &[f32], modulators: &NeuroModulators, gain_curves: &NeuromodulatorGainCurves, ) -> EncodedOutput
Encodes one streaming step using neuromodulator-driven gain curves.
Source§impl PartialEq for DeltaEncoder
impl PartialEq for DeltaEncoder
impl StructuralPartialEq for DeltaEncoder
Auto Trait Implementations§
impl Freeze for DeltaEncoder
impl RefUnwindSafe for DeltaEncoder
impl Send for DeltaEncoder
impl Sync for DeltaEncoder
impl Unpin for DeltaEncoder
impl UnsafeUnpin for DeltaEncoder
impl UnwindSafe for DeltaEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more