Skip to content

Vectored GPU based compartmental simulations. Easy to use. With some ABC (Approximate Bayesian Computation) utils

License

Notifications You must be signed in to change notification settings

QuanticPony/compartmental

Repository files navigation

PyPI Downloads PyPI Version

Commit activity License Build

Python Version Wheel



compartmental

Utility tools for Approximate Bayesian computation on compartmental models


SIR Example

(Example taken from examples)

To make a SIR model you will need a configuration and an evolution function:

sir_model = {
    "simulation": {
        "n_simulations": 100000,
        "n_executions": 1,
        "n_steps": 130
    },
    "compartments": {
        "S": { 
            "initial_value": 1,
            "minus_compartments": "I"
        },
        "I": { 
            "initial_value": "Io",
        },
        "R": { "initial_value": 0 },
    },
    "params": {
        "betta": {
            "min": 0.1,
            "max": 0.4
        },
        "mu": {
            "min": 0.01,
            "max": 0.2
        },
        "Io": {
            "min": 1e-6,
            "max": 1e-4
        }
    },
    "fixed_params": {
        "K_mean": 1
    },
    "reference": {
        "compartments" : ["R"]
    },
    "results": {
        "save_percentage": 0.1
    }
}
import compartmental as gcm
gcm.use_cupy() // or numpy in case you don't have access to a gpu.


SirModel = gcm.GenericModel(sir_model)

def evolve(m, *args, **kargs):
    p_infected = m.betta * m.K_mean * m.I

    m.R += m.mu * m.I
    m.I += m.S * p_infected - m.I * m.mu
    m.S -= m.S * p_infected

SirModel.evolve = evolve

That's it!

You can now execute it on your GPU and fit the model to some data. Have a look at the example!

image

Or have a look into a more elavorated model here. image

Instalation

compartmental releases are available as wheel packages on PyPI. You can install the last version using pip:

pip install compartmental

Documentation

Documentations is automatically generated from code on main push and hosted in github-pages here.

Help

Just open an issue with the question tag (or clic here), I would love to help!

Contributing

You can contribute with:

Even only feedback is greatly apreciated.

Just create an issue and let me know you want to help!

Licensing

compartmental is released under the Apache License Version 2.0.