P0 + P1: ml_porosity package, audited F3 data, LOWO baselines, protocol v2
P0 - ml_porosity/: survey geometry, LAS/TDR/SEG-Y readers (4 ms delay fix, invalid time scalar, header LUT for incomplete cubes), anti-aliased log-to-time resampling, CNN-GRU v2 with the thesis loss, 41+ unit tests. - Full F3 Demo 2023 under data/ (text well/fault files tracked, bulk data ignored); the filtered copy and its cleanup notes are removed. - SHA-256 manifests for F3, Volve, NLOG and the thesis outputs. P1 - configs/protocol.yaml v2, locked by SHA-256 at 2026-10-26T04:28:09Z, before the first LOWO run (04:30:50Z); 05_lowo.py refuses to run on a hash mismatch. This commit postdates the runs. - Wavelet/synthetic tie QC, residual misregistration, LOWO 5 seeds for B0a, B0b, B1, B2, B3a, B3b (scripts 04-06); gate G-A: no pivot. - Volve D3: horizons, well picks, checkshots and the ST10010 cube read from data/Volve (scripts/07). - D-1 label check against measured NLOG density (scripts/08): PHIE_DT stays the primary label. - docs/plan.md, Volve and NLOG inventories, report.html. Full-text reference PDFs in refs/ stay local (ignored). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
0
ml_porosity/eval/__init__.py
Normal file
0
ml_porosity/eval/__init__.py
Normal file
60
ml_porosity/eval/metrics.py
Normal file
60
ml_porosity/eval/metrics.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""Metric điểm cơ bản; bỏ qua mẫu NaN ở cả hai phía."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
def _valid(y_true, y_pred):
|
||||
y_true = np.asarray(y_true, dtype=float)
|
||||
y_pred = np.asarray(y_pred, dtype=float)
|
||||
ok = np.isfinite(y_true) & np.isfinite(y_pred)
|
||||
return y_true[ok], y_pred[ok]
|
||||
|
||||
|
||||
def point_metrics(y_true, y_pred) -> dict[str, float]:
|
||||
t, p = _valid(y_true, y_pred)
|
||||
err = p - t
|
||||
var_t = float(np.var(t))
|
||||
return {
|
||||
"n": int(t.size),
|
||||
"mae": float(np.mean(np.abs(err))),
|
||||
"rmse": float(np.sqrt(np.mean(err**2))),
|
||||
"pcc": float(np.corrcoef(t, p)[0, 1]) if t.size > 1 else float("nan"),
|
||||
"r2": float(1.0 - np.mean(err**2) / var_t) if var_t > 0 else float("nan"),
|
||||
"std_ratio": float(np.std(p) / np.std(t)) if np.std(t) > 0 else float("nan"),
|
||||
}
|
||||
|
||||
|
||||
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)."""
|
||||
from scipy import signal
|
||||
|
||||
y = np.asarray(y, dtype=float)
|
||||
sos = signal.butter(order, f_c_hz, fs=1000.0 / dt_ms, output="sos")
|
||||
low = signal.sosfiltfilt(sos, y, padtype="even")
|
||||
return low, y - low
|
||||
|
||||
|
||||
def band_metrics(y_true, y_pred, f_c_hz: float = 6.0, dt_ms: float = 4.0) -> dict[str, float]:
|
||||
lt, ht = split_bands(y_true, f_c_hz, dt_ms)
|
||||
lp, hp = split_bands(y_pred, f_c_hz, dt_ms)
|
||||
lo, hi = point_metrics(lt, lp), point_metrics(ht, hp)
|
||||
return {f"low_{k}": lo[k] for k in ("rmse", "pcc", "std_ratio")} | {
|
||||
f"band_{k}": hi[k] for k in ("rmse", "pcc", "std_ratio")
|
||||
}
|
||||
|
||||
|
||||
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."""
|
||||
from scipy import stats
|
||||
|
||||
y, mu, s = (np.asarray(a, dtype=float) for a in (y_true, mu, sigma))
|
||||
z = (y - mu) / s
|
||||
nll = float(np.mean(0.5 * np.log(2 * np.pi * s**2) + 0.5 * z**2))
|
||||
crps = float(np.mean(s * (z * (2 * stats.norm.cdf(z) - 1) + 2 * stats.norm.pdf(z) - 1 / np.sqrt(np.pi))))
|
||||
out = {"nll": nll, "crps": crps, "mean_sigma": float(np.mean(s))}
|
||||
for level in (50, 80, 90, 95):
|
||||
q = stats.norm.ppf(0.5 + level / 200)
|
||||
out[f"coverage_{level}"] = float(np.mean(np.abs(z) <= q))
|
||||
return out
|
||||
Reference in New Issue
Block a user