Skip to main content

Simulation of population dynamics

Project description

popdyn

Library for simulation of population dynamics.

Allows to simulate the interaction between specific groups in a population, calculating the amount of members for each group along the time. The transitions between groups are defined using probabilistic rules, and the result is obtained through the solution of the differential equations involved in the process.

Installing

pip3 install popdyn

Using the library

Let's dive in a simple example to see how it works.

First step is define the model, for this example the SIR model.

from popdyn import Model, Transition

# storage in a dict the ID and the initial population for each group
groups = {
    'S': 1000000,
    'I': 10000,
    'R': 5000
}

# intialize the model
sir = Model(list(groups.keys()))

# add transitions between groups
sir['S', 'I'] = Transition(1, 0.0561215, 'S', 'I', N=True)
sir['I', 'R'] = Transition(1, 0.0455331, 'I')

If we print the model, we can see the transitions for each group (N is the total population):

>>> print(sir)
S -> {'I': 1 * 0.0561215 * S * I / N^1}
I -> {'R': 1 * 0.0455331 * I}
R -> {}

Once ready the model, we can simulate the behavior of the groups in a period of time:

time, pops = sir.solve(t=100, initial_pop=list(groups.values()))

Getting in time the points over the time and in pops a matrix with the population for each group in the different time points.

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

popdyn-0.2.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

popdyn-0.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file popdyn-0.2.1.tar.gz.

File metadata

  • Download URL: popdyn-0.2.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0

File hashes

Hashes for popdyn-0.2.1.tar.gz
Algorithm Hash digest
SHA256 adb23b91319a403bc8a12856fd859dc7416881e6973b1efc96e50931c0f375e0
MD5 bc6a6ba16ad67a35f64d329999420a64
BLAKE2b-256 01b920e046d3708d2f834ccc4df915ef5a70e1f4ccbf08141d5b7490e6688c71

See more details on using hashes here.

File details

Details for the file popdyn-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: popdyn-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0

File hashes

Hashes for popdyn-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7fbc02667e94cad719c60be5530d8814ed9466b011f6f39875733f529409ef08
MD5 692572c17a08f42e2e4e6ae300d8aec4
BLAKE2b-256 d987a740685f4579ca355b269e50889d0206fb1725e5fe51c8005c5bc85af934

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