A Set of Tools for Simulating and Analyzing Spiking Irregularity.
The source code for the following publication:
Aghamohammadi, C., Chandrasekaran, C., & Engel, T. A. (2024). A doubly stochastic renewal framework for partitioning spiking variability. bioRxiv. [DOI: https://www.biorxiv.org/content/biorxiv/early/2024/02/23/2024.02.21.581457.full.pdf]
The Doubly Stochastic Renewal Package is a Python toolkit designed for studying spiking irregularity in single-neuron spike trains. It offers two core components:
DSR: A simulator for generating synthetic spike trains using a doubly stochastic renewal process.neuron_stats: An estimator for quantifying spiking irregularity (Ο) from experimental or simulated spike data.
This package is ideal for modeling neural dynamics, validating computational models, and analyzing neuronal spiking patterns.
The package requires Python 3.8 or higher and the following dependencies:
numpy>=1.21scipy>=1.7matplotlib>=3.4(optional, for visualization withshow_spikes)
We recommend using a virtual environment to avoid dependency conflicts:
python -m venv env
source env/bin/activate # On Windows: env\Scripts\activate
pip install .Or manually place the files in src folder into your Python path and import them.
DSR (Doubly Stochastic Renewal Process) allows the simulation of spike trains. The DSR module contains a suite of methods for generating synthetic spike trains based on a doubly stochastic renewal process. The process is defined by a pair
The user can select from among many pre-defined firing rate models common in neuroscience or provide their own user-defined firing rates. The user can also choose from several pre-defined renewal distributions.
These callable functions return a time-varying firing rate array (in Hz) and can be passed to the DSR class for spike generation.
Returns a fixed constant firing rate.
Returns a constant firing rate chosen randomly between min and max.
Returns a linear ramping firing rate from start to end.
Returns a ramping rate plus a single uniform noise term (width_var * (0.5 - U[0,1])).
Generates a firing rate using the Drift-Diffusion Model. If the rate crosses the boundaries, it is truncated with NaNs.
Like DDM, but sticky boundaries: rate is clamped at the boundary instead of truncated.
Generates a firing rate via an Ornstein-Uhlenbeck process with quartic potential (i.e., restoring force scales cubically).
Pass-through function to use a user-specified rate array.
These functions generate inter-spike intervals (ISIs) in operational time from the pre-defined renewal distributions.
Generates inter-spike intervals (ISIs) using a clock-like mechanism where ISIs are constant.
Generates inter-spike intervals (ISIs) using a Poisson distribution.
Generates inter-spike intervals (ISIs) using a Gamma distribution where phi (float) is the spiking irregularity for the Gamma distribution.
This example generates 20 trials of spike trains over 2000 ms with a constant firing rate of 10 Hz and a Gamma-distributed ISI (spiking irregularity phi=0.5). The show_spikes method displays a raster plot.
from dsr_project import DSR, neuron_stat
params = {'firing_model':{"model": "fix_constant_fr", "params": {"constant":10}},
'renewal_model':{"model": "Gamma_generator", "params": {"phi": 0.5}} }
neuron = DSR(**params)
spike_times, spike = neuron.spike_generator(time=2000, num_trials=20)
neuron.show_spikes()This example simulates spike trains using a Drift-Diffusion Model with absorbing boundaries and a Gamma renewal process (phi=0.3).
from dsr_project import DSR, neuron_stat
params = {'firing_model':{"model": "DDAB", "params": {"start" : 10.0, "Boundry_low" : 1.0, "Boundry_high" : 20, "Drift" : 0, "Diffusion" : 20 }},
'renewal_model':{"model": "Gamma_generator", "params": {"phi":0.3}} }
neuron = DSR(**params)
spike_times, spike = neuron.spike_generator(time=2000, num_trials=20)
neuron.show_spikes()This example uses the firing rate from a previous DSR instance as input for a new simulation.
from dsr_project import DSR, neuron_stat
params = {'firing_model':{"model": "Feed", "params": {"Fr_array": neuron.rates}},
'renewal_model':{"model": "Gamma_generator", "params": {"phi":1}} }
neuron = DSR(**params)
spike_times, spike = neuron.spike_generator(time=2000, num_trials=20)
neuron.show_spikes()The neuron_stats module estimates spiking irregularity (Ο) from spike trains.
Parameters
-
spike: numpy.ndarray, binary spike array. Each element of the array represents 1 ms. A value of 1 indicates the presence of a spike, while 0 means no spike.
-
react_time: float, optional reaction time (ms) to exclude from analysis (default: None).
-
waiting_time_cut: float, maximum time (ms) for ISI analysis (default: 2000).
-
binsize: float, bin size (ms) for irregularity estimation (default: 100).
-
shift: float, shift size (ms) for sliding window analysis (default: 50).
- Synthetic Data Generation: We generate synthetic spike data using:
1-The Drift-Diffusion Model as the firing rate model
2-The Gamma Distribution as the renewal distribution
- Irregularity Estimation:
Using neuron_stat (a model-agnostic tool), we estimate the spiking irregularity of the neuron.
from dsr_project import DSR, neuron_stat
params = {'firing_model':{"model": "DDAB", "params": {"start" : 30.0, "Boundry_low" : 20, "Boundry_high" : 30, "Drift" : 0, "Diffusion" : 20 }},
'renewal_model':{"model": "Gamma_generator", "params": {"phi":0.5}} }
neuron = DSR(**params)
spike_times, spike = neuron.spike_generator(time=2000, num_trials=20)
phi_result = neuron_stat.neuron_stats(
spike,
react_time=None,
waiting_time_cut=2000,
binsize=100,
shift=50
)More examples are available in the examples folder:
-Example_spiking_DD_sticky_boundaries.ipynb
-Example_spiking_constant_FR.ipynb
This project is licensed under the MIT License. See the LICENSE file for details.