import json
from pathlib import Path
import matplotlib;matplotlib.use('Agg')
import matplotlib.pyplot as plt
R=Path(__file__).resolve().parents[1];O=R/'results/l74';rows=json.loads((O/'results.json').read_text())['records'];names=['baseline','low_all','repeat_support','high_support'];labels=['Baseline','Admit all weak','Repeat support','High-quality support'];cols=['#367f70','#ca7754','#7059a5','#af9060'];fig,ax=plt.subplots(1,2,figsize=(11,4));ax[0].bar(labels,[sum(r['policies'][n]['scores']['30'] for r in rows) for n in names],color=cols);ax[0].set_ylim(0,70);ax[0].set_ylabel('Top-30 matched source polygons');ax[1].bar(labels,[sum(r['policies'][n]['kept'] for r in rows) for n in names],color=cols);ax[1].set_ylabel('Retained candidate masks');
for a in ax:a.tick_params(axis='x',labelrotation=12)
fig.tight_layout();fig.savefig(O/'support-comparison.png',dpi=140);plt.close(fig);trs=''.join(f'<tr><th>{label}</th><td>{sum(r["policies"][name]["admitted"] for r in rows)}</td><td>{sum(r["policies"][name]["kept"] for r in rows)}</td>'+''.join(f'<td>{sum(r["policies"][name]["scores"][b] for r in rows)}</td>' for b in ('10','30','60','all'))+'</tr>' for label,name in zip(labels,names))
(O/'index.html').write_text(f'''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>L74 weak mask support</title><style>body{{font:16px/1.55 system-ui;max-width:1050px;margin:2em auto;padding:0 1em;color:#18342f}}img{{max-width:100%}}a{{color:#006b59}}table{{border-collapse:collapse}}td,th{{border:1px solid #b8ccc0;padding:.5em;text-align:left}}.box{{background:#fff2d6;padding:1em}}</style><a href="/results/board.html">Research board</a><h1>L74: Can repeatable support rescue a weak mask?</h1><p class="box">Development replay of 40 previously viewed scenes. The single additional match was already known from R86, so this is hypothesis generation, not independent validation.</p><p>Weak masks have model quality 0.45–0.60. One policy admits a weak mask if a different point-prompt mask with quality at least 0.60 overlaps it at IoU ≥0.5. On these fields it matched 53/70 source polygons at top 30, versus 52/70 for baseline, while retaining 1,417 masks versus 1,343 baseline and 1,575 when all weak masks are admitted. It recovers the same single developmental source match, not a general improvement estimate.</p><img src="support-comparison.png" alt="Chart comparing matched source polygons and retained masks"><table><thead><tr><th>Policy</th><th>Admitted before NMS</th><th>Retained after NMS</th><th>Top 10</th><th>Top 30</th><th>Top 60</th><th>All</th></tr></thead><tbody>{trs}</tbody></table><p>Repeat support accepts any other candidate with quality ≥0.45; high-quality support requires the other candidate to have quality ≥0.60. Support is computed without reference labels. Different overlapping diatoms may produce high-IoU masks: a support link does not establish object identity. All admitted streams still pass through 0.8 IoU NMS, which may suppress real overlap alternatives. Unmatched proposals are not verified false positives, and source sample independence and complete labeling remain unknown.</p><h2>Diagnostic example</h2><p>The recovered example uses a reference polygon for retrospective diagnosis; this correspondence was not used to admit the candidate.</p><img src="/results/r86/filter-miss.png" alt="Reference, baseline proposals and the previously filtered candidate"><p><a href="/research/L74.md">Research note</a> · <a href="protocol.json">Frozen protocol</a> · <a href="results.json">Support links, ranks and scores</a> · <a href="/research/l74_verify.py">Replay verifier</a> · <a href="/results/r86/">Earlier filter audit</a></p></html>''')
