Example Disease with Stochasticity¶
A stochastic SIR model for an example disease
ExampleStochasticModel(config)
¶
Bases: Model
A stochastic SIR compartmental model for Example Disease.
Setting STOCHASTIC = True tells the SimulationManager to integrate with
fixed-step Euler instead of the adaptive ODE solver, and to run several
trajectories and report a median with an interval band.
equation() is written by hand using tau-leaping: the number of
infection and recovery events each step is drawn from a Poisson distribution
whose mean equals the deterministic rate. This adds demographic randomness
while keeping the same expected trajectory as the ODE version.
Initialize the model and seed its PRNG for stochastic draws.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
Validated simulation configuration. A |
required |
Source code in compartment/models/example_stochastic_model/model.py
define_parameters(schema)
classmethod
¶
Declare the model's compartments, transmission edges, and parameters.
Called once by the framework to build the model schema, from which the
config validator and parameter set are generated. Also declares the
aggregate I_total / R_total cumulative compartments and the
stochastic run count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
ParameterSchemaBuilder
|
Schema builder to populate with model info, metadata, compartments, transmission edges, disease parameters, and the intervention. |
required |
Source code in compartment/models/example_stochastic_model/model.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
get_initial_population(admin_zones, compartment_list, **kwargs)
classmethod
¶
Seed the initial infected across the two infectious compartments.
The base implementation seeds a single I compartment, which this
model does not have. Infectious individuals are split between A
(asymptomatic) and Sym (symptomatic) using the schema's default
asymptomatic fraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
admin_zones
|
list[dict]
|
Admin zone dicts providing |
required |
compartment_list
|
list[str]
|
Ordered compartment names, used for column indexing. |
required |
**kwargs
|
Any
|
Additional keyword arguments (unused). |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Initial populations of shape
|
Source code in compartment/models/example_stochastic_model/model.py
prepare_initial_state()
¶
Return the initial compartment populations for the solver.
Returns:
| Type | Description |
|---|---|
ndarray
|
Population matrix (compartments x admin zones) used as the solver's initial state. |
Source code in compartment/models/example_stochastic_model/model.py
equation(y, t, p)
¶
Tau-leaping stochastic step with two infectious compartments.
Returns the per-step change (delta); the Euler integrator applies
y_{t+1} = y_t + dt * equation(...). Infection and recovery counts are
Poisson draws around the deterministic rates. Asymptomatic (A) and
symptomatic (Sym) cases transmit at their own rates (beta and
beta_sym) and both feed a single force of infection; new cases are
then split by asymptomatic_fraction. Each compartment also recovers
on its own clock (gamma and gamma_sym). The two compartments are
combined into one "Infected" curve for graphing via
COMPARTMENT_DELTA_GROUPING.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Current compartment values, ordered by
|
required |
t
|
float
|
Current time in days since the simulation start date. |
required |
p
|
tuple
|
Packed parameter tuple, unpacked via |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Stacked per-compartment deltas for this step. |
Source code in compartment/models/example_stochastic_model/model.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |