P2 diagnosis on dev, P3 dev experiments, lock protocol_p3
- P2: SMC tie posterior (numpy + torch), RML/soft-DTW losses, bank training, D2 synthetic generator, scripts 09-13, protocol_p2 (locked) and its outcome (G-B failed; H1 not rejected, H3 rejected, H4 not rejected). - Diagnosis on dev realizations 900/901 only (scripts 14-17, run_p3_dev.sh): posterior screen, SMC stability (P = 1024, K = 1), sigma_a misspecification stress and training, H3 with the SMC posterior, F3 placement on sigma_post. - protocol_p3: H2 split into H2a (posterior-mean labels vs point ties) and H2b (RML vs posterior mean as a function of sigma_post); H3 descriptive only; sigma_a arm; new D2 config d2_synth_p3.yaml; main grid on realizations 8-15. Locked by configs/protocol_p3.sha256 and tag protocol-p3. - runlog: per-run logs and runtime index (logs/index.csv). - Docs: plan §12 items 10-11, theory, technical overview, report; wording aligned with Gunning & Glinsky (2006): the tie posterior is not claimed as new. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
"""LOWO cho các baseline P1 theo configs/protocol.yaml (B0a, B0b, B1, B2, B3a, B3b).
|
||||
"""LOWO for the P1 baselines per configs/protocol.yaml (B0a, B0b, B1, B2, B3a, B3b).
|
||||
|
||||
python scripts/05_lowo.py [--workers 12] [--device cuda] [--only B2,B3a]
|
||||
|
||||
Từ chối chạy nếu SHA-256 của protocol.yaml khác configs/protocol.sha256.
|
||||
Đầu ra: outputs/p1/results.csv (mỗi dòng: method, label, test_well, seed, reference, metric),
|
||||
outputs/p1/preds.npz (μ, σ cho từng method/label/giếng/seed), outputs/p1/selection.csv.
|
||||
Refuses to run if the SHA-256 of protocol.yaml differs from configs/protocol.sha256.
|
||||
Outputs: outputs/p1/results.csv (one row per method, label, test_well, seed, reference, metric),
|
||||
outputs/p1/preds.npz (μ, σ per method/label/well/seed), outputs/p1/selection.csv.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -30,7 +30,7 @@ def check_protocol() -> dict:
|
||||
expected = (REPO_ROOT / "configs" / "protocol.sha256").read_text().split()[0]
|
||||
actual = hashlib.sha256(PROTO.read_bytes()).hexdigest()
|
||||
if actual != expected:
|
||||
raise SystemExit(f"protocol.yaml đã đổi sau khi khoá ({actual[:12]} ≠ {expected[:12]}); tạo phiên bản mới và khoá lại")
|
||||
raise SystemExit(f"protocol.yaml changed after locking ({actual[:12]} ≠ {expected[:12]}); create a new version and lock it again")
|
||||
return yaml.safe_load(PROTO.read_text()) | {"sha256": actual}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class Data:
|
||||
self.D = {k: D[k] for k in D.files}
|
||||
|
||||
def X(self, w):
|
||||
"""Patch z-score theo kênh trên cửa sổ chính, shape (C, L)."""
|
||||
"""Per-channel z-scored patch over the main window, shape (C, L)."""
|
||||
p = self.D[f"{w}/seismic_patch"][:, self.m].astype(np.float64)
|
||||
return (p - p.mean(1, keepdims=True)) / (p.std(1, keepdims=True) + 1e-8)
|
||||
|
||||
@@ -92,11 +92,11 @@ def run_classical(d: Data, label: str, test: str, seeds: list[int]):
|
||||
def ytrain(ws):
|
||||
return np.concatenate([d.y(w, "calibrated", label) for w in ws])
|
||||
|
||||
# B0a: trend tuyến tính theo TWT
|
||||
# B0a: linear trend in TWT
|
||||
lr = LinearRegression().fit(np.tile(tt, len(train))[:, None], ytrain(train))
|
||||
out.append(("B0a", -1, lr.predict(tt[:, None]), None))
|
||||
|
||||
# B0b: attribute từ trace trung bình của patch (z-score), tính trên cửa sổ mở rộng
|
||||
# B0b: attributes from the patch mean trace (z-scored), computed on the extended window
|
||||
def feats(w):
|
||||
p = d.ext(w, "seismic_patch").astype(float)
|
||||
p = (p - p[:, d.m].mean(1, keepdims=True)) / (p[:, d.m].std(1, keepdims=True) + 1e-8)
|
||||
@@ -178,7 +178,7 @@ def run_cnn(job):
|
||||
Y = np.stack([d.y(w, tdr_train, label) for w in ws])
|
||||
return X, Y
|
||||
|
||||
# vòng inner: chọn epoch
|
||||
# inner loop: epoch selection
|
||||
curves = []
|
||||
for v in train:
|
||||
tr2 = [w for w in train if w != v]
|
||||
@@ -187,7 +187,7 @@ def run_cnn(job):
|
||||
Xv, Yv = XY([v])
|
||||
_, c = train_cnn(Xa, (Ya - mu_) / sd_, cfg, kind, seed, cfg["max_epochs"], device,
|
||||
Xv, (Yv - mu_) / sd_, cfg["eval_every"])
|
||||
curves.append([m * sd_**2 for _, m in c]) # MSE theo đơn vị nhãn gốc
|
||||
curves.append([m * sd_**2 for _, m in c]) # MSE in original label units
|
||||
eps = [e for e, _ in c]
|
||||
best_ep = int(eps[int(np.argmin(np.mean(curves, axis=0)))])
|
||||
|
||||
@@ -235,7 +235,7 @@ def main() -> None:
|
||||
sel += s
|
||||
for method, seed, mu, sigma in out:
|
||||
record(method, label, test, seed, mu, sigma)
|
||||
print(f"B0a/B0b/B1 xong sau {time.time() - t0:.0f} s")
|
||||
print(f"B0a/B0b/B1 done after {time.time() - t0:.0f} s")
|
||||
|
||||
cnn = [m for m in ("B2", "B3a", "B3b") if not only or m in only]
|
||||
jobs = [(m, lab, w, s, args.device, proto) for m in cnn for lab in labels for w in d.wells for s in seeds]
|
||||
@@ -253,7 +253,7 @@ def main() -> None:
|
||||
pd.DataFrame(rows).assign(protocol_sha256=proto["sha256"][:12]).to_csv(out_dir / f"results_{tag}.csv", index=False)
|
||||
pd.DataFrame(sel).to_csv(out_dir / f"selection_{tag}.csv", index=False)
|
||||
np.savez_compressed(out_dir / f"preds_{tag}.npz", **preds)
|
||||
print(f"-> {out_dir} ({len(rows)} dòng, {time.time() - t0:.0f} s)")
|
||||
print(f"-> {out_dir} ({len(rows)} rows, {time.time() - t0:.0f} s)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user