#[repr(C)]pub struct Signal {
pub polarity: i8,
pub magnitude: u8,
pub multiplier: u8,
}Expand description
Signal: polarity × magnitude × multiplier (s = p × m × k)
The fundamental unit of neural communication.
Compact 3-byte #[repr(C)] representation:
polarity: -1 (inhibited), 0 (neutral), +1 (excited)magnitude: 0–255 (base intensity — intrinsic neuron drive)multiplier: 0–255 (contextual scaling — metabolic state, arousal, burst energy)
Effective magnitude = magnitude × multiplier (range 0–65,025).
Fields§
§polarity: i8Polarity: -1 (inhibited), 0 (neutral), +1 (excited)
magnitude: u8Magnitude: 0–255 (base intensity — intrinsic neuron drive)
multiplier: u8Multiplier: 0–255 (contextual scaling — metabolic state, arousal, burst energy)
Default: 1 (neutral — effective magnitude equals base magnitude). 0 = silenced (effective magnitude is zero regardless of base magnitude).
Implementations§
Source§impl Signal
impl Signal
Sourcepub const MAX_POSITIVE: Signal
pub const MAX_POSITIVE: Signal
Maximum positive signal
Sourcepub const MAX_NEGATIVE: Signal
pub const MAX_NEGATIVE: Signal
Maximum negative signal
Sourcepub const BASELINE_MULTIPLIER: u8 = 1
pub const BASELINE_MULTIPLIER: u8 = 1
Baseline multiplier constant — use when k=1 is intentional.
Sourcepub const fn effective_magnitude(&self) -> u16
pub const fn effective_magnitude(&self) -> u16
Compute effective magnitude: magnitude × multiplier (0–65,025)
Sourcepub const fn current(&self) -> i32
pub const fn current(&self) -> i32
Compute signed effective current: polarity × magnitude × multiplier
Sourcepub const fn positive(magnitude: u8) -> Signal
👎Deprecated: use Signal::positive_amplified(mag, mul) — s = p × m × k requires all three values
pub const fn positive(magnitude: u8) -> Signal
use Signal::positive_amplified(mag, mul) — s = p × m × k requires all three values
Create a positive (excitatory) signal with multiplier = 1
Sourcepub const fn negative(magnitude: u8) -> Signal
👎Deprecated: use Signal::negative_amplified(mag, mul) — s = p × m × k requires all three values
pub const fn negative(magnitude: u8) -> Signal
use Signal::negative_amplified(mag, mul) — s = p × m × k requires all three values
Create a negative (inhibitory) signal with multiplier = 1
Sourcepub const fn positive_amplified(magnitude: u8, multiplier: u8) -> Signal
pub const fn positive_amplified(magnitude: u8, multiplier: u8) -> Signal
Create a positive signal with explicit multiplier
Sourcepub const fn negative_amplified(magnitude: u8, multiplier: u8) -> Signal
pub const fn negative_amplified(magnitude: u8, multiplier: u8) -> Signal
Create a negative signal with explicit multiplier
Sourcepub const fn with_polarity(polarity: Polarity, magnitude: u8) -> Signal
👎Deprecated: use Signal::with_polarity_amplified(pol, mag, mul) — s = p × m × k requires all three values
pub const fn with_polarity(polarity: Polarity, magnitude: u8) -> Signal
use Signal::with_polarity_amplified(pol, mag, mul) — s = p × m × k requires all three values
Create from Polarity enum and magnitude (type-safe, multiplier = 1)
Sourcepub const fn with_polarity_amplified(
polarity: Polarity,
magnitude: u8,
multiplier: u8,
) -> Signal
pub const fn with_polarity_amplified( polarity: Polarity, magnitude: u8, multiplier: u8, ) -> Signal
Create from Polarity enum, magnitude, and multiplier (type-safe)
Sourcepub const fn new(polarity: i8, magnitude: u8) -> Signal
👎Deprecated: use Signal::new_raw(pol, mag, mul) — s = p × m × k requires all three values
pub const fn new(polarity: i8, magnitude: u8) -> Signal
use Signal::new_raw(pol, mag, mul) — s = p × m × k requires all three values
Create from raw i8 polarity and magnitude (unchecked, multiplier = 1)
Sourcepub const fn new_raw(polarity: i8, magnitude: u8, multiplier: u8) -> Signal
pub const fn new_raw(polarity: i8, magnitude: u8, multiplier: u8) -> Signal
Create from raw components (unchecked)
Sourcepub const fn new_checked(polarity: i8, magnitude: u8) -> Option<Signal>
👎Deprecated: use Signal::new_checked_full(pol, mag, mul) — s = p × m × k requires all three values
pub const fn new_checked(polarity: i8, magnitude: u8) -> Option<Signal>
use Signal::new_checked_full(pol, mag, mul) — s = p × m × k requires all three values
Create from raw i8 polarity with validation (multiplier = 1)
Sourcepub const fn new_checked_full(
polarity: i8,
magnitude: u8,
multiplier: u8,
) -> Option<Signal>
pub const fn new_checked_full( polarity: i8, magnitude: u8, multiplier: u8, ) -> Option<Signal>
Create from raw i8 polarity, magnitude, and multiplier with validation
Sourcepub fn from_floats(polarity_f: f32, magnitude_f: f32) -> Signal
👎Deprecated: defaults multiplier to 1 — construct with explicit multiplier instead
pub fn from_floats(polarity_f: f32, magnitude_f: f32) -> Signal
defaults multiplier to 1 — construct with explicit multiplier instead
Create from separate float components (multiplier = 1)
polarity_f: quantised to {-1, 0, +1} (dead-zone ±0.1)
magnitude_f: clamped to 0.0–1.0, scaled to 0–255
Sourcepub fn from_signed(value: f32) -> Signal
👎Deprecated: defaults multiplier to 1 — construct with explicit multiplier instead
pub fn from_signed(value: f32) -> Signal
defaults multiplier to 1 — construct with explicit multiplier instead
Create from a single signed float (-1.0 to 1.0), multiplier = 1
Sign → polarity, absolute value → magnitude.
Sourcepub fn from_signed_i32(value: i32) -> Signal
👎Deprecated: defaults multiplier to 1 — use Signal::from_current(val) for full p × m × k range
pub fn from_signed_i32(value: i32) -> Signal
defaults multiplier to 1 — use Signal::from_current(val) for full p × m × k range
Create from a signed i32 (multiplier = 1, clamps magnitude to 255).
Warning: This discards values above ±255. For the full ±65,025 range,
use [from_current] instead.
Sourcepub fn from_current(value: i32) -> Signal
pub fn from_current(value: i32) -> Signal
Create from a signed i32 using the full p × m × k range (±65,025).
Decomposes the absolute value into magnitude × multiplier where both
are 0–255. Values above 65,025 are clamped. Values ≤ 255 get multiplier=1.
Values > 255 use magnitude=255 and multiplier=ceil(abs/255).
Sourcepub fn from_i16(value: i16) -> Signal
👎Deprecated: defaults multiplier to 1 — use Signal::from_signed_i32(val) for large ranges or construct with explicit multiplier
pub fn from_i16(value: i16) -> Signal
defaults multiplier to 1 — use Signal::from_signed_i32(val) for large ranges or construct with explicit multiplier
Create from a signed i16 (multiplier = 1)
Sourcepub fn from_u8_bipolar(level: u8) -> Signal
👎Deprecated: defaults multiplier to 1 — construct Signal with explicit multiplier instead
pub fn from_u8_bipolar(level: u8) -> Signal
defaults multiplier to 1 — construct Signal with explicit multiplier instead
Create from u8 bipolar representation (128 = baseline)
Sourcepub fn from_spike_rate(rate_hz: f32, max_rate_hz: f32) -> Signal
👎Deprecated: defaults multiplier to 1 — construct Signal with explicit multiplier instead
pub fn from_spike_rate(rate_hz: f32, max_rate_hz: f32) -> Signal
defaults multiplier to 1 — construct Signal with explicit multiplier instead
Create from spike rate (Hz)
Sourcepub fn from_spike_count(count: u32, window_ms: f32, max_rate_hz: f32) -> Signal
👎Deprecated: defaults multiplier to 1 — construct Signal with explicit multiplier instead
pub fn from_spike_count(count: u32, window_ms: f32, max_rate_hz: f32) -> Signal
defaults multiplier to 1 — construct Signal with explicit multiplier instead
Create from spike count in a time window
Sourcepub fn as_signed_i32(&self) -> i32
pub fn as_signed_i32(&self) -> i32
Get as signed i32 using effective magnitude (polarity × magnitude × multiplier)
Sourcepub fn magnitude_f32(&self) -> f32
pub fn magnitude_f32(&self) -> f32
Get base magnitude as float (0.0–1.0)
Sourcepub fn effective_magnitude_f32(&self) -> f32
pub fn effective_magnitude_f32(&self) -> f32
Get effective magnitude as float (0.0–1.0, normalized to max 65025)
Sourcepub fn as_signed_f32(&self) -> f32
pub fn as_signed_f32(&self) -> f32
Get as signed float using effective magnitude (-1.0 to 1.0)
Sourcepub fn to_u8_bipolar(&self) -> u8
pub fn to_u8_bipolar(&self) -> u8
Convert to u8 bipolar (128 = baseline), using base magnitude only
Sourcepub fn to_spike_rate(&self, max_rate_hz: f32) -> f32
pub fn to_spike_rate(&self, max_rate_hz: f32) -> f32
Convert to spike rate (Hz), using base magnitude
Sourcepub fn get_polarity(&self) -> Polarity
pub fn get_polarity(&self) -> Polarity
Get polarity as Polarity enum (type-safe)
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Is this a positive / excitatory signal?
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Is this a negative / inhibitory signal?
Sourcepub const fn with_multiplier(self, multiplier: u8) -> Signal
pub const fn with_multiplier(self, multiplier: u8) -> Signal
Set the multiplier (contextual scaling)
Sourcepub const fn amplify(self, delta: u8) -> Signal
pub const fn amplify(self, delta: u8) -> Signal
Amplify: increase multiplier by delta (saturating)
Sourcepub const fn attenuate(self, delta: u8) -> Signal
pub const fn attenuate(self, delta: u8) -> Signal
Attenuate: decrease multiplier by delta (saturating)
Sourcepub fn add(&self, other: &Signal) -> Signal
pub fn add(&self, other: &Signal) -> Signal
Add two signals (same polarity adds, opposite cancels). Operates on base magnitude. Result gets multiplier = 1.
Sourcepub fn scale(&self, factor: f32) -> Signal
pub fn scale(&self, factor: f32) -> Signal
Scale base magnitude by a factor (multiplier unchanged)
Sourcepub fn decay(&mut self, retention: f32)
pub fn decay(&mut self, retention: f32)
Apply decay to base magnitude (in-place, for temporal fields)
Sourcepub fn step_toward(&self, target: &Signal) -> Signal
pub fn step_toward(&self, target: &Signal) -> Signal
Step toward target by one unit (base magnitude)
Sourcepub fn step_toward_by(&self, target: &Signal, delta: u8) -> Signal
pub fn step_toward_by(&self, target: &Signal, delta: u8) -> Signal
Step toward target by specified delta (base magnitude)
Sourcepub fn step_toward_ratio(&self, target: &Signal, ratio: f32) -> Signal
pub fn step_toward_ratio(&self, target: &Signal, ratio: f32) -> Signal
Step toward target by fractional amount (0.0–1.0)