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

@@ -0,0 +1,35 @@
"""Matplotlib style for the P2 figures: reference palette of the dataviz skill (light mode), checked with validate_palette.
- Categorical (≤ 3 groups per figure): blue, orange, aqua — passes all-pairs (CVD ΔE ≥ 9.2); aqua is < 3:1, so always labelled directly.
- Ordinal (drift factor c): a single blue hue, light → dark.
- Diverging (M2/competitor ratio around 1): blue ↔ red, with a neutral grey midpoint.
"""
from __future__ import annotations
import matplotlib as mpl
from matplotlib.colors import LinearSegmentedColormap, TwoSlopeNorm
SURFACE, INK, INK2, MUTED, GRID, AXIS = "#fcfcfb", "#0b0b0b", "#52514e", "#898781", "#e1e0d9", "#c3c2b7"
BLUE, ORANGE, AQUA = "#2a78d6", "#eb6834", "#1baf7a"
ORDINAL_BLUE = ["#86b6ef", "#2a78d6", "#104281"]
GOOD, CRITICAL = "#0ca30c", "#d03b3b"
DIVERGING = LinearSegmentedColormap.from_list(
"blue_gray_red", ["#104281", "#2a78d6", "#86b6ef", "#f0efec", "#ec8a89", "#d23f3e", "#8f2626"])
def diverging_norm(vmin: float, vcenter: float, vmax: float) -> TwoSlopeNorm:
return TwoSlopeNorm(vcenter, vmin, vmax)
def apply() -> None:
mpl.rcParams.update({
"figure.facecolor": SURFACE, "axes.facecolor": SURFACE, "savefig.facecolor": SURFACE,
"axes.edgecolor": AXIS, "axes.labelcolor": INK2, "axes.titlecolor": INK, "text.color": INK,
"axes.grid": True, "grid.color": GRID, "grid.linewidth": 0.6, "axes.axisbelow": True,
"axes.spines.top": False, "axes.spines.right": False,
"xtick.color": AXIS, "ytick.color": AXIS, "xtick.labelcolor": INK2, "ytick.labelcolor": INK2,
"font.size": 9, "axes.titlesize": 10, "axes.titleweight": "regular", "axes.titlelocation": "left",
"lines.linewidth": 1.5, "lines.markersize": 5, "legend.frameon": False, "legend.fontsize": 8,
"axes.prop_cycle": mpl.cycler(color=[BLUE, ORANGE, AQUA]),
})

View File

@@ -1,4 +1,4 @@
"""Metric điểm cơ bản; bỏ qua mẫu NaN ở cả hai phía."""
"""Basic pointwise metrics; samples that are NaN on either side are ignored."""
from __future__ import annotations
@@ -27,7 +27,7 @@ def point_metrics(y_true, y_pred) -> dict[str, float]:
def split_bands(y: np.ndarray, f_c_hz: float, dt_ms: float = 4.0, order: int = 4) -> tuple[np.ndarray, np.ndarray]:
"""Tách chuỗi thành băng thấp (< f_c, Butterworth pha không) và phần còn lại (băng seismic)."""
"""Split a series into a low band (< f_c, zero-phase Butterworth) and the remainder (seismic band)."""
from scipy import signal
y = np.asarray(y, dtype=float)
@@ -46,7 +46,7 @@ def band_metrics(y_true, y_pred, f_c_hz: float = 6.0, dt_ms: float = 4.0) -> dic
def gaussian_metrics(y_true, mu, sigma) -> dict[str, float]:
"""NLL, CRPS (dạng đóng của Gaussian) và coverage của khoảng trung tâm."""
"""NLL, CRPS (Gaussian closed form) and coverage of central intervals."""
from scipy import stats
y, mu, s = (np.asarray(a, dtype=float) for a in (y_true, mu, sigma))