"""Render synthetic overlap matching ambiguity sensitivity audit."""
import json
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];OUT=ROOT/'results/r70';r=json.loads((OUT/'results.json').read_text())['records'];rows=''
for ds in ('r62','r64','r69'):
 x=[a for a in r if a['dataset']==ds]
 for stage in ('pre_final','final'):
  vals=[sum(a['metrics'][stage][k] for a in x) for k in ('ordinary','pair_iou_below_0.8','pair_iou_below_0.95','pair_iou_below_0.99')];rows+=f'<tr><td>{ds}</td><td>{stage}</td>'+''.join(f'<td>{v}</td>' for v in vals)+'</tr>'
page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Overlapping-instance metric audit</title><style>body{font:16px/1.5 system-ui;background:#f3f6ef;color:#203a38}main{max-width:1250px;margin:auto;padding:24px}.notice{background:#fff2d6;padding:16px}table{border-collapse:collapse}th,td{padding:8px;border:1px solid #aaa}img{width:100%}</style><main><nav><a href="/results/performance/">Performance monitor</a> · <a href="/research/R70.md">Research note</a></nav><h1>Do duplicate-like masks inflate overlap scores?</h1><p class="notice">Posthoc sensitivity analysis of 27 synthetic scenes. Pairwise prediction-IoU thresholds are diagnostic assumptions, not biological truth: two genuine overlapping specimens can themselves have nearly identical mask geometry. Do not use these results as an automatic discard rule or a measure of real human-level performance.</p><p>Each scene contains two synthetic target masks. We compare conventional one-to-one matching at target IoU ≥0.5 with a stricter test: for a two-target assignment to count as two, at least one pair of different predictions must match the targets while having mutual IoU below a stated threshold. Pre-final candidates combine individually suppressed detector, CLAHE and contrast streams; final candidates have undergone IoU ≥0.8 mixed-stream NMS. Consequently the final IoU &lt;0.8 agreement is expected by construction, not evidence that suppression preserved correct biological objects.</p><table><tr><th>Source scenes</th><th>Candidate stage</th><th>Ordinary / 18</th><th>Pair IoU &lt;0.8</th><th>Pair IoU &lt;0.95</th><th>Pair IoU &lt;0.99</th></tr>ROWS</table><p>Across all 27 scenes, ordinary pre-final matching scored 31/54; requiring a matching prediction pair with mutual IoU &lt;0.8 or &lt;0.95 scored 30/54. This is one synthetic case, not a population frequency. The <a href="/results/l58/">illustrated ambiguity</a> contains two predictions at IoU 0.971 that both match each target; that exact pair fails the stricter 0.8 and 0.95 diagnostics. Final lists score 30/54 under all tested thresholds.</p><img src="/results/l58/ambiguity.jpg" alt="Two highly overlapping synthetic targets and two near-identical predictions"><p><a href="protocol.json">Audit protocol</a> · <a href="results.json">Scene-level assignment diagnostics</a>. Foreground source: Gündüz et al., <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>. Source scene and original candidate archives are linked in the JSON and in <a href="/results/r69/">R69</a>.</p></main></html>'''.replace('ROWS',rows);(OUT/'index.html').write_text(page)
