Download code/src/run/loci_raw.py from bryan7264/lorapop: direct link, hf CLI and curl.
- Browser
- Download file 995 Bytes
-
https://huggingface.co/datasets/bryan7264/lorapop/resolve/main/code/src/run/loci_raw.py
- Command line
-
hf download hf://datasets/bryan7264/lorapop/code/src/run/loci_raw.py
-
curl -L -o loci_raw.py https://huggingface.co/datasets/bryan7264/lorapop/resolve/main/code/src/run/loci_raw.py
995 Bytes
| # MIT License, Bryan Cheng, 2026. | |
| """Ablation genotypes: loci from raw (Frobenius) per-module Grams instead of expressed ones (RESEARCH_PLAN 14.7).""" | |
| import json, os, sys | |
| import numpy as np | |
| import torch | |
| g = sys.argv[1] | |
| keys = json.load(open(os.path.join(g, "modules.json"))) | |
| gr = np.load(os.path.join(g, "grams_raw.npy"), mmap_mode="r") | |
| n = gr.shape[1] | |
| H = torch.eye(n, dtype=torch.float64) - 1.0 / n | |
| loci = {} | |
| for mi, k in enumerate(keys): | |
| lam, U = torch.linalg.eigh(H @ torch.from_numpy(np.asarray(gr[mi], dtype=np.float64)) @ H) | |
| lam, U = lam.flip(0).clamp(min=0), U.flip(1) | |
| tot = float(lam.sum()) | |
| nl = 0 if tot <= 0 else min(32, int((torch.cumsum(lam, 0) / tot < 0.9).sum()) + 1, int((lam > 1e-10 * tot).sum())) | |
| loci[k] = {"lam": lam[:64].float(), "U": U[:, :nl].float(), "g": (U[:, :nl] * lam[:nl].sqrt()).float(), | |
| "n_loci": nl, "total_var": tot} | |
| torch.save(loci, os.path.join(g, "loci_raw.pt")) | |
| print("raw loci", sum(v["n_loci"] for v in loci.values())) | |