Skip to main content

Pure Python implementation of the Gillespie algorithm for stochastic simulations.

Project description

gillespie

Gilles... what?

The Gillespie algorithm is commonly used to simulate stochastic processes. Even though it was developed in the context of chemical reactions, this algorithm can be applied to many fields of research, e.g. chemistry, biology, epidemiology, ...

Installation

Available on pypi.org, install via pip:

pip install gillespie

Usage

First you must define in what states the populations of your system can be. Then you model your system using three domains:

1. Initial values

A list of initial values for your states:

initials = [290, 10, 0]

Here we have three states in our population.

2. Propensities

A list of functions that, given the values of your current states, compute the transition rate of a reaction:

propensities = [lambda s, i, r: 2 * s * i / 300,
                lambda s, i, r: 0.5 * i]

Here we have two reactions that each take the three current states as input.

3. Stoichiometry

A list of incremental/decremental values for each reaction for each state:

stoichiometry = [[-1, 1, 0],
                 [0, -1, 1]]

Here the first reaction would decrement the first state and increment the second one. The second reaction would decrement the second state and increment the third.

4. Run simulation

import gillespie

times, measurements = gillespie.simulate(initials, propensities, stoichiometry, duration=15)

Times contains all the time steps where a reaction occured. And measurements is a list of triplets with the SIR measurements in this case.

Examples

See examples.

To run the examples yourself the gillespie package is not needed to be installed. However, you will need to install matplotlib:

pip install matplotlib

Then, clone the repo and run an example from the project root directory e.g. via:

python examples/epidemics/sir.py

The output plot will then be created in your working directory.

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

gillespie-0.0.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

gillespie-0.0.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file gillespie-0.0.3.tar.gz.

File metadata

  • Download URL: gillespie-0.0.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for gillespie-0.0.3.tar.gz
Algorithm Hash digest
SHA256 fb7a6cae8b125c80de96c5b5c628a72cf083e713c9e41f7d5ad9ffcec54a2130
MD5 83ac8db66c41b39254e58cabf1e3eab5
BLAKE2b-256 9c984902854f4f892a2452df9c12cd8bde360d31dc515db922f7dfc988b1d5f1

See more details on using hashes here.

File details

Details for the file gillespie-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: gillespie-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for gillespie-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 94730b875b8a11dcbab75903f8ebeceeeec4595b95cb268eb621ddc4fec5265e
MD5 9e97816753ababfd16240d1a4d77c7af
BLAKE2b-256 84ed1e24087c0dfa8025e08528498837fcb8ee35de4ded42ad413e5249091728

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