Skip to main content

SelectiveSSM

Struct SelectiveSSM 

Source
pub struct SelectiveSSM { /* private fields */ }
Available on crate feature alloc only.
Expand description

Mamba-style selective state space model.

The selective mechanism computes input-dependent B, C, and Delta at each timestep, enabling the model to dynamically control what information is stored in and retrieved from the hidden state.

§Dimensions

  • d_in – input/output dimension (number of channels)
  • n_state – hidden state dimension per channel (N)
  • Total hidden state size: d_in * n_state

§Weight Shapes

WeightShapePurpose
w_deltad_inProjects input to scalar step size
w_bN x d_inProjects input to state-input coupling
w_cN x d_inProjects input to state-output coupling
d_skipd_inSkip connection weights
log_aNFixed state transition (always negative after exp)

§Example

use irithyll_core::ssm::selective::SelectiveSSM;
use irithyll_core::ssm::SSMLayer;

let mut ssm = SelectiveSSM::new(4, 8, 42);
let output = ssm.forward(&[1.0, 2.0, 3.0, 4.0]);
assert_eq!(output.len(), 4);

Implementations§

Source§

impl SelectiveSSM

Source

pub fn new(d_in: usize, n_state: usize, seed: u64) -> Self

Create a new selective SSM with random weight initialization.

Weights are initialized from a small normal distribution (scale 0.1) using the provided seed for reproducibility. A is initialized via the S4D-Inv (HiPPO-inspired) strategy: A_n = -(0.5 + n/N), which gives a bounded spectrum of decay rates that remain meaningful at all state sizes. Skip connections (D) are initialized to 1.0 to enable input passthrough by default.

§Arguments
  • d_in – input/output dimension (number of channels)
  • n_state – hidden state dimension per channel (N)
  • seed – random seed for weight initialization
§Example
use irithyll_core::ssm::selective::SelectiveSSM;

let ssm = SelectiveSSM::new(4, 16, 42);
Source

pub fn d_in(&self) -> usize

Get the input/output dimension.

Source

pub fn n_state(&self) -> usize

Get the number of state dimensions per channel.

Source

pub fn reinitialize_channel(&mut self, d: usize, rng: &mut u64)

Surgically reinitialize a single channel, preserving all other channels.

Resets channel d’s hidden state to zero across all state dimensions, reinitializes its weight column in w_b and w_c, its w_delta entry, and its skip connection d_skip to the default (1.0). All other channels are left untouched.

§Arguments
  • d — channel index to reinitialize (must be < d_in)
  • rng — mutable RNG state for generating fresh weights
§Panics

Panics if d >= d_in.

Trait Implementations§

Source§

impl SSMLayer for SelectiveSSM

Source§

fn forward(&mut self, input: &[f64]) -> Vec<f64>

Process one input timestep and return the output vector. Read more
Source§

fn state(&self) -> &[f64]

Get a reference to the current hidden state.
Source§

fn output_dim(&self) -> usize

Output dimension of this SSM layer.
Source§

fn reset(&mut self)

Reset hidden state to zeros, as if no data has been seen.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.