Skip to main content

Generate spike trains (Poisson, gamma renewal, regular, inhomogeneous) in pure Python with zero dependencies.

Project description

spikegen

spikegen logo

PyPI CI License: MIT

Generate spike trains in pure Python with zero dependencies. Poisson, gamma renewal, regular, 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)

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.
  • with_refractory(times, refractory): drop spikes within a minimum interval.
  • population(make, units, seed): build a population of trains by calling make(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

spikegen-0.2.0.tar.gz (659.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spikegen-0.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file spikegen-0.2.0.tar.gz.

File metadata

  • Download URL: spikegen-0.2.0.tar.gz
  • Upload date:
  • Size: 659.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for spikegen-0.2.0.tar.gz
Algorithm Hash digest
SHA256 81c24a551384d96bedbf1ee056418803b07c0d16c4514f8b8efc1e848b42c2b1
MD5 5668a9135c529e5b40d3afa14ea35fb3
BLAKE2b-256 83deaf1feae9ec2e14f3b4d7edec103b59cd59eeb8004035e72198a3a76d2284

See more details on using hashes here.

File details

Details for the file spikegen-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: spikegen-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for spikegen-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00b606584b9c93ff63dbcdb665814645d23d0f2931887dc024430180904bf213
MD5 3a5e5fd7f0e3dbf64a68ee80fde69d2a
BLAKE2b-256 b28806aa7f14fd6119308fb346319b3be3888acde7aeb7586ca05b5a9820b9c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page