Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

 
 

Repository files navigation

BatchSNN — A Batched, Biologically Plausible Spiking Neural Network Framework

BatchSNN is a Python library inspired by BindsNET but designed for biological realism, batch simulation, and pharmacological modeling.
It enables efficient simulation of multiple spiking networks in parallel, sharing the same synaptic weights while evolving independently in time, allowing stable and accelerated training of spiking neural networks (SNNs).


Key Features

  • Biologically grounded neurons and synapses
    Time constants, conductances, and dynamics consistent with cortical physiology.

  • Batch evolution of parallel SNNs
    Multiple independent networks evolve simultaneously, sharing one global set of synaptic weights.
    STDP updates are combined across batches using configurable reduction functions.

  • Flexible connectivity schemes
    Supports spatial organization, distance-dependent delays, and probabilistic connections.

  • Neuromodulation and pharmacology
    Dopamine-modulated STDP at Exc→Motor synapses, enabling reward-based learning and pharmacological exploration (e.g. lesions, coma, zolpidem).

  • Optimized performance
    GPU-accelerated computation and biologically inspired weight normalization optimizers.


Model Structure

Each simulation contains:

  • A Global Neuronal Workspace (GNW) composed of excitatory and inhibitory populations.
  • Excitatory neurons (Exc): undergo plasticity and may project to motor units.
  • Inhibitory neurons (Int): regulate Exc dynamics via lateral and local inhibition.

The parameter ratio defines the fraction of excitatory neurons:
N_exc = N * ratio, N_inh = N * (1 - ratio).

For experiments involving modular architectures (e.g., digit-like columns), you can specify:

  • n_digits: number of cortical columns (or modules).
  • column_size: number of neurons per column.
    The total number of neurons is then N = n_digits × column_size.

The image below is extracted from the example_09.ipynb notebook, and shows the distribution of neurones when n_digits = 4, N = 120, ratio = 0.8.

alt text


Batch Processing

When batch_size > 1, BatchSNN simulates several identical networks in parallel:

  • Each network receives independent inputs and has independent membrane potentials.
  • All networks share the same synaptic weights.
  • STDP updates from each network are combined using a reduction function (e.g. sum_reduction_fn, mean_reduction_fn, etc.).
  • The flag unique_samples=True ensures that each batch network receives a distinct input pattern.

This approach allows faster, more stable and more reproducible learning.


Connectivity Options

Type Description
"all_to_all" Fully connected across all populations.
"all_to_all_except_Exc" All-to-all except between Exc1 and Exc2 groups.
"all_to_all_sparse" Randomly pruned connections preserving type ratios.
"all_to_all_sparse_dist" Sparse connections with distance-dependent probabilities: (p = exp(-dist_scale * dist / dist.max())).

Additional parameters:

  • connection_ratio: fraction of existing connections (for sparse topologies).
  • connection_dist_scale: scales the exponential distance-dependence of connectivity.
  • implement_delay: enables biologically realistic synaptic transmission delays.

The image below is extracted from the example_07.ipynb notebook and shows the connectivity graph in the network when the parameters are the following: connection = "all_to_all_sparse_dist", connection_ratio = 0.2, connection_ratio, connection_dist_scale = 10. alt text alt text


Optimizers

Optimizer Description
"connectivity_normalization" Normalizes total connectivity strength to maintain homeostasis.
"connectivity_distance_normalization" Same as above, but scaled by inter-neuron distance (using optim_lambda_distance and optim_scale_factor).

The distance-based optimizer uses:

  • optim_lambda_distance: controls how strongly distance affects normalization.
  • optim_scale_factor: scales the global normalization effect.

Below is a simple example that shows the stability and convergence speed brought by the optimizer. The first image was extracted from example_01.ipynb, in which no optimizer was used. The network's learning remains pretty stable because the batch size is equal to 1. The second image shows the results from the same simulation with the only difference being the use of the optimizer "connectivity_normalization".

1- optimizer = None: alt text alt text

2- optimizer = "connectivity_normalization": alt text alt text


Lesion Modeling

BatchSNN can simulate focal or global lesions during runtime:

lesion_parameters = {
    "lesion_time": 4000,           # time (ms) when lesion occurs
    "lesion_population": ["Int"],  # affected populations
    "lesion_nr_neurons": [10],     # number of neurons to silence
    "local_lesion": False          # True = spatially localized lesion
}

With the parameters above, the resulting lesion appears as:

alt text


Dopamine and Modulation

When learn_dopa=True, dopamine-modulated STDP is enabled for Exc→Motor connections.
This allows reward-based learning or pharmacological simulation (e.g., zolpidem effects).
The GNW connections remain standard STDP (no dopamine).
An experimental exploration mechanism allows dormant synapses to explore higher weights when no dopamine activity has been detected for long periods.


Reduction Functions

Defined in utils/reductions.py.
sum_reduction_fn is the most stable and is used by default.


Plotting & Saving

  • plot_batch_indices: list of batch indices to visualize (e.g. [0, 2]) for the final raster plot.
  • save_pickles=True: saves simulation data (spikes, weights, etc.) as .pickle files in save_path.
  • show_figures, save_figures, and save_path control output visualization and storage.

Here is an example of a raster plot, extracted from example_10_2.ipynb. alt text


Examples

Several example notebooks are included in the example_notebooks directory to demonstrate how network epigenesis evolves depending on key parameters such as:

  • Simulation duration (time)
  • Timestep (dt)
  • Batch size (batch_size)
  • Connectivity pattern (connection)
  • Optimizer type (optimizer)
  • Lesion conditions (lesion_parameters)
  • etc.

Running the Simulation

You can design experiments in the main.py module. Some default experiments are provided. They generate the necessary data to run the notebooks analyze_results_Exp<i>.ipynb in the result_analysis_notebooks directory. If you want to run these experiments, uncomment them at the end of the main.py module. To run the simulation, type:

python main.py

Typical parameters include time, dt, batch_size, and network configuration (N, ratio, connection, optimizer, etc.).
All simulation parameters can be adjusted in the run_network() call inside main.py.

For running on the Narval supercomputer, do not forget to set --account and --mail-user when calling run_narval.sh.


Installation

Follow these steps to set up the project:

  1. Clone the repository in your local working repository:
git clone https://github.com/antoinecautru/Epigenesis_pytorch_miniBinsnet.git
  1. Download Python 3.9.2 from the official Python website.

  2. Open Git PowerShell in the project directory (Epigenesis_pytorch_miniBinsnet/ folder)

  3. Create a virtual environment called venv:

<path_to_python3.9.2>/python.exe -m venv venv

Note: The name of the virtual environment is important, as it is included in the .gitignore file and in .bash files you will run later.

  1. Activate the virtual environment:
  • On Windows:
  .\venv\Scripts\Activate
  • On Linux/macOS:
  source venv/bin/activate
  1. Install the project dependencies:
pip install -r requirements.txt

If issues arise during installation, please manually install the following libraries:

  • numpy
  • pytorch
  • matplotlib
  • notebook
  • tqdm
  • Brian2

Development Roadmap

  • Add neuromodulators beyond dopamine (e.g. serotonin, acetylcholine).
  • Integrate exploratory plasticity mechanisms.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages