broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, sigma, gamma, mu, efficacy):
    if min(beta, sigma, gamma) <= 0 or mu < 0 or not 0 < efficacy <= 1:
        return None
    r0 = beta * sigma / ((sigma + mu) * (gamma + mu))
    if r0 <= 1:
        return [round(r0, 6), 0.0, 0.0]
    threshold = 1 / r0
    coverage = threshold / efficacy
    if coverage > 1:
        coverage = None
    else:
        coverage = round(coverage, 6)
    return [round(r0, 6), round(threshold, 6), coverage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None)],
 [('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('regression: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('regression: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('regression: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('regression: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('regression: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('regression: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, sigma, gamma, mu, efficacy):
    if min(beta, sigma, gamma) <= 0 or mu < 0 or not 0 < efficacy <= 1:
        return None
    r0 = beta * sigma / ((sigma + mu) * (gamma + mu))
    if r0 <= 1:
        return [round(r0, 6), 0.0, 0.0]
    threshold = (r0 - 1) / (r0 + 1)
    coverage = threshold / efficacy
    if coverage > 1:
        coverage = None
    else:
        coverage = round(coverage, 6)
    return [round(r0, 6), round(threshold, 6), coverage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None)],
 [('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('regression: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('regression: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('regression: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('regression: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('regression: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('regression: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), 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)

prompt:
Herd immunity thresholds fall as R0 rises.

R0 = beta*sigma/((sigma+mu)*(gamma+mu)); when R0<=1 return [R0,0.0,0.0]; herd threshold 1-1/R0; critical coverage threshold/efficacy, None if it exceeds 1 (exactly 1 is feasible); values rounded to 6; None for invalid rates or efficacy outside (0,1].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, sigma, gamma, mu, efficacy):
    if min(beta, sigma, gamma) <= 0 or mu < 0 or not 0 < efficacy <= 1:
        return None
    r0 = beta * sigma / ((sigma + mu) * (gamma + mu))
    if r0 <= 1:
        return [round(r0, 6), 0.0, 0.0]
    threshold = 1 - 1 / r0
    coverage = threshold * efficacy
    if coverage > 1:
        coverage = None
    else:
        coverage = round(coverage, 6)
    return [round(r0, 6), round(threshold, 6), coverage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6])],
 [('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), 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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, sigma, gamma, mu, efficacy):
    if min(beta, sigma, gamma) <= 0 or mu < 0 or not 0 < efficacy <= 1:
        return None
    r0 = beta * sigma / ((sigma + mu) * (gamma + mu))
    if r0 <= 1:
        return [round(r0, 6), 0.0, 0.0]
    threshold = 1 - 1 / r0
    coverage = threshold + (1 - efficacy)
    if coverage > 1:
        coverage = None
    else:
        coverage = round(coverage, 6)
    return [round(r0, 6), round(threshold, 6), coverage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6])],
 [('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('regression: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('regression: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('regression: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), 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)

prompt:
Imperfect vaccines appear to need lower coverage than perfect ones.

R0 = beta*sigma/((sigma+mu)*(gamma+mu)); when R0<=1 return [R0,0.0,0.0]; herd threshold 1-1/R0; critical coverage threshold/efficacy, None if it exceeds 1 (exactly 1 is feasible); values rounded to 6; None for invalid rates or efficacy outside (0,1].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, sigma, gamma, mu, efficacy):
    if min(beta, sigma, gamma) <= 0 or mu < 0 or not 0 < efficacy <= 1:
        return None
    r0 = beta * sigma / ((sigma + mu) * (gamma + mu))
    if r0 <= 1:
        return [round(r0, 6), 0.0, 0.0]
    threshold = 1 - 1 / r0
    coverage = threshold / efficacy
    if coverage >= 1:
        coverage = None
    else:
        coverage = round(coverage, 6)
    return [round(r0, 6), round(threshold, 6), coverage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('control: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6])],
 [('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None)],
 [('control: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('control: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('control: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('control: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('control: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('control: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(beta, sigma, gamma, mu, efficacy):
    if min(beta, sigma, gamma) <= 0 or mu < 0 or not 0 < efficacy <= 1:
        return None
    r0 = beta * sigma / ((sigma + mu) * (gamma + mu))
    if r0 <= 1:
        return [round(r0, 6), 0.0, 0.0]
    threshold = 1 - 1 / r0
    coverage = threshold / efficacy
    if round(coverage, 2) >= 1:
        coverage = None
    else:
        coverage = round(coverage, 6)
    return [round(r0, 6), round(threshold, 6), coverage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('control: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6])],
 [('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None)],
 [('control: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), None),
  ('control: invalid negative mortality', (1.0, 0.5, 0.2, -0.1, 0.9), None),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('control: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('control: measles-like high R0', (1.8, 0.1, 0.125, 0.0, 0.95), [14.4, 0.930556, 0.979532]),
  ('control: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: perfect vaccine', (0.9, 0.25, 0.2, 0.001, 1.0), [4.459773, 0.775773, 0.775773]),
  ('control: long latency high mortality', (2.4, 0.05, 0.3, 0.04, 0.85), [3.921569, 0.745, 0.876471])],
 [('control: flu-like moderate R0 with births', (0.5, 0.5, 0.25, 0.02, 0.6), [1.780627, 0.4384, 0.730667]),
  ('regression: exact R0 of two with half efficacy', (2.0, 1.0, 1.0, 0.0, 0.5), [2.0, 0.5, 1.0]),
  ('control: subcritical with mortality', (0.3, 0.2, 0.25, 0.05, 0.9), [0.8, 0.0, 0.0]),
  ('control: boundary R0 exactly one', (1.0, 1.0, 1.0, 0.0, 0.8), [1.0, 0.0, 0.0]),
  ('control: infeasible coverage poor vaccine', (1.2, 0.3, 0.2, 0.01, 0.5), [5.529954, 0.819167, None]),
  ('control: high mortality relative to latency', (3.0, 0.1, 0.5, 0.1, 1.0), [2.5, 0.6, 0.6]),
  ('control: invalid efficacy zero', (1.0, 0.5, 0.2, 0.0, 0.0), 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)

prompt:
A campaign that needs exactly 100% coverage is reported as infeasible.

R0 = beta*sigma/((sigma+mu)*(gamma+mu)); when R0<=1 return [R0,0.0,0.0]; herd threshold 1-1/R0; critical coverage threshold/efficacy, None if it exceeds 1 (exactly 1 is feasible); values rounded to 6; None for invalid rates or efficacy outside (0,1].

split: open-access


prompt:
Expected cases exceed the susceptible pool when several infectives are present.

Expected Reed-Frost: C[t+1] = S[t]*(1-(1-p)**C[t]), S[t+1]=S[t]-C[t+1]; cases are infectious for one generation only; stop early once expected cases fall below 1e-9; return [cases per generation including the index generation rounded to 4, final size including index cases rounded to 4]; None for invalid p or negative counts.

split: open-access


prompt:
Epidemics saturate too quickly because every past case keeps transmitting.

Expected Reed-Frost: C[t+1] = S[t]*(1-(1-p)**C[t]), S[t+1]=S[t]-C[t+1]; cases are infectious for one generation only; stop early once expected cases fall below 1e-9; return [cases per generation including the index generation rounded to 4, final size including index cases rounded to 4]; None for invalid p or negative counts.

split: open-access


prompt:
Generation sizes never decline and the final size exceeds the population.

Expected Reed-Frost: C[t+1] = S[t]*(1-(1-p)**C[t]), S[t+1]=S[t]-C[t+1]; cases are infectious for one generation only; stop early once expected cases fall below 1e-9; return [cases per generation including the index generation rounded to 4, final size including index cases rounded to 4]; None for invalid p or negative counts.

split: open-access


prompt:
Chains are truncated while fractional expected cases would still infect others.

Expected Reed-Frost: C[t+1] = S[t]*(1-(1-p)**C[t]), S[t+1]=S[t]-C[t+1]; cases are infectious for one generation only; stop early once expected cases fall below 1e-9; return [cases per generation including the index generation rounded to 4, final size including index cases rounded to 4]; None for invalid p or negative counts.

split: open-access


prompt:
The final size misses the index cases.

Expected Reed-Frost: C[t+1] = S[t]*(1-(1-p)**C[t]), S[t+1]=S[t]-C[t+1]; cases are infectious for one generation only; stop early once expected cases fall below 1e-9; return [cases per generation including the index generation rounded to 4, final size including index cases rounded to 4]; None for invalid p or negative counts.

split: open-access


prompt:
The chain is cut one generation short of the requested horizon.

Expected Reed-Frost: C[t+1] = S[t]*(1-(1-p)**C[t]), S[t+1]=S[t]-C[t+1]; cases are infectious for one generation only; stop early once expected cases fall below 1e-9; return [cases per generation including the index generation rounded to 4, final size including index cases rounded to 4]; None for invalid p or negative counts.

split: open-access


prompt:
Declaring permanent immunity (0) makes every recovered person susceptible again the next day.

Daily forward-Euler SIRS; waning flow is R/immunity_days back to S (immunity_days 0 means permanent immunity); cumulative incidence sums every S->I flow including reinfections; return [S, I, R, cumulative incidence] rounded to 3.

split: open-access


prompt:
Population shrinks steadily as immunity wanes.

Daily forward-Euler SIRS; waning flow is R/immunity_days back to S (immunity_days 0 means permanent immunity); cumulative incidence sums every S->I flow including reinfections; return [S, I, R, cumulative incidence] rounded to 3.

split: open-access


prompt:
People recovering today already lose immunity in the same step.

Daily forward-Euler SIRS; waning flow is R/immunity_days back to S (immunity_days 0 means permanent immunity); cumulative incidence sums every S->I flow including reinfections; return [S, I, R, cumulative incidence] rounded to 3.

split: open-access


prompt:
Cumulative incidence stops growing, and even falls, once reinfections occur.

Daily forward-Euler SIRS; waning flow is R/immunity_days back to S (immunity_days 0 means permanent immunity); cumulative incidence sums every S->I flow including reinfections; return [S, I, R, cumulative incidence] rounded to 3.

split: open-access


prompt:
The endemic prevalence target is the susceptible equilibrium, so convergence is judged against the wrong level.

SIS with susceptibles pop-I; endemic target pop*(1-1/R0) if R0=beta/gamma>1 else 0; iterate daily Euler I += beta*I*(pop-I)/pop - gamma*I until |I-target| <= tol*pop or max_days steps; return [target rounded 4, days taken, I rounded 4] or None for non-positive beta, gamma or pop.

split: open-access


prompt:
Subcritical infections report a negative endemic level and never converge.

SIS with susceptibles pop-I; endemic target pop*(1-1/R0) if R0=beta/gamma>1 else 0; iterate daily Euler I += beta*I*(pop-I)/pop - gamma*I until |I-target| <= tol*pop or max_days steps; return [target rounded 4, days taken, I rounded 4] or None for non-positive beta, gamma or pop.

split: open-access


prompt:
Prevalence grows exponentially without saturating.

SIS with susceptibles pop-I; endemic target pop*(1-1/R0) if R0=beta/gamma>1 else 0; iterate daily Euler I += beta*I*(pop-I)/pop - gamma*I until |I-target| <= tol*pop or max_days steps; return [target rounded 4, days taken, I rounded 4] or None for non-positive beta, gamma or pop.

split: open-access


prompt:
Convergence takes far longer than required and often hits the day cap.

SIS with susceptibles pop-I; endemic target pop*(1-1/R0) if R0=beta/gamma>1 else 0; iterate daily Euler I += beta*I*(pop-I)/pop - gamma*I until |I-target| <= tol*pop or max_days steps; return [target rounded 4, days taken, I rounded 4] or None for non-positive beta, gamma or pop.

split: open-access


prompt:
Non-converging runs take one more step than allowed.

SIS with susceptibles pop-I; endemic target pop*(1-1/R0) if R0=beta/gamma>1 else 0; iterate daily Euler I += beta*I*(pop-I)/pop - gamma*I until |I-target| <= tol*pop or max_days steps; return [target rounded 4, days taken, I rounded 4] or None for non-positive beta, gamma or pop.

split: open-access


prompt:
Small high-contact groups dominate R0 even when few susceptibles are in them.

K[i][j] = contact[i][j]*sizes[i]/sum(sizes)/gamma[j] (infections in group i caused by one infective in j); R0 is the dominant eigenvalue of the 2x2 K; lead group is the larger component of its eigenvector (ties and decoupled ties to group 0); return [flattened K rounded 6, R0 rounded 6, lead] or None for empty population or non-positive gamma.

split: open-access


prompt:
R0 is wrong whenever the groups recover at different rates.

K[i][j] = contact[i][j]*sizes[i]/sum(sizes)/gamma[j] (infections in group i caused by one infective in j); R0 is the dominant eigenvalue of the 2x2 K; lead group is the larger component of its eigenvector (ties and decoupled ties to group 0); return [flattened K rounded 6, R0 rounded 6, lead] or None for empty population or non-positive gamma.

split: open-access


prompt:
Cross-group transmission is ignored when computing R0.

K[i][j] = contact[i][j]*sizes[i]/sum(sizes)/gamma[j] (infections in group i caused by one infective in j); R0 is the dominant eigenvalue of the 2x2 K; lead group is the larger component of its eigenvector (ties and decoupled ties to group 0); return [flattened K rounded 6, R0 rounded 6, lead] or None for empty population or non-positive gamma.

split: open-access


prompt:
Strong cross-coupling lowers R0 instead of raising it.

K[i][j] = contact[i][j]*sizes[i]/sum(sizes)/gamma[j] (infections in group i caused by one infective in j); R0 is the dominant eigenvalue of the 2x2 K; lead group is the larger component of its eigenvector (ties and decoupled ties to group 0); return [flattened K rounded 6, R0 rounded 6, lead] or None for empty population or non-positive gamma.

split: open-access


prompt:
The leading group flips for asymmetric coupling.

K[i][j] = contact[i][j]*sizes[i]/sum(sizes)/gamma[j] (infections in group i caused by one infective in j); R0 is the dominant eigenvalue of the 2x2 K; lead group is the larger component of its eigenvector (ties and decoupled ties to group 0); return [flattened K rounded 6, R0 rounded 6, lead] or None for empty population or non-positive gamma.

split: open-access


prompt:
Two identical decoupled groups report group 1 as leading.

K[i][j] = contact[i][j]*sizes[i]/sum(sizes)/gamma[j] (infections in group i caused by one infective in j); R0 is the dominant eigenvalue of the 2x2 K; lead group is the larger component of its eigenvector (ties and decoupled ties to group 0); return [flattened K rounded 6, R0 rounded 6, lead] or None for empty population or non-positive gamma.

split: open-access


prompt:
Subcritical pathogens report a large positive overshoot.

Attack fraction z is the positive root of z = 1-exp(-R0*z) found by bisection on (1e-9, 1] until the bracket is narrower than tol; for R0<=1 return [0.0, 0, 0.0]; return [z rounded 6, round(z*pop), overshoot z-(1-1/R0) rounded 6].

split: open-access


prompt:
Bisection converges to the trivial root and reports no epidemic.

Attack fraction z is the positive root of z = 1-exp(-R0*z) found by bisection on (1e-9, 1] until the bracket is narrower than tol; for R0<=1 return [0.0, 0, 0.0]; return [z rounded 6, round(z*pop), overshoot z-(1-1/R0) rounded 6].

split: open-access


prompt:
The attack fraction never exceeds the herd-immunity threshold (no overshoot).

Attack fraction z is the positive root of z = 1-exp(-R0*z) found by bisection on (1e-9, 1] until the bracket is narrower than tol; for R0<=1 return [0.0, 0, 0.0]; return [z rounded 6, round(z*pop), overshoot z-(1-1/R0) rounded 6].

split: open-access


prompt:
Final sizes are only accurate to three decimals regardless of the requested tolerance.

Attack fraction z is the positive root of z = 1-exp(-R0*z) found by bisection on (1e-9, 1] until the bracket is narrower than tol; for R0<=1 return [0.0, 0, 0.0]; return [z rounded 6, round(z*pop), overshoot z-(1-1/R0) rounded 6].

split: open-access


prompt:
Expected case counts are one lower than the nearest integer.

Attack fraction z is the positive root of z = 1-exp(-R0*z) found by bisection on (1e-9, 1] until the bracket is narrower than tol; for R0<=1 return [0.0, 0, 0.0]; return [z rounded 6, round(z*pop), overshoot z-(1-1/R0) rounded 6].

split: open-access


prompt:
Overshoot values are large even for mild epidemics.

Attack fraction z is the positive root of z = 1-exp(-R0*z) found by bisection on (1e-9, 1] until the bracket is narrower than tol; for R0<=1 return [0.0, 0, 0.0]; return [z rounded 6, round(z*pop), overshoot z-(1-1/R0) rounded 6].

split: open-access


prompt:
The campaign starts one day late.

Each day from day index start_day (inclusive), dose=min(doses_per_day, S) is given to susceptibles before transmission; dose*efficacy moves S->V; failed vaccinees stay in S; mixing uses the full pop; return [S, I, R, V, doses administered] rounded to 3.

split: open-access


prompt:
Susceptibles go negative once supply exceeds the remaining pool.

Each day from day index start_day (inclusive), dose=min(doses_per_day, S) is given to susceptibles before transmission; dose*efficacy moves S->V; failed vaccinees stay in S; mixing uses the full pop; return [S, I, R, V, doses administered] rounded to 3.

split: open-access


prompt:
Vaccine failures vanish from the population.

Each day from day index start_day (inclusive), dose=min(doses_per_day, S) is given to susceptibles before transmission; dose*efficacy moves S->V; failed vaccinees stay in S; mixing uses the full pop; return [S, I, R, V, doses administered] rounded to 3.

split: open-access


prompt:
Same-day vaccinations do not reduce that day's transmission.

Each day from day index start_day (inclusive), dose=min(doses_per_day, S) is given to susceptibles before transmission; dose*efficacy moves S->V; failed vaccinees stay in S; mixing uses the full pop; return [S, I, R, V, doses administered] rounded to 3.

split: open-access


prompt:
Administered doses match protected people rather than shots given.

Each day from day index start_day (inclusive), dose=min(doses_per_day, S) is given to susceptibles before transmission; dose*efficacy moves S->V; failed vaccinees stay in S; mixing uses the full pop; return [S, I, R, V, doses administered] rounded to 3.

split: open-access


prompt:
Vaccination makes remaining susceptibles meet infectives more often.

Each day from day index start_day (inclusive), dose=min(doses_per_day, S) is given to susceptibles before transmission; dose*efficacy moves S->V; failed vaccinees stay in S; mixing uses the full pop; return [S, I, R, V, doses administered] rounded to 3.

split: open-access


prompt:
Pressure on children uses the contacts adults report making with children.

lambda[a] = beta*susceptibility[a]*sum_b contacts[a][b]*infected[b]/sizes[b] (groups with zero size skipped); expected new infections susceptible[a]*(1-exp(-lambda[a])); return [lambdas rounded 6, new infections rounded 4, total rounded 4].

split: open-access


prompt:
Small age bands receive inflated force of infection from large ones.

lambda[a] = beta*susceptibility[a]*sum_b contacts[a][b]*infected[b]/sizes[b] (groups with zero size skipped); expected new infections susceptible[a]*(1-exp(-lambda[a])); return [lambdas rounded 6, new infections rounded 4, total rounded 4].

split: open-access


prompt:
Groups with reduced susceptibility are infected at full rate.

lambda[a] = beta*susceptibility[a]*sum_b contacts[a][b]*infected[b]/sizes[b] (groups with zero size skipped); expected new infections susceptible[a]*(1-exp(-lambda[a])); return [lambdas rounded 6, new infections rounded 4, total rounded 4].

split: open-access


prompt:
Expected infections include people who are already infected or immune.

lambda[a] = beta*susceptibility[a]*sum_b contacts[a][b]*infected[b]/sizes[b] (groups with zero size skipped); expected new infections susceptible[a]*(1-exp(-lambda[a])); return [lambdas rounded 6, new infections rounded 4, total rounded 4].

split: open-access


prompt:
Later age groups accumulate the pressure computed for earlier groups.

lambda[a] = beta*susceptibility[a]*sum_b contacts[a][b]*infected[b]/sizes[b] (groups with zero size skipped); expected new infections susceptible[a]*(1-exp(-lambda[a])); return [lambdas rounded 6, new infections rounded 4, total rounded 4].

split: open-access


broken_source:
"""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(0, len(weights)):
            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 = [[('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
 [('regression: 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),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: 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: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
 [('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: 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),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)]]
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)

source:
"""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)):
            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 = [[('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
 [('regression: 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),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: 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: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)],
 [('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: 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),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: flat incidence', ([10, 10, 10, 10, 10, 10], [0.5, 0.3, 0.2], 5, 3), 1.0)]]
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)

prompt:
Same-day cases are counted as their own infectors.

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.

split: open-access


broken_source:
"""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]
        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),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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),
  ('regression: 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)],
 [('regression: 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),
  ('regression: 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),
  ('control: 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)],
 [('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
  ('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),
  ('control: 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: 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),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
  ('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),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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),
  ('regression: 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)]]
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)

source:
"""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]
        pressure /= sum(weights)
        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),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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),
  ('regression: 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)],
 [('regression: 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),
  ('regression: 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),
  ('control: 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)],
 [('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
  ('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),
  ('control: 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: 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),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
  ('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),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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),
  ('regression: 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)]]
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)

prompt:
Early-window Rt is biased upward and unnormalised weights distort all estimates.

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.

split: open-access


broken_source:
"""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, t):
        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 = [[('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)],
 [('regression: 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),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: 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),
  ('control: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: 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),
  ('control: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: 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)

source:
"""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):
        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 = [[('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None)],
 [('regression: 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),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: 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),
  ('control: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: 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),
  ('control: zero history', ([0, 0, 0, 5, 7], [0.6, 0.4], 3, 2), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('control: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('control: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('regression: single day window', ([10, 12, 15, 17, 22, 25], [0.25, 0.5, 0.25], 5, 1), 1.408451),
  ('regression: 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)],
 [('regression: growing outbreak', ([1, 2, 4, 7, 12, 20, 33, 50, 80], [0.2, 0.5, 0.3], 8, 3), 2.515432),
  ('regression: declining outbreak', ([90, 80, 60, 45, 30, 20, 12, 8], [0.3, 0.4, 0.3], 7, 2), 0.383877),
  ('regression: unnormalised weights', ([5, 6, 8, 9, 11, 14, 16], [2, 3, 1], 6, 2), 1.417323),
  ('regression: 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: t out of range', ([4, 6, 9], [0.5, 0.5], 3, 1), None),
  ('control: 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)

prompt:
Rt lags one day behind and excludes the most recent incidence.

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.

split: open-access


broken_source:
"""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 < 0 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),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667)],
 [('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: 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),
  ('control: 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)],
 [('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: 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),
  ('control: 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),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('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),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667)]]
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)

source:
"""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 < 2 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),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667)],
 [('control: early window truncation', ([3, 5, 9, 14, 20], [0.1, 0.2, 0.3, 0.4], 3, 2), 2.76),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: 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),
  ('control: 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)],
 [('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: 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),
  ('control: 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),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('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),
  ('regression: boundary window reaching day 0', ([4, 6, 9, 12], [0.5, 0.5], 2, 3), None),
  ('regression: window starting on day 1', ([4, 6, 9, 12], [0.5, 0.5], 2, 2), 1.666667),
  ('regression: single day window at day 1', ([3, 5, 8], [1.0], 1, 1), 1.666667)]]
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)

prompt:
A window touching day 0 is estimated using a day with no infection history.

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.

split: open-access


broken_source:
"""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)

source:
"""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)

prompt:
Windows with no prior infections report Rt=0 instead of undefined.

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.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(counts, generation_mean, latent_fraction):
    pts = [(d, math.log(c)) for d, c in enumerate([c for c in counts if c > 0])]
    if len(pts) < 2:
        return None
    n = len(pts)
    mx = sum(d for d, _ in pts) / n
    my = sum(y for _, y in pts) / n
    sxx = sum((d - mx) ** 2 for d, _ in pts)
    sxy = sum((d - mx) * (y - my) for d, y in pts)
    r = sxy / sxx
    doubling = round(math.log(2) / r, 4) if r > 0 else None
    tl = latent_fraction * generation_mean
    ti = generation_mean - tl
    rep = (1 + r * tl) * (1 + r * ti)
    return [round(r, 6), doubling, round(rep, 6)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: noisy growth', ([3, 5, 6, 10, 14, 19, 30], 5.0, 0.4), [0.372323, 1.8617, 3.693365]),
  ('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('regression: declining', ([50, 41, 30, 26, 18, 15], 4.0, 0.3), [-0.246645, None, 0.217822]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592])],
 [('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592]),
  ('regression: no latency', ([10, 13, 17, 22, 28], 5.0, 0.0), [0.258533, 2.6811, 2.292666]),
  ('regression: two points', ([5, 9], 4.5, 0.25), [0.587787, 1.1792, 4.956834])],
 [('regression: noisy growth', ([3, 5, 6, 10, 14, 19, 30], 5.0, 0.4), [0.372323, 1.8617, 3.693365]),
  ('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('regression: declining', ([50, 41, 30, 26, 18, 15], 4.0, 0.3), [-0.246645, None, 0.217822]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592]),
  ('regression: no latency', ([10, 13, 17, 22, 28], 5.0, 0.0), [0.258533, 2.6811, 2.292666]),
  ('regression: two points', ([5, 9], 4.5, 0.25), [0.587787, 1.1792, 4.956834])],
 [('regression: noisy growth', ([3, 5, 6, 10, 14, 19, 30], 5.0, 0.4), [0.372323, 1.8617, 3.693365]),
  ('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('regression: declining', ([50, 41, 30, 26, 18, 15], 4.0, 0.3), [-0.246645, None, 0.217822]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592])],
 [('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592]),
  ('regression: no latency', ([10, 13, 17, 22, 28], 5.0, 0.0), [0.258533, 2.6811, 2.292666]),
  ('regression: two points', ([5, 9], 4.5, 0.25), [0.587787, 1.1792, 4.956834])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(counts, generation_mean, latent_fraction):
    pts = [(d, math.log(c + 1)) for d, c in enumerate(counts)]
    if len(pts) < 2:
        return None
    n = len(pts)
    mx = sum(d for d, _ in pts) / n
    my = sum(y for _, y in pts) / n
    sxx = sum((d - mx) ** 2 for d, _ in pts)
    sxy = sum((d - mx) * (y - my) for d, y in pts)
    r = sxy / sxx
    doubling = round(math.log(2) / r, 4) if r > 0 else None
    tl = latent_fraction * generation_mean
    ti = generation_mean - tl
    rep = (1 + r * tl) * (1 + r * ti)
    return [round(r, 6), doubling, round(rep, 6)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: noisy growth', ([3, 5, 6, 10, 14, 19, 30], 5.0, 0.4), [0.372323, 1.8617, 3.693365]),
  ('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('regression: declining', ([50, 41, 30, 26, 18, 15], 4.0, 0.3), [-0.246645, None, 0.217822]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592])],
 [('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592]),
  ('regression: no latency', ([10, 13, 17, 22, 28], 5.0, 0.0), [0.258533, 2.6811, 2.292666]),
  ('regression: two points', ([5, 9], 4.5, 0.25), [0.587787, 1.1792, 4.956834])],
 [('regression: noisy growth', ([3, 5, 6, 10, 14, 19, 30], 5.0, 0.4), [0.372323, 1.8617, 3.693365]),
  ('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('regression: declining', ([50, 41, 30, 26, 18, 15], 4.0, 0.3), [-0.246645, None, 0.217822]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592]),
  ('regression: no latency', ([10, 13, 17, 22, 28], 5.0, 0.0), [0.258533, 2.6811, 2.292666]),
  ('regression: two points', ([5, 9], 4.5, 0.25), [0.587787, 1.1792, 4.956834])],
 [('regression: noisy growth', ([3, 5, 6, 10, 14, 19, 30], 5.0, 0.4), [0.372323, 1.8617, 3.693365]),
  ('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('regression: declining', ([50, 41, 30, 26, 18, 15], 4.0, 0.3), [-0.246645, None, 0.217822]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592])],
 [('regression: with reporting gap zero', ([2, 4, 0, 9, 13, 0, 30], 6.0, 0.5), [0.437065, 1.5859, 5.341617]),
  ('control: flat', ([7, 7, 7, 7], 5.0, 0.5), [0.0, None, 1.0]),
  ('regression: too few positives', ([0, 0, 4, 0], 5.0, 0.5), None),
  ('regression: exact doubling per day', ([1, 2, 4, 8, 16], 3.0, 0.5), [0.693147, 1.0, 4.160461]),
  ('regression: leading zeros', ([0, 0, 1, 3, 5, 12], 7.0, 0.6), [0.796555, 0.8702, 14.037592]),
  ('regression: no latency', ([10, 13, 17, 22, 28], 5.0, 0.0), [0.258533, 2.6811, 2.292666]),
  ('regression: two points', ([5, 9], 4.5, 0.25), [0.587787, 1.1792, 4.956834])]]
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)

prompt:
Growth rates are overstated whenever zero-count days are dropped.

r is the least-squares slope of ln(count) against day index over days with positive counts (original day indices kept); doubling time ln2/r only when r>0 else None; latent time Tl=latent_fraction*Tg, infectious time Ti=Tg-Tl, R=(1+r*Tl)*(1+r*Ti); return [r rounded 6, doubling rounded 4, R rounded 6]; None with fewer than two positive days.

split: open-access