FAILURE MAP
← Case archive

FA-65291 / Epidemic compartment models / Open access

Household secondary attack rate: stratum ordering · case 01

The size table follows input order.

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

ROOT CAUSE

The per-size table is emitted in insertion order.

THE FAILURE

The per-size table is emitted in insertion order.

Unsuccessful approach: Sorting descending violates the ascending contract.

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(num / den, 6) if den else None
    table = [[k, round(a / b, 6)] for k, (a, b) in 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]]]),
  ('control: 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]]]),
  ('control: 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]]]),
  ('control: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('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: 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]]]),
  ('control: 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, [[4, 0.666667], [3, 0.0], [5, 0.333333], [2, 1.0]]][0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]Failed
regression: two index cases[0.454545, [[6, 0.444444], [3, 0.5]]][0.454545, [[3, 0.5], [6, 0.444444]]]Failed
regression: no index household[0.6, [[4, 0.333333], [3, 1.0]]][0.6, [[3, 1.0], [4, 0.333333]]]Failed
control: 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 / 646bd26aa6132f7e1e8763ad108be26c54d3c5743a629e08eebb8e4a788ac93a

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, 6) if den else None
    table = [[k, round(a / b, 6)] for k, (a, b) in sorted(by_size.items(), key=lambda kv: -kv[0])]
    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]]]),
  ('control: 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]]]),
  ('control: 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]]]),
  ('control: single-person household', ([[1, 1, 0], [2, 1, 1]],), [1.0, [[2, 1.0]]]),
  ('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: 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]]]),
  ('control: 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, [[5, 0.333333], [4, 0.666667], [3, 0.0], [2, 1.0]]][0.444444, [[2, 1.0], [3, 0.0], [4, 0.666667], [5, 0.333333]]]Failed
regression: two index cases[0.454545, [[6, 0.444444], [3, 0.5]]][0.454545, [[3, 0.5], [6, 0.444444]]]Failed
regression: no index household[0.6, [[4, 0.333333], [3, 1.0]]][0.6, [[3, 1.0], [4, 0.333333]]]Failed
control: single-person household[1.0, [[2, 1.0]]][1.0, [[2, 1.0]]]Passed
regression: data error secondary too high[0.5, [[5, 0.5], [3, 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 / e5035202e67ddf0781a34e050089efa5239d4bcb7742dfe34cd71e2c5a7b30aa

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 7 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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

Case digest / 70c77e8b9c124ae58059d210684fbdf91e068ba8b041cdc9733c6143bc54a410