#!/usr/bin/env python3 """job1930-analyze.py -- reduce the T23/T29/T31 exact fold spectra to the route-82 decision. Reads the JSON emitted by `job1930-k2.py spectrum` (first line of the log) and prints: 1. the pre-registered T31 test (interval spanned by T23 and T29, expanded by 0.05); 2. the full Lambda(p) spectrum at the three tiles with the tile-over-tile ratios; 3. the exchangeable-null deficit and the collapse of K2 at the larger folds. No new computation; pure reduction of the exact counts. """ import json import sys from fractions import Fraction PATH = sys.argv[1] if len(sys.argv) > 1 else "outputs/1930/spectrum.log" raw = open(PATH).read() line = next(l for l in raw.splitlines() if l.lstrip().startswith("[")) data = json.loads(line) by_tile = {t["x"]: {f["p"]: f for f in t["folds"]} for t in data} tiles = sorted(by_tile) allp = sorted(set().union(*[set(d) for d in by_tile.values()])) print("== 1. pre-registered T31 test (question: does Lambda plateau at fixed fold?) ==") print("rule: success = Lambda(T31,p) inside [min(T23,T29), max(T23,T29)] expanded by 0.05, for p=31,37") print(" failure = Lambda(T31,p) leaves that interval by MORE than 0.05") for p in (31, 37): a = by_tile[23][p]["lambda"] b = by_tile[29][p]["lambda"] c = by_tile[31][p]["lambda"] lo, hi = min(a, b), max(a, b) elo, ehi = lo - 0.05, hi + 0.05 excess = max(0.0, c - ehi, elo - c) inside = elo <= c <= ehi print(f" p={p}: T23 {a:.5f} T29 {b:.5f} T31 {c:.5f} | span [{lo:.5f},{hi:.5f}] " f"expanded [{elo:.5f},{ehi:.5f}]") print(f" ratio T29/T23 {b/a:.3f} T31/T29 {c/b:.3f} | excess over expanded band {excess:.5f}" f" -> success={inside} failure(excess>0.05)={excess > 0.05}") print() print("== 2. exact Lambda spectrum: T23 / T29 / T31 ==") print(f"{'p':>5} {'in-tile':>8} | " + " | ".join(f"L(T{t})" for t in tiles) + " || " + " | ".join(f"r{t}/{tiles[k]}" for k, t in enumerate(tiles[1:], 1))) for p in allp: row = [] for t in tiles: f = by_tile[t].get(p) row.append(f"{f['lambda']:.5f}" if f else " -- ") ratios = [] for k in range(1, len(tiles)): a = by_tile[tiles[k - 1]].get(p) b = by_tile[tiles[k]].get(p) ratios.append(f"{b['lambda']/a['lambda']:.4f}" if a and b and a["lambda"] > 0 else " -- ") it = " x==p" if p in tiles else "" print(f"{p:>5} {it:>8} | " + " | ".join(row) + " || " + " | ".join(ratios)) print() print("== 3b. fold-independent repeat statistic: adjacent EQUAL gap values ==") print("R = sum(g=g_{i+1}); E_rep = sum_g h_g(h_g-1)/(D-1) under exchangeability") for t in data: r = t["repeat"] print(f" T{t['x']}: D={t['D']:>12} R={r['R']:>12} E_rep={r['E_repeat']:>16.1f} " f"R/E_rep={r['ratio']:.5f}") print() print("== 3. one-step m_p, two-step K2 and the exchangeable deficit at T31 ==") print(f"{'p':>5} {'m_p':>13} {'K2':>11} {'E':>14} {'Lambda':>10} {'z':>10} {'|S_p n supp|':>11} support (gap values that occur)") for p in allp: f = by_tile[31].get(p) if not f: continue print(f"{p:>5} {f['m']:>13} {f['K2']:>11} {f['E']:>14.1f} {f['lambda']:>10.5f} {f['z']:>10.1f} " f"{len(f['support']):>11} {f['support']}")