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,7 +1,7 @@
"""Đọc dữ liệu giếng F3: LAS, marker, checkshot, track và các mô hình TD.
"""Readers for F3 well data: LAS, markers, checkshots, tracks and TD models.
Quy ước độ sâu: MD tính từ KB (m). Bốn giếng F3 đều thẳng đứng nên MD = TVD + 0
so với KB; TVDSS = MD − KB.
Depth convention: MD is measured from KB (m). All four F3 wells are vertical, so MD = TVD + 0
relative to KB; TVDSS = MD − KB.
"""
from __future__ import annotations
@@ -17,7 +17,7 @@ from ml_porosity.paths import f3_root, f3_wells_dir
F3_WELLS = ("F02-1", "F03-2", "F03-4", "F06-1")
# Vị trí IL/XL mà luận văn dùng (test 2/prepare_data.py:17–21); chỉ để audit, không dùng.
# IL/XL locations used in the thesis (test 2/prepare_data.py:17–21); for auditing only, not used.
LEGACY_IL_XL = {"F03-4": (362, 821), "F02-1": (418, 608), "F06-1": (283, 842)}
@@ -27,10 +27,10 @@ class Well:
x: float
y: float
kb: float
logs: pd.DataFrame # index = MD (m), cột = mnemonic, NaN thay cho NULL
logs: pd.DataFrame # index = MD (m), columns = mnemonics, NaN in place of NULL
units: dict[str, str] = field(default_factory=dict)
markers: pd.DataFrame | None = None # cột: md, name
checkshot: pd.DataFrame | None = None # cột: md, twt_ms (marker TD, xem plan mục 1.2e)
markers: pd.DataFrame | None = None # columns: md, name
checkshot: pd.DataFrame | None = None # columns: md, twt_ms (marker TD, see plan §1.2e)
@property
def md(self) -> np.ndarray:
@@ -50,8 +50,8 @@ def read_las(path: str | Path) -> tuple[pd.DataFrame, dict[str, str], lasio.LASF
def read_two_columns(path: str | Path, skip_header: bool = False) -> np.ndarray:
"""Đọc file hai cột số (depth, value). `skip_header=True` cho file OpendTect
(.wlt, .csmdl) có phần đầu kết thúc bằng dòng `!` thứ hai."""
"""Read a two-column numeric file (depth, value). `skip_header=True` for OpendTect files
(.wlt, .csmdl) whose header ends at the second `!` line."""
lines = Path(path).read_text(errors="replace").splitlines()
if skip_header:
bangs = [i for i, s in enumerate(lines) if s.strip() == "!"]
@@ -79,7 +79,7 @@ def read_markers(path: str | Path) -> pd.DataFrame:
def read_track(path: str | Path) -> np.ndarray:
"""Cột: X, Y, TVDSS (m), MD (m)."""
"""Columns: X, Y, TVDSS (m), MD (m)."""
return np.loadtxt(path)
@@ -91,7 +91,7 @@ def load_well(name: str, wells_dir: Path | None = None) -> Well:
kb = float(las.well["EKB"].value)
markers = read_markers(d / "Tops" / f"{name}_markers.txt")
# File checkshot có dòng trùng (nhiều marker cùng độ sâu) và không theo thứ tự (F03-2, F03-4).
# Checkshot files contain duplicate rows (several markers at the same depth) and are unsorted (F03-2, F03-4).
cs = read_two_columns(d / "Checkshot" / f"{name}_TD.txt")
checkshot = (
pd.DataFrame({"md": cs[:, 0], "twt_ms": cs[:, 1] * 1000.0})
@@ -102,12 +102,12 @@ def load_well(name: str, wells_dir: Path | None = None) -> Well:
def load_td_source(name: str, source: str) -> np.ndarray:
"""Cặp (MD m, TWT ms) từ một nguồn TD.
"""(MD m, TWT ms) pairs from a TD source.
source:
"checkshot" – Checkshot/*_TD.txt (thời gian marker đã tie với horizon, giây)
"dt_model" – DT_model/*_TD.txt (ms; nguồn gốc chưa rõ, lệch checkshot, plan mục 1.2c)
"wlt" – WellInfo/*.wlt (Depth2Time model của OpendTect, giây)
"checkshot" – Checkshot/*_TD.txt (marker times tied to horizons, seconds)
"dt_model" – DT_model/*_TD.txt (ms; unknown provenance, offset from checkshot, plan §1.2c)
"wlt" – WellInfo/*.wlt (OpendTect Depth2Time model, seconds)
"""
d = f3_wells_dir()
if source == "checkshot":
@@ -118,4 +118,4 @@ def load_td_source(name: str, source: str) -> np.ndarray:
if source == "wlt":
a = read_two_columns(f3_root() / "WellInfo" / f"{name}.wlt", skip_header=True)
return np.column_stack([a[:, 0], a[:, 1] * 1000.0])
raise ValueError(f"nguồn TD không hợp lệ: {source}")
raise ValueError(f"invalid TD source: {source}")