Download code/case2/paper_numbers.py from harryzhang1018/TestRandomization: direct link, hf CLI and curl.
- Browser
- Download file 5.95 kB
-
https://huggingface.co/datasets/harryzhang1018/TestRandomization/resolve/main/code/case2/paper_numbers.py
- Command line
-
hf download hf://datasets/harryzhang1018/TestRandomization/code/case2/paper_numbers.py
-
curl -L -o paper_numbers.py https://huggingface.co/datasets/harryzhang1018/TestRandomization/resolve/main/code/case2/paper_numbers.py
5.95 kB
| """Collect the Case 2 numbers reported in the paper from the analysis outputs (no simulation). Sim2Sim. | |
| Reads results/exploration_tau_table.json, results/confirm_analysis.json, results/posthoc_confirm.json, | |
| results/behavior_B_confirm16.json and the Chrono records. Writes results/paper_numbers.json and prints a summary. | |
| Usage: python paper_numbers.py | |
| """ | |
| import json | |
| import fixed_design as design | |
| import variants as V | |
| from common import RESULTS | |
| from run_rom import POOLS | |
| R = lambda name: json.loads((RESULTS / name).read_text()) | |
| expl, conf, ph, beh = (R('exploration_tau_table.json'), R('confirm_analysis.json'), R('posthoc_confirm.json'), | |
| R('behavior_B_confirm16.json')) | |
| r2 = lambda x: round(float(x), 2) | |
| out = {} | |
| # Exploration, goal set A (16 policies: 12 design policies + 4 released checkpoints) | |
| e = expl['all16'] | |
| out['exploration'] = dict( | |
| test_conditions_excluding_nominal=len([n for n in V.EXPLORE if n != 'nominal']), | |
| chrono_episodes=sum(1 for _ in open(RESULTS / 'chrono_A_explore/episodes.jsonl')), | |
| tau_b={n: r2(e[n]['all']) for n in ['nominal', 'paper_tr', 'rate_rand_paper', 'rate_rand', 'delay_rand03']}) | |
| # Held-out evaluation, goal set B | |
| P, S = conf['pools']['primary'], conf['pools']['secondary'] | |
| held = P['policies'] | |
| nom, tr = P['conditions']['nominal']['rom'], P['conditions'][design.PRIMARY_TR]['rom'] | |
| csr = P['chrono']['success_rate'] | |
| out['heldout_success'] = dict( | |
| nominal_rom_min_success_id_ood=[min(nom['success_rate'][g][p] for p in held) for g in ('id', 'ood')], | |
| chrono_success_id_range=[r2(min(csr['id'].values())), r2(max(csr['id'].values()))], | |
| chrono_success_ood_range=[r2(min(csr['ood'].values())), r2(max(csr['ood'].values()))], | |
| chrono_success_all_min=r2(min(csr['all'].values()))) | |
| pr = ph['pools']['primary']['pair_resolution_vs_chrono'] | |
| table = {} | |
| for n in design.CONDITIONS: | |
| v = P['conditions'][n]['vs_chrono'] | |
| table[n] = dict(tau_b=r2(v['all']['kendall_tau_b']), ci95=[r2(x) for x in v['all']['kendall_ci95']], | |
| tau_id=r2(v['id']['kendall_tau_b']), tau_ood=r2(v['ood']['kendall_tau_b']), | |
| same=pr[n]['same_direction'], reversed=pr[n]['opposite_direction'], unresolved=pr[n]['unresolved']) | |
| out['table_case2_confirm'] = table | |
| pt = conf['primary_test'] | |
| out['primary_test'] = dict(delta_tau=r2(pt['delta_tau']), ci95=[r2(x) for x in pt['ci95']], met=pt['supported'], | |
| chrono_resolved_pairs=f"{P['chrono']['resolved_pairs']}/{len(P['chrono']['pairs'])}") | |
| # Steering behavior of the held-out policies (nominal ROM) and its relation to Chrono success | |
| chat = {p: beh[p]['mean_abs_steer_change'] for p in held} | |
| bang = sorted(p for p in held if chat[p] > 0.1) | |
| smooth = sorted(p for p in held if chat[p] <= 0.1) | |
| two = sorted(held, key=chat.get)[:2] | |
| rank = lambda order, p: order.index(p) + 1 | |
| out['steering'] = dict( | |
| mean_abs_steer_change={p: round(chat[p], 3) for p in sorted(held, key=chat.get)}, | |
| bang_bang_count=len(bang), bang_bang_range=[r2(min(chat[p] for p in bang)), r2(max(chat[p] for p in bang))], | |
| smooth_range=[r2(min(chat[p] for p in smooth)), r2(max(chat[p] for p in smooth))], | |
| spearman_chatter_vs_chrono_ood_success=dict((k, round(v, 3)) for k, v in | |
| ph['pools']['primary']['chatter_vs_chrono_success']['ood'].items()), | |
| two_smoothest={p: dict(chrono_rank=rank(P['chrono']['order'], p), nominal_rank=rank(nom['order'], p), | |
| tr_rank=rank(tr['order'], p)) for p in two}) | |
| d = ph['pools']['primary']['delta_tau_primary_tr_minus']['det_calibrated'] | |
| out['calibrated_rom'] = dict(tau_b=table['det_calibrated']['tau_b'], tr_minus_calibrated=r2(d['value']), | |
| ci95=[r2(x) for x in d['ci95']]) | |
| rat_p = P['conditions']['nominal']['chrono_over_rom_time_ratio'] | |
| rat_s = S['conditions']['nominal']['chrono_over_rom_time_ratio'] | |
| out['time_ratio_chrono_over_nominal_rom'] = dict(heldout_range=[r2(min(rat_p.values())), r2(max(rat_p.values()))], | |
| checkpoints={p: r2(rat_s[p]) for p in POOLS['released']}) | |
| # Four released checkpoints (secondary pool, 16 policies) | |
| rel = POOLS['released'] | |
| ssr = S['chrono']['success_rate'] | |
| sub_order = lambda order: [p for p in order if p in rel] | |
| pairs = {} | |
| for src, pl in [('chrono', S['chrono']['pairs']), ('nominal', S['conditions']['nominal']['rom']['pairs']), | |
| (design.PRIMARY_TR, S['conditions'][design.PRIMARY_TR]['rom']['pairs'])]: | |
| pairs[src] = {f"{p['a']}-{p['b']}": (0 if not p['resolved'] else (1 if p['win_a'] > 0.5 else -1)) for p in pl | |
| if p['a'] in rel and p['b'] in rel} | |
| cmp = lambda m: dict(same=[k for k, s in pairs[m].items() if s and s == pairs['chrono'][k]], | |
| reversed=[k for k, s in pairs[m].items() if s and s == -pairs['chrono'][k]], | |
| unresolved=[k for k, s in pairs[m].items() if not s]) | |
| out['checkpoints'] = dict( | |
| chrono_success_id_pct={p: round(100 * ssr['id'][p]) for p in rel}, | |
| chrono_success_ood_pct={p: round(100 * ssr['ood'][p]) for p in rel}, | |
| order_chrono=sub_order(S['chrono']['order']), | |
| order_nominal=sub_order(S['conditions']['nominal']['rom']['order']), | |
| order_tr=sub_order(S['conditions'][design.PRIMARY_TR]['rom']['order']), | |
| chrono_resolved_pairs=sum(1 for s in pairs['chrono'].values() if s), | |
| nominal_vs_chrono=cmp('nominal'), tr_vs_chrono=cmp(design.PRIMARY_TR)) | |
| sv = {n: S['conditions'][n]['vs_chrono']['all'] for n in ['nominal', design.PRIMARY_TR, 'tr_rate_half', 'tr_rate_double']} | |
| out['pool16'] = dict(tau_b={n: r2(v['kendall_tau_b']) for n, v in sv.items()}, | |
| delta_tr_minus_nominal=r2(sv[design.PRIMARY_TR]['delta_tau_vs_nominal']), | |
| ci95=[r2(x) for x in sv[design.PRIMARY_TR]['delta_tau_ci95']]) | |
| (RESULTS / 'paper_numbers.json').write_text(json.dumps(out, indent=1) + '\n') | |
| print(json.dumps(out, indent=1)) | |