pub mod compete;
pub mod dendrite;
pub mod eventbus;
pub mod hdc;
pub mod hopfield;
pub mod integration;
pub mod plasticity;
pub mod routing;
pub mod separate;
pub use compete::{KWTALayer, LateralInhibition, WTALayer};
pub use dendrite::{Compartment, Dendrite, DendriticTree, PlateauPotential};
pub use eventbus::{
BackpressureController, BackpressureState, DVSEvent, Event, EventRingBuffer, EventSurface,
ShardedEventBus,
};
pub use hdc::{HdcError, HdcMemory, Hypervector};
pub use hopfield::ModernHopfield;
pub use plasticity::eprop::{EpropLIF, EpropNetwork, EpropSynapse, LearningSignal};
pub use routing::{
BudgetGuardrail, CircadianController, CircadianPhase, CircadianScheduler, CoherenceGatedSystem,
GlobalWorkspace, HysteresisTracker, NervousSystemMetrics, NervousSystemScorecard,
OscillatoryRouter, PhaseModulation, PredictiveLayer, Representation, ScorecardTargets,
};
pub use separate::{DentateGyrus, SparseBitVector, SparseProjection};
#[derive(Debug, thiserror::Error)]
pub enum NervousSystemError {
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Compartment index out of bounds: {0}")]
CompartmentOutOfBounds(usize),
#[error("Synapse index out of bounds: {0}")]
SynapseOutOfBounds(usize),
#[error("Invalid weight: {0}")]
InvalidWeight(f32),
#[error("Invalid time constant: {0}")]
InvalidTimeConstant(f32),
#[error("Invalid gradients: {0}")]
InvalidGradients(String),
#[error("Dimension mismatch: expected {expected}, got {actual}")]
DimensionMismatch { expected: usize, actual: usize },
#[error("HDC error: {0}")]
HdcError(#[from] HdcError),
#[error("Invalid dimension: {0}")]
InvalidDimension(String),
#[error("Invalid sparsity: {0}")]
InvalidSparsity(String),
}
pub type Result<T> = std::result::Result<T, NervousSystemError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_basic_hdc_workflow() {
let v1 = Hypervector::random();
let v2 = Hypervector::random();
let sim = v1.similarity(&v2);
assert!(sim > -0.2 && sim < 0.2, "random similarity: {}", sim);
let bound = v1.bind(&v2);
assert!(
bound.similarity(&v1) > -0.2,
"bound similarity: {}",
bound.similarity(&v1)
);
let mut memory = HdcMemory::new();
memory.store("test", v1.clone());
let results = memory.retrieve(&v1, 0.9);
assert_eq!(results.len(), 1);
assert_eq!(results[0].0, "test");
}
#[test]
fn test_dendrite_workflow() {
let mut dendrite = Dendrite::new(5, 20.0);
for i in 0..3 {
dendrite.receive_spike(i, 100);
}
let triggered = dendrite.update(100, 1.0);
assert!(!triggered);
for i in 3..8 {
dendrite.receive_spike(i, 100);
}
let triggered = dendrite.update(100, 1.0);
assert!(triggered);
assert!(dendrite.has_plateau());
}
}