from epymorph.kit import *
from sympy import Max
class MyIpm(CompartmentModel):
= (
compartments "S"),
compartment("I"),
compartment("R"),
compartment(
)
= [
requirements "beta", type=float, shape=Shapes.TxN, comment="infection rate"),
AttributeDef("gamma", type=float, shape=Shapes.TxN, comment="recovery rate"),
AttributeDef(
]
def edges(self, symbols):
= symbols.all_compartments
[S, I, R] = symbols.all_requirements
[beta, gamma] = Max(1, S + I + R)
N return [
=beta * S * I / N),
edge(S, I, rate=gamma * I),
edge(I, R, rate ]
CompartmentModel
compartment_model.CompartmentModel()
A compartment model definition and its corresponding metadata. Effectively, a collection of compartments, transitions between compartments, and the data parameters which are required to compute the transitions.
CompartmentModel is an abstract class. To create a custom IPM, you will write an implementation of this class.
Examples
Attributes
compartments: Sequence[CompartmentDef]
-
The compartments of the model.
requirements: Sequence[AttributeDef]
-
The attributes required by the model.
quantities: Iterator[CompartmentDef | EdgeDef]
-
All quantities from the model, compartments then edges, in definition order.
symbols: ModelSymbols
-
The symbols which represent parts of this model.
transitions: Sequence[TransitionDef]
-
The transitions in the model.
events: Sequence[EdgeDef]
-
Iterate over all events in order.
requirements_dict: OrderedDict[AbsoluteName, AttributeDef]
-
The attributes required by this model.
strata: Sequence[str]
-
The names of the strata involved in this compartment model.
is_multistrata: bool
-
True if this compartment model is multistrata (False for single-strata).
select: QuantitySelector
-
Make a quantity selection from this IPM.
Methods
Name | Description |
---|---|
diagram |
Render a diagram of this IPM, either by showing it with matplotlib (default) or by saving it to file as a png image. |
edges |
When implementing a CompartmentModel, override this method to define the transition edges between compartments. |