suchirsalhan commited on
Commit
d5c0c98
·
verified ·
1 Parent(s): 29a487f

Upload code/analyze.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. code/analyze.py +25 -1
code/analyze.py CHANGED
@@ -228,6 +228,30 @@ if pred_rows:
228
  r["bh_q"] = float(qq) if np.isfinite(qq) else ""
229
  to_csv(pred_rows, f"{R}/predictor_auroc.csv")
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  # ---------------- P0-2b: does the predictor transfer ACROSS substrates (leave-one-size-out)?
232
  xfer = []
233
  szs_all = sorted({r["size"] for r in rows1 if len([q for q in rows1 if q["size"] == r["size"]]) >= 8})
@@ -319,7 +343,7 @@ if rows1:
319
  # 2. rescue vs coordinate share
320
  if rows1:
321
  fig, axes = plt.subplots(1, 2, figsize=(8.4, 3.6))
322
- for ax, pk, lab in ((axes[0], "p_coord_share_bnd_perm", "coordinate share (block-normalised, permutation)"),
323
  (axes[1], "p_cka_mean", "unaligned CKA (mean over layers)")):
324
  for sz in sorted({r["size"] for r in rows1}, key=lambda s: int(s[:-1])):
325
  sub = [r for r in rows1 if r["size"] == sz]
 
228
  r["bh_q"] = float(qq) if np.isfinite(qq) else ""
229
  to_csv(pred_rows, f"{R}/predictor_auroc.csv")
230
 
231
+ # ---------------- P0-2 CONFIRMATORY family: the five predictors the audit brief itself names,
232
+ # on the one outcome it asks about. Fixed from the brief, not chosen after seeing the table, and
233
+ # BH-corrected within this small family only. Everything else in predictor_auroc.csv is exploratory.
234
+ CONFIRMATORY = [("p_weight_cosine", "weight cosine"),
235
+ ("p_coord_share_bnd_perm", "coordinate share (block-normalised / permutation)"),
236
+ ("p_qmd_act_perm", "QMD (quotient_residual / permutation)"),
237
+ ("p_cka_mean", "CKA (mean over layers / unaligned)"),
238
+ ("p_task_vector_cosine", "task-vector cosine")]
239
+ conf = []
240
+ for r in pred_rows:
241
+ if r["outcome"] != "rescue_frac":
242
+ continue
243
+ for pk, lbl in CONFIRMATORY:
244
+ if r["predictor"] == pk[2:]:
245
+ conf.append({"substrate": r["substrate"], "predictor": lbl, "n_pairs": r["n_pairs"],
246
+ "spearman": r["spearman_rescue"], "auroc_heldout_by_seed": r["auroc_heldout_by_seed"],
247
+ "perm_null_mean": r["perm_null_mean"], "perm_p": r["perm_null_p"],
248
+ "n_null_draws": r["n_null_draws"]})
249
+ if conf:
250
+ qq = bh([c["perm_p"] for c in conf])
251
+ for c, q in zip(conf, qq):
252
+ c["bh_q_within_confirmatory_family"] = float(q) if np.isfinite(q) else ""
253
+ to_csv(conf, f"{R}/predictor_confirmatory.csv")
254
+
255
  # ---------------- P0-2b: does the predictor transfer ACROSS substrates (leave-one-size-out)?
256
  xfer = []
257
  szs_all = sorted({r["size"] for r in rows1 if len([q for q in rows1 if q["size"] == r["size"]]) >= 8})
 
343
  # 2. rescue vs coordinate share
344
  if rows1:
345
  fig, axes = plt.subplots(1, 2, figsize=(8.4, 3.6))
346
+ for ax, pk, lab in ((axes[0], "p_coord_share_bnd_perm", "coordinate share (block-normalised / permutation)"),
347
  (axes[1], "p_cka_mean", "unaligned CKA (mean over layers)")):
348
  for sz in sorted({r["size"] for r in rows1}, key=lambda s: int(s[:-1])):
349
  sub = [r for r in rows1 if r["size"] == sz]