"""Render frozen prompt-policy replay on R75 crossings."""
import json,html,datetime
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r77';d=json.loads((O/'results.json').read_text());records=d['records'];labels={'uniform':'Uniform grid','contrast':'Contrast stratified','mixed':'Mixed grid + contrast'};names=list(labels)
def totals(name,n):
 x=[r['policies'][name]['budgets'][str(n)] for r in records];return {'n':sum(y['n'] for y in x),'visible05':sum(y['visible05']['matched'] for y in x),'visible075':sum(y['visible075']['matched'] for y in x),'full05':sum(y['full05']['matched'] for y in x)}
rows=[];md=[]
for n in (5,10,20):
 for name in names:
  t=totals(name,n);row=[str(n),labels[name],str(t['n']),str(t['visible05'])+'/12',str(t['visible075'])+'/12',str(t['full05'])+'/12'];rows.append('<tr>'+''.join('<td>'+x+'</td>' for x in row)+'</tr>');md.append('| '+' | '.join(row)+' |')
cards=[]
for r in records:
 parts=', '.join(f"{labels[n]} {r['policies'][n]['budgets']['20']['visible05']['matched']}/2" for n in names);cards.append(f"<article><h3>{html.escape(r['variant'])} · pair {r['pair']}</h3><img src='{html.escape(r['image'])}' alt='Visible reference masks, uniform, contrast, and mixed top-ten masks'><p>Visible IoU ≥0.5 at up to 20 masks: {parts}.</p></article>")
