neural-dynamics 0.1.0

Large-scale neural network simulation library with advanced connectivity patterns and dynamics
Documentation

Neural Dynamics Library

A comprehensive library for large-scale neural network simulations with advanced connectivity patterns, dynamics analysis, and mean-field approximations.

Overview

This library provides tools for simulating networks of biophysically realistic neurons with complex connectivity patterns and analyzing their collective dynamics. It integrates:

  • Hodgkin-Huxley neurons: Detailed biophysical neuron models
  • Synaptic models: Realistic synaptic transmission and plasticity
  • Network topologies: Small-world, scale-free, spatial networks
  • Population dynamics: Mean-field approximations (Wilson-Cowan)
  • Analysis tools: Synchrony, criticality, avalanche detection

Quick Start

Create a simple excitatory-inhibitory network

use neural_dynamics::{Network, NetworkBuilder, ConnectionPattern, SynapseType};
use neural_dynamics::stimulation::CurrentInjection;

# fn main() -> Result<(), Box<dyn std::error::Error>> {
// Build an E-I network
let mut network = NetworkBuilder::new(0.1)?
    .add_excitatory_population("E", 80)?
    .add_inhibitory_population("I", 20)?
    .connect(0, 0, ConnectionPattern::FixedProbability(0.1),
             SynapseType::Excitatory, 0.5, 1.0)?
    .connect(0, 1, ConnectionPattern::FixedProbability(0.2),
             SynapseType::Excitatory, 0.8, 1.0)?
    .connect(1, 0, ConnectionPattern::FixedProbability(0.3),
             SynapseType::Inhibitory, 1.5, 0.5)?
    .with_spike_recording()
    .build();

// Add external drive to excitatory population
let stim = CurrentInjection::new(5.0, 0.0, 100.0);
network.add_stimulation(0, Box::new(stim))?;

// Run simulation
network.run(100.0)?;

// Analyze results
let stats = network.statistics();
println!("Total spikes: {}", stats.total_spikes);
# Ok(())
# }

Analyze network synchrony

use neural_dynamics::analysis::kuramoto_order_parameter;
use std::f64::consts::PI;

let phases = vec![0.0, 0.1, 0.05, 0.0]; // Nearly synchronized
let order_param = kuramoto_order_parameter(&phases);
println!("Synchrony: {:.2}", order_param); // Close to 1.0

Detect network avalanches

use neural_dynamics::analysis::detect_avalanches;

# fn main() -> Result<(), Box<dyn std::error::Error>> {
let spike_trains = vec![
    vec![1.0, 2.0, 10.0],
    vec![1.5, 2.5, 10.5],
    vec![2.0, 11.0],
];

let avalanches = detect_avalanches(&spike_trains, 1.0, 1)?;
println!("Detected {} avalanches", avalanches.len());
# Ok(())
# }

Wilson-Cowan mean-field model

use neural_dynamics::mean_field::WilsonCowanModel;

# fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut model = WilsonCowanModel::balanced_network()?;
model.set_input(0.5, 0.0);

// Simulate population dynamics
let trace = model.simulate(100.0, 0.1)?;

// Analyze fixed points
let fixed_points = model.find_fixed_points(20);
println!("Found {} fixed points", fixed_points.len());
# Ok(())
# }

Architecture

Populations

A NeuralPopulation groups neurons with similar properties:

  • Homogeneous: All neurons identical
  • Heterogeneous: Parameter variability across neurons
  • Efficient parallel updates using rayon

Projections

A Projection connects two populations with:

  • Flexible connectivity patterns (all-to-all, small-world, scale-free, etc.)
  • Synaptic transmission delays
  • Weight distributions (constant, uniform, normal)
  • Event-driven spike propagation

Network

The Network orchestrates:

  • Multiple populations and projections
  • External stimulation protocols
  • Recording (spikes, voltages, rates)
  • Efficient simulation with delay queues

Connectivity Patterns

  • AllToAll: Dense connectivity
  • OneToOne: Identity mapping
  • FixedProbability(p): Erdős-Rényi random graph
  • FixedNumber(n): Fixed in-degree
  • SmallWorld{k, p}: Watts-Strogatz model
  • ScaleFree{m}: Barabási-Albert model
  • Gaussian{σ}: Distance-dependent connectivity
  • Custom: User-defined connectivity matrix

Analysis Tools

Synchrony Measures

  • Kuramoto order parameter: R ∈ [0,1], 1 = perfect synchrony
  • Cross-correlation: Temporal relationships between spike trains
  • Phase locking: Relative spike timing analysis

Criticality

  • Avalanche detection: Contiguous activity bursts
  • Branching parameter: σ = ⟨n_{t+1}⟩/⟨n_t⟩, σ=1 is critical
  • Power-law distributions: Scale-free avalanche statistics

Firing Statistics

  • Population rates: Average activity levels
  • CV_ISI: Coefficient of variation of interspike intervals
  • Spike count distributions

Mathematical Models

Hodgkin-Huxley Neurons

C_m dV/dt = -I_Na - I_K - I_K(Ca) - I_leak + I_ext + I_syn

Wilson-Cowan Equations

τ_E dE/dt = -E + S(w_EE·E - w_EI·I + I_E)
τ_I dI/dt = -I + S(w_IE·E - w_II·I + I_I)

where S(x) = 1/(1 + exp(-gain·(x - θ))) is the sigmoid transfer function.

Kuramoto Order Parameter

R = |1/N Σ_j exp(iθ_j)|

Performance

  • Parallel updates: Population dynamics computed in parallel using rayon
  • Sparse connectivity: Efficient storage and computation
  • Event-driven spikes: Lazy propagation through delay queues
  • Memory efficient: Minimal allocations in simulation loops

Features

  • ✅ Biophysically realistic neurons (Hodgkin-Huxley)
  • ✅ Complex synaptic dynamics (AMPA, NMDA, GABA)
  • ✅ Short-term plasticity (depression, facilitation)
  • ✅ Long-term plasticity (STDP)
  • ✅ Multiple connectivity patterns
  • ✅ Mean-field approximations
  • ✅ Comprehensive analysis tools
  • ✅ Parallel computation
  • ✅ Extensive test coverage

Examples

See the examples directory for complete simulations:

  • balanced_network.rs: E-I balance and oscillations
  • small_world.rs: Small-world connectivity and synchronization
  • critical_dynamics.rs: Self-organized criticality
  • wilson_cowan.rs: Mean-field population dynamics

References

  • Hodgkin & Huxley (1952). A quantitative description of membrane current and its application to conduction and excitation in nerve.
  • Wilson & Cowan (1972). Excitatory and inhibitory interactions in localized populations of model neurons.
  • Watts & Strogatz (1998). Collective dynamics of 'small-world' networks.
  • Barabási & Albert (1999). Emergence of scaling in random networks.
  • Beggs & Plenz (2003). Neuronal avalanches in neocortical circuits.
  • Kuramoto (1984). Chemical Oscillations, Waves, and Turbulence.