Generate spike trains (Poisson, gamma renewal, regular, Bernoulli, inhomogeneous) in pure Python with zero dependencies.
Project description
spikegen
Generate spike trains in pure Python with zero dependencies. Poisson, gamma renewal, regular, Bernoulli, and inhomogeneous processes, returned as plain sorted lists of spike times, with explicit seeds for reproducibility.
Install
pip install spikegen
30-second example
from spikegen import homogeneous_poisson, regular, gamma_renewal, with_refractory
homogeneous_poisson(rate=50.0, duration=2.0, seed=0) # Poisson spikes in [0, 2)
regular(rate=10.0, duration=1.0) # [0.0, 0.1, 0.2, ...]
gamma_renewal(rate=20.0, shape=2.0, duration=1.0, seed=0) # more regular than Poisson
spikes = homogeneous_poisson(rate=80.0, duration=1.0, seed=0)
with_refractory(spikes, refractory=0.002) # enforce a 2 ms refractory period
from spikegen import population
population(lambda s: homogeneous_poisson(rate=50.0, duration=2.0, seed=s), units=10, seed=0)
from spikegen import bernoulli, jitter
# Discrete-time Bernoulli process: 1 ms bins, 50 Hz rate over 1 second
bernoulli(rate=50.0, duration=1.0, dt=0.001, seed=0)
# Jitter: add Gaussian noise (sigma=2 ms) to each spike time, useful for surrogate data
spikes = homogeneous_poisson(rate=40.0, duration=1.0, seed=0)
jitter(spikes, sigma=0.002, seed=1)
Times are in the same units as 1 / rate (seconds if rate is in Hz). Seeded processes are
reproducible: the same seed gives the same train.
Why this exists
Generating synthetic spike trains is a daily need, but the generators live inside heavy
frameworks: elephant requires neo and quantities, pyspike is NumPy-based, and other
options are old or partial. spikegen is a small, dependency-free generator that returns
plain lists of floats, so reproducible spike trains are one import away. It pairs with
spikedist: generate trains, then measure the
distance between them.
Processes
regular(rate, duration): evenly spaced spikes. Deterministic.homogeneous_poisson(rate, duration, seed): constant-rate Poisson process.inhomogeneous_poisson(rate_fn, max_rate, duration, seed): time-varying rate by thinning.gamma_renewal(rate, shape, duration, seed): gamma inter-spike intervals; shape 1 is Poisson, larger shape is more regular.bernoulli(rate, duration, dt, seed): discrete-time Bernoulli process. Time is divided into bins of width dt; each bin fires at its start time with probabilityrate * dt. RaisesValueErrorwhenrate * dt > 1.with_refractory(times, refractory): drop spikes within a minimum interval.jitter(times, sigma, seed): add independent Gaussian jitter (standard deviation sigma) to each spike time and return sorted results. Useful for surrogate or null datasets that destroy precise timing while preserving spike count.sigma = 0sorts without change.population(make, units, seed): build a population of trains by callingmake(seed)once per unit with independent, reproducible child seeds derived from the base seed.
All parameters after the first are keyword-only and explicit.
Testing
pip install -e ".[dev]"
pytest
Tests cover exact values for the deterministic generators, seeded reproducibility, the rate-bound and ordering invariants, and the validation paths, with property tests via Hypothesis.
Contributing
Issues and pull requests are welcome. See CONTRIBUTING.md.
License
MIT. See LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spikegen-0.3.0.tar.gz.
File metadata
- Download URL: spikegen-0.3.0.tar.gz
- Upload date:
- Size: 861.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0c7efc8db41292ece9837d43fb7c71792d15ced8b77b3bee556291a6271e527
|
|
| MD5 |
6f0def7dc5335ea8d2b2e71d2a8c5a08
|
|
| BLAKE2b-256 |
10d5cad9e0410a74af3b1aacc33b7eb35c9609c470ea3e5969a9044fb045797f
|
File details
Details for the file spikegen-0.3.0-py3-none-any.whl.
File metadata
- Download URL: spikegen-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e88dd57ea14777b2d2c1db61cff6533b961a40d8c0daa7c16cd057c158e3f422
|
|
| MD5 |
db67e38b7a13d9caae5213015e0553a9
|
|
| BLAKE2b-256 |
ed855b8b9f0883e587ba6d0c1a94d35f862b1cc39c547eb960cbc8889521f339
|