(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!
Or have a look into a more elavorated model here.
compartmental releases are available as wheel packages on PyPI. You can install the last version using pip
:
pip install compartmental
Documentations is automatically generated from code on main push and hosted in github-pages here.
Just open an issue with the question
tag (or clic here), I would love to help!
You can contribute with:
- Examples
- Documentation
- Bug report/fix
- Features
- Code
Even only feedback is greatly apreciated.
Just create an issue and let me know you want to help!
compartmental is released under the Apache License Version 2.0.