episimlab package

Subpackages

Submodules

episimlab.compt_model module

class episimlab.compt_model.ComptModel(*, tm_subset={}, state, compt_graph, stochastic, seed_state)

Bases: object

Applies the compartmental disease model defined in compt_graph to the current state of the system.

_tm_subsetattr.Attribute

Mapping of all variables that belong to group ‘edge_weight’

Variable properties:

  • type : group_dict

  • intent : in

  • default value : {}

stateattr.Attribute

The current state of the simulation. in the context of a compartmental model, this tensor contains the current populations of all compartments along every demographic axis (e.g. age, risk, geospatial vertex).

Variable properties:

  • type : variable

  • intent : inout

  • global name : state

  • dimensions : (‘vertex’, ‘compt’, ‘age’, ‘risk’)

tmattr.Attribute

The transition matrix (tm for short) that is added to the state at time t to get the state for the state at the t + 1 timestep.

Variable properties:

  • type : variable

  • intent : out

  • global name : edge_weight

  • dimensions : (‘vertex’, ‘compt’, ‘age’, ‘risk’)

compt_graphattr.Attribute

The compartment graph is a networkx graph where nodes are compartments and edges are allowed transitions between them in the compartmental model.

Variable properties:

  • type : variable

  • intent : in

  • global name : compt_graph

  • dimensions : (‘compt_graph’,)

stochasticattr.Attribute

Boolean flag that determines whether to sample edge weights stochastically (stochastic=true) or not (deterministic, stochastic=false)

Variable properties:

  • type : variable

  • intent : in

  • global name : stochastic

  • dimensions : ()

seed_stateattr.Attribute

Integer seed for generating the random number generator at every time step.

Variable properties:

  • type : variable

  • intent : in

  • global name : seed_state

  • dimensions : ()

STATE_DIMS = ('vertex', 'compt', 'age', 'risk')
TAGS = ('essential',)
apply_edges() None

Iterate over edges in compt_graph in ascending order of priority. Apply each edge to the TM.

calc_k(*edges) xarray.core.dataarray.DataArray

Find some scaling factor k such that origin node u will not be depleted if all edges (u, v) are applied simultaneously. All edges must share the same origin node u.

edge_to_tm(*edges, k=1.0) None

Applies to the transition matrix (TM) the weight of directed edges (u, v) from compartment u to compartment v. Scale edge weights by k to ensure that population of origin node u is always non-negative after edge weight has been applied.

edge_weight(u, v)
property edges_by_priority: tuple

Parses the compt_graph attribute into tuples of edges sorted by edges’ priority attribute. Basically, only used in the apply_edges method.

finalize_step()
get_edge_weight(u, v)

Try to find an edge weight for (u, v) in tm_subset, then in the edge attribute. Default to zero weight if none can be found.

poisson(val)
property rng
run_step()

In particular, we need to ensure that tm_subset and tm refresh at every timestep.

stochastic_draw(*args, **kwargs)

episimlab.foi module

class episimlab.foi.BaseFOI(*, phi, state, beta, coords={})

Bases: object

Base class for calculating force of infection (FOI).

phiattr.Attribute

Pairwise contact patterns

Variable properties:

  • type : variable

  • intent : in

  • global name : phi

  • dimensions : (‘age0’, ‘age1’, ‘risk0’, ‘risk1’, ‘vertex0’, ‘vertex1’)

stateattr.Attribute

No description given

Variable properties:

  • type : global

  • intent : in

  • global name : state

betaattr.Attribute

No description given

Variable properties:

  • type : variable

  • intent : in

  • global name : beta

  • dimensions : ()

_coordsattr.Attribute

Mapping of all variables that belong to group ‘coords’

Variable properties:

  • type : group_dict

  • intent : in

  • default value : {}

property I
I_COMPT_LABELS = 'I'
PHI_DIMS = ('age0', 'age1', 'risk0', 'risk1', 'vertex0', 'vertex1')
property S
S_COMPT_LABELS = 'S'
TAGS = ('FOI', 'essential', 'example')
property foi: xarray.core.dataarray.DataArray
property foi_coords: dict
property foi_dims: tuple

We assume that we want to include all phi dimensions in the FOI calculation.

normalize_index(index)

Generate an index that that is compatible with DataArray.loc.

property phi_dims
class episimlab.foi.BruteForceFOI(*, phi, state, beta, coords={})

Bases: episimlab.foi.BaseFOI

Calculate force of infection (FOI) using naive for looping. Similar to BruteForceFOI process in Episimlab v1

phiattr.Attribute

Pairwise contact patterns

Variable properties:

  • type : variable

  • intent : in

  • global name : phi

  • dimensions : (‘age0’, ‘age1’, ‘risk0’, ‘risk1’, ‘vertex0’, ‘vertex1’)

stateattr.Attribute

No description given

Variable properties:

  • type : global

  • intent : in

  • global name : state

betaattr.Attribute

No description given

Variable properties:

  • type : variable

  • intent : in

  • global name : beta

  • dimensions : ()

_coordsattr.Attribute

Mapping of all variables that belong to group ‘coords’

Variable properties:

  • type : group_dict

  • intent : in

  • default value : {}

PHI_DIMS = ('age0', 'age1', 'risk0', 'risk1', 'vertex0', 'vertex1')
TAGS = ('model::SIR', 'FOI', 'brute_force', 'deprecated')
property foi: xarray.core.dataarray.DataArray

Brute force FOI, like BruteForceFOI in Episimlab v1.0

run_step()

Module contents