chc.epidemic¶
Stability tier: experimental.
Scientific flagship: SIR epidemic control — flatten the curve down to a hospital capacity.
Nonlinear known dynamics (compartmental SIR) with an NPI control u that scales transmission
beta -> beta*(1-u). Optimal control holds infections at a hospital-capacity threshold with
minimal intervention, the threshold a steep penalty rather than a hard limit — optimal control on
a classic nonlinear population model (the Bazykin /
Riznichenko / Marchuk-immunology lineage). In observational logs the intervention effect is
confounded (policy reacts to case counts); here the plant is the true system and control is planned
against it.
SIRDynamics
¶
Bases: Module
Normalised SIR; state [S, I], control u in [0,1] scales beta -> beta*(1-u).
epidemic_cost(model, x0, us, dt, i_max, w_npi, w_peak)
¶
Intervention effort plus a squared penalty for exceeding the capacity i_max.
optimal_npi(model, x0, dt, horizon, i_max, u_max=0.9, w_npi=1.0, w_peak=10000.0, steps=10000, lr0=0.5)
¶
Open-loop optimal NPI: the least intervention that holds I at i_max.
Projected gradient on epidemic_cost, which prices the capacity as w_peak times the
squared excess, not as a hard limit, so the peak can end a little above i_max. The descent
stops where 30 halvings of the step find no cost lower by 1e-12, or after steps steps,
so where it stops depends on the precision. At R0 = 6 a float32 descent stops after 2,887
steps, the peak at 0.1005 against 0.1; a float64 one runs all 10_000, to 0.1004. 400 steps
leave the cost 2 % above either.