FA-65136 / Epidemic compartment models / Open access
Windowed renewal-equation Rt estimate: zero pressure result · case 01
Windows with no prior infections report Rt=0 instead of undefined.
ROOT CAUSE
A zero denominator returns 0 rather than None.
VERIFIED REPAIR
Restore the zero pressure result rule: `if den <= 0: / return None`.
Unsuccessful approach: Returning the case count is not an Rt value.
Case contract
weights[s-1] is the serial-interval weight at lag s>=1 (unnormalised); daily infection pressure Lambda_k = sum_s w_s*I[k-s]/sum of available weights (lags reaching before day 0 dropped); Rt = sum_{k=t-window+1..t} I_k / sum Lambda_k; None if the window reaches day 0, t is out of range or the denominator is zero; result rounded 6.
Why this case matters
Compartmental epidemic calculations drive outbreak forecasts, vaccine targets and hospital planning; a single wrong flow, rate conversion or boundary silently changes every downstream number.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(incidence, weights, t, window):
if window < 1 or t - window + 1 < 1 or t >= len(incidence):
return None
num = 0.0
den = 0.0
for k in range(t - window + 1, t + 1):
pressure = 0.0
mass = 0.0
for s in range(1, len(weights) + 1):
if k - s < 0:
break
pressure += weights[s - 1] * incidence[k - s]
mass += weights[s - 1]
if mass > 0:
pressure /= mass
num += incidence[k]
den += pressure
if den <= 0:
return 0.0
return round(num / den, 6)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)],
[('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('control: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667),
('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667),
('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
('control: long serial interval',
([2, 3, 5, 8, 11, 15, 19, 24, 30, 36], [0.1, 0.15, 0.2, 0.25, 0.3], 9, 4),
2.289916),
('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
('control: long serial interval',
([2, 3, 5, 8, 11, 15, 19, 24, 30, 36], [0.1, 0.15, 0.2, 0.25, 0.3], 9, 4),
2.289916),
('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control: growing outbreak | 2.515432 | 2.515432 | Passed |
| control: declining outbreak | 0.383877 | 0.383877 | Passed |
| control: unnormalised weights | 1.417323 | 1.417323 | Passed |
| control: early window truncation | 2.76 | 2.76 | Passed |
| control: boundary window reaching day 0 | None | None | Passed |
| control: window starting on day 1 | 1.666667 | 1.666667 | Passed |
| regression: zero history | 0.0 | None | Failed |
SHA-256 / c128d8add25197f7f6ae9b793e840bb2a21c92133b47088cc0c3d01ef60312b8
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(incidence, weights, t, window):
if window < 1 or t - window + 1 < 1 or t >= len(incidence):
return None
num = 0.0
den = 0.0
for k in range(t - window + 1, t + 1):
pressure = 0.0
mass = 0.0
for s in range(1, len(weights) + 1):
if k - s < 0:
break
pressure += weights[s - 1] * incidence[k - s]
mass += weights[s - 1]
if mass > 0:
pressure /= mass
num += incidence[k]
den += pressure
if den <= 0:
return round(num, 6)
return round(num / den, 6)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)],
[('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('control: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667),
('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667),
('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
('control: long serial interval',
([2, 3, 5, 8, 11, 15, 19, 24, 30, 36], [0.1, 0.15, 0.2, 0.25, 0.3], 9, 4),
2.289916),
('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
('control: long serial interval',
([2, 3, 5, 8, 11, 15, 19, 24, 30, 36], [0.1, 0.15, 0.2, 0.25, 0.3], 9, 4),
2.289916),
('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control: growing outbreak | 2.515432 | 2.515432 | Passed |
| control: declining outbreak | 0.383877 | 0.383877 | Passed |
| control: unnormalised weights | 1.417323 | 1.417323 | Passed |
| control: early window truncation | 2.76 | 2.76 | Passed |
| control: boundary window reaching day 0 | None | None | Passed |
| control: window starting on day 1 | 1.666667 | 1.666667 | Passed |
| regression: zero history | 5.0 | None | Failed |
SHA-256 / b7f8ed9a77f13e6f3e067adbfbcb4687c1feade67711d2d0ad36e73493cb84e9
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(incidence, weights, t, window):
if window < 1 or t - window + 1 < 1 or t >= len(incidence):
return None
num = 0.0
den = 0.0
for k in range(t - window + 1, t + 1):
pressure = 0.0
mass = 0.0
for s in range(1, len(weights) + 1):
if k - s < 0:
break
pressure += weights[s - 1] * incidence[k - s]
mass += weights[s - 1]
if mass > 0:
pressure /= mass
num += incidence[k]
den += pressure
if den <= 0:
return None
return round(num / den, 6)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)],
[('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('control: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667),
('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667),
('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
('control: long serial interval',
([2, 3, 5, 8, 11, 15, 19, 24, 30, 36], [0.1, 0.15, 0.2, 0.25, 0.3], 9, 4),
2.289916),
('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
('control: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
('control: long serial interval',
([2, 3, 5, 8, 11, 15, 19, 24, 30, 36], [0.1, 0.15, 0.2, 0.25, 0.3], 9, 4),
2.289916),
('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
[('control: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
('control: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
('control: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
('control: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
('regression: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control: growing outbreak | 2.515432 | 2.515432 | Passed |
| control: declining outbreak | 0.383877 | 0.383877 | Passed |
| control: unnormalised weights | 1.417323 | 1.417323 | Passed |
| control: early window truncation | 2.76 | 2.76 | Passed |
| control: boundary window reaching day 0 | None | None | Passed |
| control: window starting on day 1 | 1.666667 | 1.666667 | Passed |
| regression: zero history | None | None | Passed |
SHA-256 / 979828b2511a02ea12a9db56af262af9a9831797cbea0ce79b018f3987b884de
Verification & scope
Deterministic bounded teaching model with a stipulated contract; not a validated scientific or public-health modelling library. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:31.268192+00:00.
Case digest / cacbf470b9bbf2cdda489c9548085d11d87c1a01eab63d5f0889edcd265872b8