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:
2026-10-27 06:03:33 +00:00
parent a76e61398a
commit cee2ff0859
84 changed files with 8793 additions and 460 deletions

View File

@@ -1,4 +1,4 @@
"""Huấn luyện CNN–GRU cho B2 (loss gốc) và B3 (Gaussian NLL), chọn epoch theo vòng inner."""
"""CNN–GRU training for B2 (original loss) and B3 (Gaussian NLL), with epoch selection in the inner loop."""
from __future__ import annotations
@@ -12,7 +12,7 @@ from ml_porosity.models.cnn_gru import CNNGRU
class CNNGRUHetero(nn.Module):
"""Backbone CNN–GRU v2 với head 2 kênh: μ và σ = softplus(·) + σ_min."""
"""CNN–GRU v2 backbone with a 2-channel head: μ and σ = softplus(·) + σ_min."""
def __init__(self, in_ch: int, d: int = 64, pdrop: float = 0.05, sigma_min: float = 1e-3):
super().__init__()
@@ -35,7 +35,7 @@ def gaussian_nll(mu, sigma, y):
def train_cnn(Xtr, Ytr, cfg: dict, kind: str, seed: int, epochs: int, device: str,
Xva=None, Yva=None, eval_every: int = 25):
"""kind: "legacy" (B2) hoặc "nll" (B3). Y ở thang đã chuẩn hoá. Trả về (model, [(epoch, val_mse)])."""
"""kind: "legacy" (B2) or "nll" (B3). Y is on the standardised scale. Returns (model, [(epoch, val_mse)])."""
torch.manual_seed(seed)
np.random.seed(seed)
T = lambda a: torch.tensor(a, dtype=torch.float32, device=device)