Skip to main content

ChannelRouter

Struct ChannelRouter 

Source
pub struct ChannelRouter {
    pub total_routes: u64,
    pub channel_fatigue: Vec<f32>,
    /* private fields */
}
Expand description

Generic multi-channel SNN Router.

Integrates multi-channel signals over ROUTING_TIMESTEPS to produce a sparse activation mask. The number of channels is configurable at construction time via RouterConfig.

Supports adaptive neuromodulatory routing via ChannelRouter::route_modulated:

  • Channels strengthen with use (dopamine-gated potentiation)
  • Channels weaken when idle (use-it-or-lose-it decay)
  • Fatigue accumulates with activation, cortisol amplifies it
  • The router naturally seeks the least-resistance pathway

Deserialization re-runs RouterConfig::validate and requires neuron, weight, fatigue, and baseline-weight vector shapes to match channel_count. Missing config / channel_fatigue / baseline_weights (legacy snapshots) are filled from the neuron bank rather than rejected.

Ingress is atomic: non-finite signals or invalid NeuromodState values return a structured MeshError and leave neurons, fatigue, adaptive weights, and total_routes unchanged.

Fields§

§total_routes: u64

Cumulative routing decisions since creation.

§channel_fatigue: Vec<f32>

Per-channel fatigue (0.0 = fresh, 1.0 = fully exhausted).

Implementations§

Source§

impl ChannelRouter

Source

pub fn new() -> Self

Create a new router with default configuration (3 channels).

Source

pub fn with_config(config: RouterConfig) -> Self

Create a new router with a custom configuration.

Invalid configs panic. Prefer ChannelRouter::try_with_config when the caller needs a recoverable error.

§Panics

Panics if RouterConfig::validate fails (zero routing_timesteps, out-of-range channel count, non-finite parameters, or rates outside their documented interval).

Source

pub fn try_with_config(config: RouterConfig) -> Result<Self>

Fallible counterpart of ChannelRouter::with_config.

Validates config before allocating the dense weight tables, so an oversized channel_count cannot exhaust memory on the way to an error.

Source

pub fn route<S: AsRef<[f32]>>(&mut self, signals: S) -> Result<RoutingDecision>

Route raw channel signals through the SNN (non-modulated).

signals must have length equal to config.channel_count. Every sample must be finite; NaN and ±infinity are rejected with MeshError::NonFiniteSignal naming the channel index. Finite signed samples are accepted and participate in the weighted sum (a negative input inhibits).

Validation runs before any neuron, fatigue, weight, or total_routes mutation, including the deserialized-state self-heal.

Backward-compatible thin wrapper around ChannelRouter::route_modulated. The error context reported on a signal-length mismatch is "route signals", matching the original pre-neuromodulation API — callers using this public method see the same error message they did before, even though the implementation now delegates to route_modulated internally.

Source

pub fn route_modulated<S: AsRef<[f32]>>( &mut self, signals: S, mods: &NeuromodState, ) -> Result<RoutingDecision>

Route with neuromodulatory modulation.

Seeks the least-resistance pathway by dynamically adjusting thresholds and applying use-it-or-lose-it plasticity:

  • Cortisol raises effective thresholds (resistance)
  • Dopamine lowers thresholds and strengthens active channels (conductance)
  • Serotonin increases leak (reduces persistence)
  • Inactive channels decay toward baseline weights
  • Active channels potentiate (dopamine-gated)

signals follow the same finite/signed rules as ChannelRouter::route. mods is validated via NeuromodState::validate before any routing timestep: non-finite fields become MeshError::NonFiniteNeuromodulator, and finite values outside [0, 1] become MeshError::OutOfRangeNeuromodulator. Both this method and ChannelRouter::route share that ingress check.

Source

pub fn apply_feedback(&mut self, channel_idx: usize, reward: f32)

Apply feedback to adjust synaptic weights for a specific channel.

Self-heals channel_fatigue and baseline_weights before any indexing, so calling apply_feedback on a freshly deserialized router (where the lazy repair in route_modulated has not yet run) is safe. See ensure_neuromod_state_synced for the exact shape check.

Source

pub fn set_global_gain(&mut self, gain: f32)

Apply global neuromodulatory gain to all neurons.

Source

pub fn weight_matrix(&self) -> Vec<Vec<f32>>

Current routing weight matrix (row = neuron, col = input channel).

Source

pub fn config(&self) -> &RouterConfig

Access the router configuration.

Source

pub fn fatigue(&self) -> &[f32]

Access per-channel fatigue levels.

Trait Implementations§

Source§

impl Clone for ChannelRouter

Source§

fn clone(&self) -> ChannelRouter

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 ChannelRouter

Source§

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

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

impl Default for ChannelRouter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ChannelRouter

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ChannelRouter

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

Source§

type Output = T

Should always be Self
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.