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 @@
"""B1: post-stack model-based AI inversion (PyLops) với LFM nội suy theo horizon, rồi φ = a + b·AI."""
"""B1: post-stack model-based AI inversion (PyLops) with a horizon-guided interpolated LFM, followed by φ = a + b·AI."""
from __future__ import annotations
@@ -10,7 +10,7 @@ from ml_porosity.data.wavelet import estimate_wavelet_ls
def fill_edges(x: np.ndarray) -> np.ndarray:
"""Thay NaN bằng nội suy tuyến tính, giữ hằng ở hai đầu."""
"""Replace NaNs by linear interpolation, holding values constant at both ends."""
x = np.asarray(x, dtype=float).copy()
ok = np.isfinite(x)
x[~ok] = np.interp(np.flatnonzero(~ok), np.flatnonzero(ok), x[ok])
@@ -23,8 +23,8 @@ def lowpass(x: np.ndarray, f_c_hz: float, dt_ms: float = 4.0, order: int = 4) ->
def strat_map(t: np.ndarray, h_from: np.ndarray, h_to: np.ndarray) -> np.ndarray:
"""Ánh xạ thời gian ở giếng đích sang thời gian tương đương địa tầng ở giếng nguồn: nội suy
tuyến tính từng đoạn qua các cặp horizon (h_from → h_to), ngoài cùng thì dịch song song."""
"""Map times at the target well to stratigraphically equivalent times at the source well: piecewise-linear
interpolation through the horizon pairs (h_from → h_to), with a parallel shift beyond the outermost horizons."""
ok = np.isfinite(h_from) & np.isfinite(h_to)
a, b = h_from[ok], h_to[ok]
order = np.argsort(a)
@@ -38,7 +38,7 @@ def strat_map(t: np.ndarray, h_from: np.ndarray, h_to: np.ndarray) -> np.ndarray
def build_lfm(t, target_h, target_xy, wells: dict, f_c_hz: float = 6.0, power: float = 2.0) -> np.ndarray:
"""wells[name] = {"logai": (L,), "h": (H,), "xy": (2,)} trên cùng trục t. Trả về LFM của log(AI)."""
"""wells[name] = {"logai": (L,), "h": (H,), "xy": (2,)} on a common t axis. Returns the LFM of log(AI)."""
num = np.zeros_like(t, dtype=float)
den = 0.0
for w in wells.values():
@@ -53,7 +53,7 @@ def build_lfm(t, target_h, target_xy, wells: dict, f_c_hz: float = 6.0, power: f
def operator_reflectivity(logai: np.ndarray, nspike: int = 33) -> np.ndarray:
"""Reflectivity theo đúng quy ước của PoststackLinearModelling (wavelet xung đơn vị)."""
"""Reflectivity following the exact convention of PoststackLinearModelling (unit-spike wavelet)."""
spike = np.zeros(nspike)
spike[nspike // 2] = 1.0
G0 = PoststackLinearModelling(spike, len(logai), explicit=True).A
@@ -67,7 +67,7 @@ def estimate_wavelet(train_logai: list[np.ndarray], train_seis: list[np.ndarray]
def invert(seis: np.ndarray, wav: np.ndarray, lfm: np.ndarray, e: float) -> np.ndarray:
"""log(AI) nghịch đảo: Tikhonov về LFM với epsI = e·trace(GᵀG)/n."""
"""Inverted log(AI): Tikhonov regularisation towards the LFM with epsI = e·trace(GᵀG)/n."""
G = PoststackLinearModelling(wav, len(seis), explicit=True).A
eps = e * np.trace(G.T @ G) / len(seis)
m, _ = PoststackInversion(seis, wav, m0=lfm, explicit=True, epsI=eps, simultaneous=False)