Example Disease with Spatial Mobility¶
A spatial, age-structured SIR model with selectable inter-zone mobility, contact-matrix age mixing, and a single transmission rate
ExampleSpatialMobilityModel(config)
¶
Bases: Model
SIR model with selectable inter-zone mobility AND age-structured mixing.
This extends the spatial-mobility SIR so the population is age-stratified
and age groups mix through a contact matrix, while transmission is still
governed by a single scalar beta (no per-age transmission rate).
Two couplings act together on the force of infection:
- Space — a selectable, row-stochastic presence travel matrix
T(T[i,j]= fraction of zone i present in zone j; rows sum to 1), built bybuild_travel_matrixfrom each admin zone's population and coordinates (1 = gravity, 2 = exponential, 3 = radiation, 4 = uniform). - Age — a contact matrix
M(M[a,b]= relative contact intensity between age groups a and b), auto-loaded by the framework from each demographic group'sage_range.Mis normalised by its spectral radius so it only redistributes risk across ages; the overall transmission scale stays set by the singlebeta(i.e.betakeeps its usual R0-equivalent meaning, as in the non-age model).
Force of infection for susceptibles of age a in zone r (state axes are
(age, zone); the zone axis is last)::
N_present[b,j] = sum_i N[b,i] T[i,j] (age-b people present in j)
I_present[b,j] = sum_i I[b,i] T[i,j] (age-b infectious present in j)
phi[b,j] = I_present[b,j] / N_present[b,j] (age-b prevalence in j)
exposure[a,j] = sum_b M[a,b] phi[b,j] (age mixing within each zone)
lambda[a,r] = beta * sum_j T[r,j] exposure[a,j]
With M = I (identity) and one age group this reduces exactly to the
original zone-only spatial SIR; with travel_sigma = 0 (T = I) it
reduces to independent, age-mixed SIRs per zone.
Initialize the model from a validated simulation config.
Source code in compartment/models/example_spatial_mobility_v2_model/model.py
define_parameters(schema)
classmethod
¶
Declare compartments, transmission edges, mobility, and demographics.
Source code in compartment/models/example_spatial_mobility_v2_model/model.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
build_travel_matrix(admin_zones)
¶
Return the (R, R) row-stochastic presence matrix for the chosen model.
Source code in compartment/models/example_spatial_mobility_v2_model/model.py
prepare_initial_state()
¶
Expand the state across age bands and precompute the age-mixing matrix.
_prepare_demographic_state reshapes the compartments to
(compartments, age groups, zones) using the declared demographic
weights, so results are tracked per age group. The framework-loaded
contact matrix is normalised by its spectral radius once here (it is
constant over the run) so the single beta keeps its overall
transmission scale while M only sets the relative age mixing.
Source code in compartment/models/example_spatial_mobility_v2_model/model.py
equation(y, t, p)
¶
SIR derivatives with spatial (travel) and age (contact) mixing.
State rows are shaped (age groups, zones). Space is coupled by the
presence travel matrix T and age by the normalised contact matrix
M; a single scalar beta sets the transmission scale.