Skip to main content

STDPRule

Struct STDPRule 

Source
pub struct STDPRule {
    pub tau_plus_us: u32,
    pub tau_minus_us: u32,
    pub a_plus: i16,
    pub a_minus: i16,
    pub learning_rate: u16,
}
Available on crate feature unstable-stdp only.
Expand description

Unstable: behind unstable-stdp. Spike-Timing-Dependent Plasticity rule.

The audit flagged this as the better STDP implementation (vs stdp_plasticity.rs): a linear stand-in for the exponential decay, in fixed point (the factor is 1000 − |dt|·1000/tau, clamped at 0), sign-correct (positive dt → LTD, negative dt → LTP).

Fields§

§tau_plus_us: u32

LTP time constant (μs) — pre-before-post window.

§tau_minus_us: u32

LTD time constant (μs) — post-before-pre window.

§a_plus: i16

LTP amplitude (fixed-point, 1000 = 1.0).

§a_minus: i16

LTD amplitude (negative).

§learning_rate: u16

Overall learning rate (fixed-point, 1000 = 1.0).

Implementations§

Source§

impl STDPRule

Source

pub fn new() -> Self

Default biological STDP: 20ms/20ms tau, asymmetric amplitudes (LTD slightly larger).

Source

pub fn calculate_weight_change(&self, dt_us: i32) -> i16

Compute the weight delta for a given spike-time difference.

§Parameters
  • dt_us = pre_spike_time - post_spike_time (positive = post fired first → LTD).
§Returns

Weight delta (signed): non-negative for LTP, non-positive for LTD, zero outside the window.

§Invariants
  • dt > 0 → returns ≤ 0 (LTD)
  • dt < 0 → returns ≥ 0 (LTP)
  • |dt| ≥ tau → returns 0 (the linear factor reaches 0)
§Bug fix vs v0.1

v0.1 used factor = SCALE - decay without clamping. When |dt| > tau, decay > SCALE and factor goes negative, breaking the sign convention (LTP returns negative, LTD returns positive). The property test prop_stdp_sign_convention catches this at dt = -24000. Fix: clamp factor to ≥ 0 — the linear exp approximation naturally floors at zero.

§Bug fix (R18 rider, 2026-08-22)

dt_us.abs() * SCALE overflowed i32 at |dt| > ~2.15 s (release: silent wrap → spurious deltas far outside the window, e.g. −560 at dt = ±2 200 000 μs where 0 is required; debug: panic) — and dt_us.abs() itself is UB-adjacent at i32::MIN. The whole expression now runs in i64, cast BEFORE the abs (total at i32::MIN), which also covers the tail product a · factor · learning_rate overflowing i32 at extreme learning_rate (u16 max). Observable values identical everywhere the old code didn’t overflow.

Trait Implementations§

Source§

impl Clone for STDPRule

Source§

fn clone(&self) -> Self

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 STDPRule

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for STDPRule

Source§

fn default() -> Self

Returns the “default value” for a type. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.