page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>R77 · Prompt policies on other crossings</title><style>body{font:16px/1.5 system-ui;background:#f2f6f0;color:#203b34}main{max-width:1180px;margin:auto;padding:20px}article,.card{background:white;padding:16px;margin:12px 0;border:1px solid #d4ded6}img{max-width:100%}.notice{background:#fff2d6;padding:14px}th,td{padding:8px;text-align:left;border-bottom:1px solid #d4ded6}.scroll{overflow:auto}a{color:#126d55}</style><main><nav><a href="/results/board.html">Research board</a> · <a href="/research/R77.md">Research note</a> · <a href="/results/l66/">Earlier prompt test</a></nav><h1>Do the fixed prompt policies carry over?</h1><p class="notice"><strong>Previously observed synthetic development scenes.</strong> These six opaque crossings reuse three cutout pairs across two layouts and backgrounds. They are not an independent real-slide test; backgrounds are incompletely annotated, and biological and model-training overlap are unknown.</p><p>Each policy selects 64 points from cached 256-point MobileSAM predictions. The policies, filters, suppression and detector-assisted ranking are unchanged from L66. No new model inference or runtime savings are measured. Each target is scored at most once, against visible or full synthetic masks after ranking.</p><div class="card"><div class="scroll"><table><tr><th>Max masks per scene</th><th>64-point policy</th><th>Total masks actually displayed</th><th>Visible IoU ≥0.5</th><th>Visible IoU ≥0.75</th><th>Full IoU ≥0.5</th></tr>{ROWS}</table></div><p>At a maximum of 20 masks per scene, the mixed policy matched 5/12 visible targets versus 6/12 for uniform. At ten, both matched 4/12. The small mixed-policy improvement seen in L66 therefore did not repeat on these scenes. Counts of masks actually shown differ because some scenes retained fewer than the budget.</p><p>Across all retained candidates, each policy matched 7/12 visible targets; those searches require 102 uniform, 122 contrast, or 118 mixed masks in total. This is a reference-based diagnostic, not a deployable selection policy.</p></div><h2>Scene reconstruction</h2><p>The source experiment did not save a hash of the RGB image at inference. We reconstructed each image using its frozen scene code and input hashes, and verified both reference masks against the archived masks. This supports reproducibility, but does not directly prove the reconstructed RGB bytes equal the original inference pixels. RGB files are currently in temporary storage and are not redistributed here.</p><h2>Scene silhouettes</h2><p>From left: visible targets, then the first ten masks from uniform, contrast and mixed policies. Colors distinguish visual layers, not identities.</p>{CARDS}<p><a href="results.json">Scores, prompts and rankings</a> · <a href="protocol.json">Frozen protocol</a> · <a href="scene-manifest.json">Reconstructed-image provenance</a> · <a href="/research/r77_verify.py">Independent verifier</a> · <a href="/results/r75/">Original candidate masks</a></p></main></html>'''.replace('{ROWS}',''.join(rows)).replace('{CARDS}',''.join(cards));(O/'index.html').write_text(page)
lines=['# R77 · Fixed prompt policies on different crossing cutouts','','[Visual comparison](/results/r77/) · [frozen protocol](/results/r77/protocol.json) · [all points, rankings and metrics](/results/r77/results.json) · [reconstruction manifest](/results/r77/scene-manifest.json) · [independent verifier](/research/r77_verify.py)','','Apply L66’s already-fixed uniform, contrast-stratified and mixed 64-point subsets to all six R75/R41 crossing scenes. The three R41 cutout pairs each appear in an original and an alternate rotated layout; their source image hashes differ from L66’s cutouts, but all scenes were previously viewed and used in other studies. Inputs and detector-assisted ranking are fixed; 256 cached SAM masks are sampled, quality/area-filtered, and NMS-filtered separately for each 64-point policy. References are used only for posthoc one-to-one scoring.','','| Max masks per scene | 64-point policy | Total masks displayed | Visible IoU ≥0.5 | Visible IoU ≥0.75 | Full IoU ≥0.5 |','|---:|---|---:|---:|---:|---:|']+md
lines+=['','At up to 20 masks per scene, mixed gives 5/12 visible matches versus uniform 6/12; at 10 both give 4/12. L66’s one-target mixed advantage did not repeat in this six-scene development comparison. The strategies produce different numbers of eligible/retained masks, so the 20-mask budget results show 91 uniform, 101 contrast and 94 mixed masks in total. Across all retained candidates, each policy achieves 7/12 visible matches, requiring 102, 122 and 118 masks respectively. These are reference-assisted pool upper bounds rather than automatic decisions. Scenes are related across layout and the sample is far too small to infer a population-level difference.','','R75 did not save an RGB image hash at the original inference call. We reconstructed six 512×512 images from the same frozen R41 scene code, source cutouts, annotations and backgrounds; hashes of these inputs matched R75’s protocol and the reconstructed visible and full references matched the R75 archives exactly. This does not directly prove reconstructed RGB pixels match those originally passed to the model. The new RGB image hashes and paths are in the manifest, but the RGB composites and public cutouts remain in `/tmp` and could disappear; the public license text was not available, so these images are not redistributed on the static server.','','The independent verifier rederived all 18 prompt selections from the reconstructed RGB, reimplemented NMS and ranking, and checked 90 per-scene metric records, input hashes and output images. It did not rerun the model or prove the exact original inference RGB image. Masks may merge or duplicate objects; a mask covering half of two full references is a warning signal, not proof of identity. IoU ≥0.8 duplicate counts among retained candidates are zero by NMS construction. The fixed-mask replay cannot measure 64-point inference latency or costs.','','The result weakens the case for adopting mixed sampling based on L66 alone. It does not establish real microscopy, freshwater, false-positive, genus/species, or human-level segmentation performance. Continue with other model/proposal approaches and truly independent labeled overlapping/partial instances while preserving original pixels and suppressed alternatives for later feedback.']
(R/'research/R77.md').write_text('\n'.join(lines)+'\n');p=R/'research/board.json';board=json.loads(p.read_text());board['updated']=datetime.date.today().isoformat()
for t in board['tasks']:
 if t['id']=='R77':t.update(status='review',summary='L66 mixed-policy gain did not repeat: 5/12 visible top-20 vs 6/12 uniform across 6 related previously viewed crossings.',result='/results/r77/')
p.write_text(json.dumps(board,indent=2)+'\n');p=R/'RESEARCH.md';s=p.read_text();s+='\n- **R77 · Fixed prompt replay:** Mixed selection matched 5/12 synthetic visible crossing targets at top 20 vs 6/12 uniform; prior gain did not repeat. [Results](/results/r77/) · [note](research/R77.md).\n';p.write_text(s)
