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: u64Cumulative routing decisions since creation.
channel_fatigue: Vec<f32>Per-channel fatigue (0.0 = fresh, 1.0 = fully exhausted).
Implementations§
Source§impl ChannelRouter
impl ChannelRouter
Sourcepub fn with_config(config: RouterConfig) -> Self
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).
Sourcepub fn try_with_config(config: RouterConfig) -> Result<Self>
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.
Sourcepub fn route<S: AsRef<[f32]>>(&mut self, signals: S) -> Result<RoutingDecision>
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.
Sourcepub fn route_modulated<S: AsRef<[f32]>>(
&mut self,
signals: S,
mods: &NeuromodState,
) -> Result<RoutingDecision>
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.
Sourcepub fn apply_feedback(&mut self, channel_idx: usize, reward: f32)
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.
Sourcepub fn set_global_gain(&mut self, gain: f32)
pub fn set_global_gain(&mut self, gain: f32)
Apply global neuromodulatory gain to all neurons.
Sourcepub fn weight_matrix(&self) -> Vec<Vec<f32>>
pub fn weight_matrix(&self) -> Vec<Vec<f32>>
Current routing weight matrix (row = neuron, col = input channel).
Sourcepub fn config(&self) -> &RouterConfig
pub fn config(&self) -> &RouterConfig
Access the router configuration.
Trait Implementations§
Source§impl Clone for ChannelRouter
impl Clone for ChannelRouter
Source§fn clone(&self) -> ChannelRouter
fn clone(&self) -> ChannelRouter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more