FAILURE MAP
← Case archive

FA-65286 / Epidemic compartment models / Open access

Household secondary attack rate: stratum key · case 01

Size strata mix households of different sizes that share an at-risk count.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The table is keyed by at-risk members instead of household size.

VERIFIED REPAIR

Restore the stratum key rule: `a, b = by_size.get(size, (0, 0)) / by_size[size] =`.

Unsuccessful approach: Keying by size-1 mislabels every stratum.

Case contract

Each household is [size, index_cases, secondary]; skip households without an index case, without members at risk, or with more secondaries than at-risk members; pooled SAR = sum secondary / sum (size-index); per-size table sorted by size ascending; return [pooled rounded 6 or None, table].

Why this case matters

Compartmental epidemic calculations drive outbreak forecasts, vaccine targets and hospital planning; a single wrong flow, rate conversion or boundary silently changes every downstream number.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(households):
    num = 0
    den = 0
    by_size = {}
    for size, index, secondary in households:
        at_risk = size - index
        if index < 1 or at_risk <= 0:
            continue
        if secondary > at_risk:
            continue
        num += secondary
        den += at_risk
        a, b = by_size.get(at_risk, (0, 0))
        by_size[at_risk] = (a + secondary, b + at_risk)
    overall = round(num / den, 6) if den else None
    table = [[k, round(a / b, 6)] for k, (a, b) in sorted(by_size.items())]
    return [overall, table]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression: mixed households[0.444444, [[1, 1.0], [2, 0.0], [3, 0.5]]][0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]Failed
regression: two index cases[0.454545, [[2, 0.5], [4, 0.75], [5, 0.2]]][0.454545, [[3, 0.5], [6, 0.444444]]]Failed
regression: no index household[0.6, [[2, 1.0], [3, 0.333333]]][0.6, [[3, 1.0], [4, 0.333333]]]Failed
regression: single-person household[1.0, [[1, 1.0]]][1.0, [[2, 1.0]]]Failed
regression: data error secondary too high[0.5, [[2, 0.5], [4, 0.5]]][0.5, [[3, 0.5], [5, 0.5]]]Failed
control: empty input[None, []][None, []]Passed
control: all index[None, []][None, []]Passed

SHA-256 / a3cb7a32815b64105f6e57e83b18e03c47b55571ed87d695abe1600d4c9be6e1

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(households):
    num = 0
    den = 0
    by_size = {}
    for size, index, secondary in households:
        at_risk = size - index
        if index < 1 or at_risk <= 0:
            continue
        if secondary > at_risk:
            continue
        num += secondary
        den += at_risk
        a, b = by_size.get(size - 1, (0, 0))
        by_size[size - 1] = (a + secondary, b + at_risk)
    overall = round(num / den, 6) if den else None
    table = [[k, round(a / b, 6)] for k, (a, b) in sorted(by_size.items())]
    return [overall, table]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression: mixed households[0.444444, [[1, 1.0], [2, 0.0], [3, 0.666667], [4, 0.333333]]][0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]Failed
regression: two index cases[0.454545, [[2, 0.5], [5, 0.444444]]][0.454545, [[3, 0.5], [6, 0.444444]]]Failed
regression: no index household[0.6, [[2, 1.0], [3, 0.333333]]][0.6, [[3, 1.0], [4, 0.333333]]]Failed
regression: single-person household[1.0, [[1, 1.0]]][1.0, [[2, 1.0]]]Failed
regression: data error secondary too high[0.5, [[2, 0.5], [4, 0.5]]][0.5, [[3, 0.5], [5, 0.5]]]Failed
control: empty input[None, []][None, []]Passed
control: all index[None, []][None, []]Passed

SHA-256 / 14781e156c844c9f66efdb2641ae2abed5c92eb52d04a6ed1b8e18ea6e80e949

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(households):
    num = 0
    den = 0
    by_size = {}
    for size, index, secondary in households:
        at_risk = size - index
        if index < 1 or at_risk <= 0:
            continue
        if secondary > at_risk:
            continue
        num += secondary
        den += at_risk
        a, b = by_size.get(size, (0, 0))
        by_size[size] = (a + secondary, b + at_risk)
    overall = round(num / den, 6) if den else None
    table = [[k, round(a / b, 6)] for k, (a, b) in sorted(by_size.items())]
    return [overall, table]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: two index cases',
   ([[6, 2, 3], [6, 1, 1], [3, 1, 1]],),
   [0.454545, [[3, 0.5], [6, 0.444444]]]),
  ('regression: no index household', ([[4, 0, 0], [4, 1, 1], [3, 1, 2]],), [0.6, [[3, 1.0], [4, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []])],
 [('regression: mixed households',
   ([[4, 1, 2], [3, 1, 0], [5, 2, 1], [2, 1, 1]],),
   [0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]),
  ('regression: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('regression: data error secondary too high',
   ([[3, 1, 4], [3, 1, 1], [5, 1, 2]],),
   [0.5, [[3, 0.5], [5, 0.5]]]),
  ('control: empty input', ([],), [None, []]),
  ('regression: descending sizes',
   ([[7, 1, 3], [2, 1, 0], [4, 1, 1]],),
   [0.4, [[2, 0.0], [4, 0.333333], [7, 0.5]]]),
  ('control: all index', ([[2, 2, 0], [3, 3, 0]],), [None, []]),
  ('regression: large and small',
   ([[8, 1, 6], [2, 1, 1], [8, 2, 1], [3, 1, 0]],),
   [0.5, [[2, 1.0], [3, 0.0], [8, 0.538462]]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression: mixed households[0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]][0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]Passed
regression: two index cases[0.454545, [[3, 0.5], [6, 0.444444]]][0.454545, [[3, 0.5], [6, 0.444444]]]Passed
regression: no index household[0.6, [[3, 1.0], [4, 0.333333]]][0.6, [[3, 1.0], [4, 0.333333]]]Passed
regression: single-person household[1.0, [[2, 1.0]]][1.0, [[2, 1.0]]]Passed
regression: data error secondary too high[0.5, [[3, 0.5], [5, 0.5]]][0.5, [[3, 0.5], [5, 0.5]]]Passed
control: empty input[None, []][None, []]Passed
control: all index[None, []][None, []]Passed

SHA-256 / ff67cdbb29c1e87a3d31bcb12e0b407e0de0e54f60a683c85c0f47e51cb3a9d3

Verification & scope

Deterministic bounded teaching model with a stipulated contract; not a validated scientific or public-health modelling library. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:47:32.633174+00:00.

Case digest / 59e75c664f4c39ae339ad68f2aad07861738ce03f21f5c66acb0bfe0694b130b