# results_irm

Invariant Risk Minimization (IRM) fine-tune of `stem_ms96` from SWA checkpoints. Treat AVGC/DTU/KUL/UHD/USTC as environments. Loss = mean_e ERM BCE + λ · mean_e ‖∇_w|_{w=1} R^e(w·logit)‖². Architecture unchanged (ms feats, w96). Init `models/stem_ms96_swa/{held-*,all5}.pt` with causal `-inf` mask restored (SWA equal-avg had turned mask `-inf`→`nan`). EMA 0.995 eval. Smoke λ∈{0.1,1.0,10.0} (40 steps, held-AVGC) chose **λ=0.1**. Full run 1000 steps, batch 512. HMM preset p_stay 0.994 scale 0.8. Also scored causal tau-30 high-pass of IRM evidence (`hp30`; corpus emissions).

Code: `stem_ms96_irm.py`. Checkpoints: `models/stem_ms96_irm/`. JSON: `results/research/stem_ms96_irm.json`. Log: `experiments/stem_ms96_irm.log` / `stem_ms96_irm_console.log`. Smoke: `experiments/stem_ms96_irm_smoke.log`.

## LODO (preset)

| Held-out | IRM H | IRM Acc % | stem_ms96 H/Acc | SWA H/Acc | RSC H/Acc | hp30 H | hp30 Acc % |
|---|---:|---:|---|---|---|---:|---:|
| AVGC | 0.8095 | 75.12 | 0.7945/74.06 | 0.8015/74.91 | 0.8042/75.12 | 0.7755 | 70.77 |
| DTU | 0.8999 | 88.88 | 0.9061/89.85 | 0.9003/89.52 | 0.9059/89.70 | 0.8255 | 70.67 |
| KUL | 0.8702 | 81.84 | 0.8755/82.33 | 0.8769/82.35 | 0.8717/82.15 | 0.8465 | 74.60 |
| UHD | 0.8530 | 79.96 | 0.8407/79.47 | 0.8553/80.09 | 0.8500/79.79 | 0.8053 | 72.87 |
| USTC | 0.9148 | 85.96 | 0.9219/86.36 | 0.9161/86.19 | 0.9190/85.80 | 0.8314 | 71.16 |
| **mean** | **0.8695** | **82.35** | **0.8677/82.42** | **0.8700/82.61** | **0.8702/82.51** | | |

## External (preset)

| Set | IRM H | IRM Acc % | linear_hp30 | stem_ms96 | SWA | RSC | IRM_hp30 H/Acc |
|---|---:|---:|---|---|---|---|---|
| AASD | 0.6207 | 51.01 | 0.6422/53.12 | 0.6158/51.54 | 0.6202/51.08 | 0.6196/51.13 | 0.6005/50.99 |
| Carta2026 | 0.5426 | 48.04 | 0.6520/60.54 | 0.5695/51.03 | 0.5507/48.68 | 0.5481/48.48 | 0.5646/49.54 |

## Targets

| Target | Result |
|---|---|
| AVGC H>=0.85 and Acc>=78 | miss (0.8095/75.12); **best AVGC H so far** (+0.0080 vs SWA, +0.0053 vs RSC); Acc = RSC; still open |
| UHD H>=0.85 | met (0.8530); already met under SWA (0.8553); no new flip |
| AASD Acc>60 with H>0.63 | miss (0.6207/51.01); Acc flat vs SWA/RSC, below linear_hp30 |
| Carta vs linear_hp30 | moved away (0.5426/48.04) |

## Notes

- λ=0.1 → IRM penalty contribution ≪ ERM (pen≈1e-4); effect is mostly SWA-init fine-tune with per-environment ERM averaging.
- No open target flipped to met. AASD Acc unchanged (~51).
