pub struct PoissonEncoder {
pub num_steps: usize,
}Expand description
Poisson spike train encoder.
Generates spike trains with Poisson-distributed timing based on either a per-step probability or an explicit firing rate and time step.
§Mathematical Model
// Dimensionless probability input:
probability = clamp(input, 0.0, 1.0)
spike[i] = 1 if random() < probability else 0
// Physical rate input:
probability = 1 - exp(-rate_hz * dt_seconds) // via -exp_m1(-x) in f32§When to Use
- Generating baseline spike trains with controllable average rates
- Poisson-like random spike generation for stochastic encoders
- Creating temporal patterns with controllable firing rates
§Note
This encoder is NOT part of the Encoder trait because its output type (Vec<u8>)
differs from other encoders (EncodedOutput). It operates in a different mode:
the input is a single probability (0.0 to 1.0) and the output is a spike train
over multiple time steps.
§Examples
use axon_encoder::prelude::*;
let enc = PoissonEncoder::new(32);
let train = enc.encode(0.0); // never spikes
assert_eq!(train.len(), 32);
assert!(train.iter().all(|&b| b == 0));
let p = probability_from_rate_hz(50.0, 0.001);
assert!((0.0..=1.0).contains(&p));Fields§
§num_steps: usizeImplementations§
Source§impl PoissonEncoder
impl PoissonEncoder
pub fn new(steps: usize) -> Self
Sourcepub fn encode_rate_hz(&self, rate_hz: f32, dt_seconds: f32) -> Vec<u8> ⓘ
pub fn encode_rate_hz(&self, rate_hz: f32, dt_seconds: f32) -> Vec<u8> ⓘ
Encodes a firing rate in hertz into a spike train using an explicit time step in seconds for each bin.
Sourcepub fn encode_rate_hz_step(&self, rate_hz: f32, dt_seconds: f32) -> u8
pub fn encode_rate_hz_step(&self, rate_hz: f32, dt_seconds: f32) -> u8
Encodes a single rate-based step using an explicit time step in seconds.
Sourcepub fn encode(&self, input: f32) -> Vec<u8> ⓘ
pub fn encode(&self, input: f32) -> Vec<u8> ⓘ
Encodes a single probability value into a spike train.
Each of the num_steps represents an independent time step where
a spike occurs with the given probability.
Sourcepub fn encode_step(&self, input: f32) -> u8
pub fn encode_step(&self, input: f32) -> u8
Encodes a single step - returns 1 or 0 based on input probability.
Useful for streaming mode where you want one spike decision at a time.
Trait Implementations§
Source§impl Clone for PoissonEncoder
impl Clone for PoissonEncoder
Source§fn clone(&self) -> PoissonEncoder
fn clone(&self) -> PoissonEncoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more