Skip to content

Emir2099/BRIAN2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Analog–Digital Hybrid Neural Network (Brian2)

This repository contains a Brian2-based hybrid neuromorphic framework that combines analog and digital neurons. It includes: a minimal end‑to‑end demo, an experiments harness (noise, jitter, ablation), and a long‑run consolidation/saturation study. This README explains what each file does and how to reproduce all figures for your paper.

Overview

1) Quick start (Windows PowerShell)

Create a virtual environment and install dependencies:

python -m venv .venv
.\.venv\Scripts\Activate
pip install brian2 numpy matplotlib

Clone/open this repo, then run the scripts below from their folders as shown.

2) Project structure and what each file does

  • AnalogAndDigital_Final/
    • main_file.py – Minimal end‑to‑end demo of the hybrid architecture (2 analog + 2 digital neurons) with configurable synaptic plasticity (Hebb, STDP, LTP), basic energy estimation, noise adaptability visualization, and non‑volatile memory export (nv_memory.json). Produces interactive plots (not saved to disk by default).
  • Review/
    • update.py – Experiments harness that reproduces noise robustness, timing/jitter, and ablation results. Saves three PDFs in the same folder:
      • fig_noise_sweep_updated.pdf
      • fig_jitter_test_updated.pdf
      • fig_ablation_updated.pdf
    • saturation.py – Long‑run LTM consolidation/saturation tests with multiple conditions (baseline/full/decay_only/norm_only). Saves plots to Review/saturation_results/:
      • fig_saturation_norm.pdf (||W|| over time)
      • fig_saturation_hist.pdf (weight histograms at t0/tmid/tend)
      • fig_saturation_perf.pdf (mean firing rate over time)
    • saturation_results/ – Output directory created by saturation.py.
  • AnalogAndDigital_Older/ – Earlier variants kept for reference.

3) How to run and recreate results

A. End‑to‑end demo (minimal) – main_file.py

From the AnalogAndDigital_Final folder:

cd AnalogAndDigital_Final
python main_file.py

What you’ll see/produce:

  • Interactive figures: analog/digital voltage traces, synaptic weight evolution (one synapse 0→1), spike rasters, energy comparison bar chart, and noise adaptability curves.
  • A JSON snapshot nv_memory.json containing neuron states and synaptic weights.

Choosing the learning rule:

  • Open main_file.py and set the call in __main__:
    • run_dual_mode_dual_neuron(learning_rule='hebb' | 'stdp' | 'ltp')
  • Implemented behaviors:
    • Hebb (demo form): additive potentiation on pre‑spike, w = clip(w + 0.01*mV, 0, 1*mV) → approximately linear growth until capped.
    • STDP (pair-based): uses pre/post traces with balanced potentiation/depression, clipped to w_max.
    • LTP (bounded multiplicative): w += α (w_max − w) clipped to [0, w_max] → concave growth that slows near the ceiling.

Notes for reproducing a strictly linear Hebbian figure (as in the paper):

  • Plot right after the initial 1000 ms run (before any subsequent noise runs); otherwise additional runs will change the slope and produce curvature.

B. Experiments harness – Review/update.py

From the Review folder:

cd Review
python update.py

Outputs (saved in Review/):

  • fig_noise_sweep_updated.pdf – Mean ± SD accuracy vs. input noise (analog vs. digital)
  • fig_jitter_test_updated.pdf – First‑spike latency vs. jitter
  • fig_ablation_updated.pdf – Perturbation response with/without adaptive synapse

Each experiment builds a fresh network per trial and uses fixed time step dt = 0.1 ms for reproducibility.

C. Saturation & consolidation study – Review/saturation.py

From the Review folder:

cd Review
python saturation.py

Outputs (saved in Review/saturation_results/):

  • fig_saturation_norm.pdf – L2 norm of weights across consolidation steps
  • fig_saturation_hist.pdf – Weight distributions at different times
  • fig_saturation_perf.pdf – Population mean firing rate (Hz)

The script runs multiple seeds and conditions and writes all figures to a dedicated results directory.

4) Reproducibility notes

  • Randomness: Some scripts set seeds internally (see saturation.py). For exact replication of figures, run the scripts from their own folders and avoid editing seeds unless required by the paper.
  • Units: Brian2 enforces physical units. All weight updates are bounded via clip(..., 0*mV, w_max) where applicable to avoid runaway growth.
  • Plot fonts: main_file.py sets global Matplotlib font sizes for readability. PDFs produced by Review scripts embed the font sizes present at runtime.

5) Troubleshooting

  • “My Hebbian curve looks curved, not linear”: Ensure you’re plotting the segment from the initial 1000 ms run only. Later noise/adaptive runs (after net.store()/restore()) can change firing rates and bend the trajectory.
  • “Different curves look too similar”: If rules saturate at the same ceiling and runtime is long, all curves flatten near w_max. Reduce runtime or lower w_max to highlight differences, or compare multiple synapses with different spike correlations.
  • Windows tip: Run each script from its own folder so that PDFs and nv_memory.json are written to the expected locations.

6) Key features

  • Dual‑mode neurons: analog (variability/adaptability) and digital (precision timing)
  • Configurable plasticity rules:
    • Hebbian learning
    • Spike‑timing‑dependent plasticity (STDP)
    • Long‑term potentiation (LTP)

7) Requirements

  • Python 3.8+ (3.10/3.11 recommended)
  • Brian2
  • NumPy
  • Matplotlib
  • JSON (standard library)

8) Installation

Use Windows PowerShell commands (or adapt to your shell):

git clone https://github.com/Emir2099/BRIAN2.git
cd BRIAN2
python -m venv .venv
.\.venv\Scripts\Activate
pip install brian2 numpy matplotlib

9) Visualization

The code generates several plots:

  • Membrane potential traces for analog and digital neurons
  • Synaptic weight evolution over time
  • Spike raster plots
  • Energy efficiency comparison
  • Noise adaptability analysis

10) Applications

  • Edge AI: low‑power wearable devices
  • Autonomous robotics: systems requiring persistent skill retention
  • Neuromorphic hardware: RRAM‑integrated chips
  • Brain‑inspired computing: models bridging biological plausibility and engineering pragmatism

7) Acknowledgments

  • Brian2 development team
  • Neuromorphic computing community

About

A Hybrid Neuromorphic Framework With Dual-Mode Memory and Adaptive Synaptic Plasticity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages