FAILURE MAP
← Case archive

FA-65281 / Epidemic compartment models / Open access

Household secondary attack rate: pooling method · case 01

The overall SAR weights each household size equally.

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

ROOT CAUSE

Stratum rates are averaged instead of pooling secondaries over persons at risk.

VERIFIED REPAIR

Restore the pooling method rule: `overall = round(num / den, 6) if den else None`.

Unsuccessful approach: Secondary-to-uninfected odds are reported instead of a proportion.

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(size, (0, 0))
        by_size[size] = (a + secondary, b + at_risk)
    overall = round(sum(a / b for a, b in by_size.values()) / len(by_size), 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.5, [[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]]]Failed
regression: two index cases[0.472222, [[3, 0.5], [6, 0.444444]]][0.454545, [[3, 0.5], [6, 0.444444]]]Failed
regression: no index household[0.666667, [[3, 1.0], [4, 0.333333]]][0.6, [[3, 1.0], [4, 0.333333]]]Failed
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 / 34eb1b232d0b7395cf9256d465dcb7f3af64189b385fb9141971b1e08d94f7c0

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, (0, 0))
        by_size[size] = (a + secondary, b + at_risk)
    overall = round(num / (den - num), 6) if den > num 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.8, [[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]]]Failed
regression: two index cases[0.833333, [[3, 0.5], [6, 0.444444]]][0.454545, [[3, 0.5], [6, 0.444444]]]Failed
regression: no index household[1.5, [[3, 1.0], [4, 0.333333]]][0.6, [[3, 1.0], [4, 0.333333]]]Failed
regression: single-person household[None, [[2, 1.0]]][1.0, [[2, 1.0]]]Failed
regression: data error secondary too high[1.0, [[3, 0.5], [5, 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 / 87d2b78b5623c7db3a9086e356ab4ea97fb5d27f09676c9c1eb9a89981b12978

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.631616+00:00.

Case digest / 80a1105a0b83f5e34f0aeab7bec474c3b5015231beb0c289bbb81582204fc6eb