Skip to main content

PoissonEncoder

Struct PoissonEncoder 

Source
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: usize

Implementations§

Source§

impl PoissonEncoder

Source

pub fn new(steps: usize) -> Self

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> PoissonEncoder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PoissonEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.