Complete P4 Volve; pivot the manuscript to theory + benchmark
P4 (Volve field case). Add the deviated-well and Volve well builders (ml_porosity/data/deviated.py, volve_wells.py), the ml_porosity/volve/ pipeline, scripts 23-25, the run_p4 drivers and tests. The protocol configs/protocol_volve.yaml was locked at 2026-10-29T01:17:42Z before the run (.sha256, .lock.json) and is committed here after the run. Gate G-D failed: M2-Sa beats the selected B3 at 2/6 wells (lowo) and 3/6 (slot), coverage90 is about 0.47, and no method has blind-well skill (R2 < 0). A post hoc constant at the training-well mean beats every network, so G-D had no power. The dropped P4x exploratory run is kept as a record only (exploratory/, docs/research/p4-exploratory.md). Applicability and Teapot Dome (exploratory, pre-declared). Scripts 26-29 and docs/research/applicability-*.md: F3 and Volve fail C1 and pass C2; T3 power needs 5-18 blind wells with an exact reference; Teapot T0 and pilot P-a failed, so Teapot is stopped. Raw Teapot data stay gitignored. Manuscript (Pivot 1, level A). Reframe paper/ as a theory and synthetic benchmark paper: Propositions 3-6, Corollaries 3-4, T4 coverage (script 30) and the post hoc H2b bound check (script 31), with F3/Volve moved to Appendix B. Correct two earlier claims: the Berkson and classical bounds differ by 1.5-4.6x at the f^4-weighted band, and the bank gain exceeds the registered classical bound (7/8 wide cells at N = 16) but only 3/8 under the post hoc Berkson bound. Docs. Sync plan, AGENTS.md, README, report.html, theory and technical overview. The length pass for the venue is dropped by the user (plan section 12 item 25); the length risk stays recorded as R9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
140
scripts/30_t4_coverage.py
Normal file
140
scripts/30_t4_coverage.py
Normal file
@@ -0,0 +1,140 @@
|
||||
"""T4 (exploratory): why cleaner labels give lower coverage of seed-ensemble intervals (paper Proposition 5, prop:coverage).
|
||||
|
||||
Uses only saved P2r predictions (outputs/p2r/train/<regime>/cells/r<rid>_c<c>_n<N>.npz: y_true on the true warp
|
||||
of the 8 test wells, per-seed mu and sigma of every method at its selected budget). For each method the 5-seed
|
||||
ensemble has s_e^2 = s_al^2 + s_seed^2, with s_al^2 = mean_s sigma_s^2 (the heteroscedastic head) and
|
||||
s_seed^2 = var_s mu_s (ddof 0, as in H3). Per (regime, c, N, method), averaged over wells and samples, then over
|
||||
realizations:
|
||||
rms_al, rms_seed, rms_e square roots of the mean s_al^2, s_seed^2, s_e^2
|
||||
rmse, rmse_low, rmse_band error of the ensemble mean (total; below f_c and seismic band, split as in metrics.py)
|
||||
kappa mean s_e^2 / mean e^2 (1: matched second moment); the dispersion ratio xi of the paper
|
||||
cov90, cov90_al, cov90_seed coverage of the central 90% Gaussian interval with s_e, s_al only, s_seed only
|
||||
dvar, dmse mean s_e^2 and mean e^2 minus the Oracle's in the same realization
|
||||
Proposition 5(a): kappa_m - kappa_Oracle = (dvar - kappa_Oracle * dmse) / mse_m, so a misregistered source has the larger
|
||||
kappa (and, for Gaussian standardized errors, the larger coverage) iff dvar > kappa_Oracle * dmse; dvar >= dmse with
|
||||
kappa_Oracle <= 1 is sufficient. Also tabulated (budget_dev.csv): mean sigma, RMSE and coverage per training budget on
|
||||
the P2 dev realizations 900/901, the only runs that saved every budget, to show the effect of training length.
|
||||
Descriptive only: nothing here is a gate, and nothing is chosen with these numbers.
|
||||
|
||||
python scripts/30_t4_coverage.py # -> outputs/t4/
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
os.environ.setdefault("OMP_NUM_THREADS", "2")
|
||||
os.environ.setdefault("MKL_NUM_THREADS", "2")
|
||||
os.environ.setdefault("OPENBLAS_NUM_THREADS", "2")
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from scipy import stats
|
||||
|
||||
from ml_porosity.eval.metrics import split_bands
|
||||
from ml_porosity.paths import outputs_dir
|
||||
|
||||
OUT = outputs_dir() / "t4"
|
||||
REGIMES = ("R10", "R0", "Rm5", "R0h", "R10tb", "R10_sa3.5", "R10_sa14")
|
||||
METHODS = ("Oracle", "B3d-Sa", "M2-Sa", "B3d", "B3c-R", "B3c", "B3b")
|
||||
ENS = {m: ("B5" if m == "B3b" else f"{m}-ens") for m in METHODS}
|
||||
F_C, DT = 6.0, 4.0
|
||||
Z90 = stats.norm.ppf(0.95)
|
||||
|
||||
|
||||
def seeds(z, method: str) -> tuple[np.ndarray, np.ndarray]:
|
||||
keys = sorted(k for k in z.files if k.startswith(f"{method}/s") and k.endswith("/mu"))
|
||||
if len(keys) != 5:
|
||||
raise RuntimeError(f"{method}: expected 5 seeds, got {len(keys)}")
|
||||
return (np.stack([z[k] for k in keys]).astype(float),
|
||||
np.stack([z[k[:-2] + "sigma"] for k in keys]).astype(float))
|
||||
|
||||
|
||||
def well_rows() -> pd.DataFrame:
|
||||
rows = []
|
||||
for regime in REGIMES:
|
||||
for f in sorted((outputs_dir() / f"p2r/train/{regime}/cells").glob("r*_c*_n*.npz")):
|
||||
rid, c, n = f.stem.split("_")
|
||||
with np.load(f) as z:
|
||||
y = z["y_true"].astype(float)
|
||||
pred = {m: seeds(z, m) for m in METHODS}
|
||||
for m, (mu, sg) in pred.items():
|
||||
mu_e, v_al, v_seed = mu.mean(0), (sg**2).mean(0), mu.var(0)
|
||||
for i in range(y.shape[0]):
|
||||
ok = np.isfinite(y[i]) & np.isfinite(mu_e[i])
|
||||
e = y[i] - mu_e[i]
|
||||
lo, hi = split_bands(e[ok], F_C, DT)
|
||||
v_e = v_al[i] + v_seed[i]
|
||||
rows.append(dict(
|
||||
regime=regime, rid=int(rid[1:]), c=float(c[1:]), n_train=int(n[1:]), method=ENS[m], well=i,
|
||||
v_al=v_al[i][ok].mean(), v_seed=v_seed[i][ok].mean(), v_e=v_e[ok].mean(),
|
||||
mse=np.mean(e[ok] ** 2), mse_low=np.mean(lo**2), mse_band=np.mean(hi**2),
|
||||
cov90=np.mean(np.abs(e[ok]) <= Z90 * np.sqrt(v_e[ok])),
|
||||
cov90_al=np.mean(np.abs(e[ok]) <= Z90 * np.sqrt(v_al[i][ok])),
|
||||
cov90_seed=np.mean(np.abs(e[ok]) <= Z90 * np.sqrt(v_seed[i][ok]))))
|
||||
return pd.DataFrame(rows)
|
||||
|
||||
|
||||
def cells(w: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Mean over wells per realization; differences to the Oracle within the realization."""
|
||||
keys = ["regime", "c", "n_train", "rid", "method"]
|
||||
r = w.groupby(keys, as_index=False)[["v_al", "v_seed", "v_e", "mse", "mse_low", "mse_band", "cov90", "cov90_al",
|
||||
"cov90_seed"]].mean()
|
||||
o = r[r.method == "Oracle-ens"].set_index(keys[:-1])[["v_e", "mse"]]
|
||||
r = r.join(o, on=keys[:-1], rsuffix="_oracle")
|
||||
return r.assign(dvar=r.v_e - r.v_e_oracle, dmse=r.mse - r.mse_oracle, kappa=r.v_e / r.mse)
|
||||
|
||||
|
||||
def summary(r: pd.DataFrame) -> pd.DataFrame:
|
||||
g = r.groupby(["regime", "c", "n_train", "method"])
|
||||
s = g[["v_al", "v_seed", "v_e", "mse", "mse_low", "mse_band", "cov90", "cov90_al", "cov90_seed", "kappa", "dvar",
|
||||
"dmse"]].mean()
|
||||
s["frac_dvar_ge_dmse"] = g.apply(lambda d: float(np.mean(d.dvar >= d.dmse)), include_groups=False)
|
||||
s["n_rid"] = g.size()
|
||||
for k in ("v_al", "v_seed", "v_e", "mse", "mse_low", "mse_band"):
|
||||
s[k.replace("v_", "rms_") if k.startswith("v_") else k.replace("mse", "rmse")] = np.sqrt(s.pop(k))
|
||||
return s.reset_index()
|
||||
|
||||
|
||||
def budget_dev() -> pd.DataFrame:
|
||||
d = pd.read_csv(outputs_dir() / "p2/dev/results.csv")
|
||||
keys = ["c", "n_train", "method", "budget"]
|
||||
return d.groupby(keys, as_index=False)[["mean_sigma", "rmse", "low_rmse", "band_rmse", "coverage_90"]].mean()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
w = well_rows()
|
||||
w.to_csv(OUT / "wells.csv.gz", index=False)
|
||||
r = cells(w)
|
||||
r.to_csv(OUT / "cells.csv", index=False)
|
||||
s = summary(r)
|
||||
s.to_csv(OUT / "summary.csv", index=False)
|
||||
# Check against the registered H3 table (c = 1): ensemble coverage must reproduce it.
|
||||
h3 = pd.read_csv(outputs_dir() / "p2r/summary/h3.csv")
|
||||
chk = s[s.c == 1.0].merge(h3, on=["regime", "n_train", "method"], suffixes=("", "_h3"))
|
||||
dev = float(np.abs(chk.cov90 - chk.coverage_90).max()) if len(chk) else float("nan")
|
||||
budget_dev().to_csv(OUT / "budget_dev.csv", index=False)
|
||||
non_oracle = r[r.method != "Oracle-ens"]
|
||||
k_o = non_oracle.v_e_oracle / non_oracle.mse_oracle
|
||||
meta = dict(regimes=REGIMES, methods=[ENS[m] for m in METHODS], f_c_hz=F_C, dt_ms=DT, z90=float(Z90),
|
||||
n_well_rows=len(w), h3_cov90_max_abs_dev=dev, h3_rows_checked=len(chk),
|
||||
frac_dvar_ge_dmse_all=float(np.mean(non_oracle.dvar >= non_oracle.dmse)),
|
||||
frac_dvar_pos_all=float(np.mean(non_oracle.dvar > 0)),
|
||||
frac_kappa_gt_oracle_all=float(np.mean(non_oracle.kappa > k_o)),
|
||||
frac_cov90_gt_oracle_all=float(np.mean(non_oracle.cov90 > non_oracle.join(
|
||||
r[r.method == "Oracle-ens"].set_index(["regime", "c", "n_train", "rid"]).cov90.rename("cov90_o"),
|
||||
on=["regime", "c", "n_train", "rid"]).cov90_o)),
|
||||
low_band_share_of_mse=float((r.mse_low / r.mse).mean()),
|
||||
n_realization_cells=int(len(non_oracle)))
|
||||
(OUT / "meta.json").write_text(json.dumps(meta, indent=1, default=float))
|
||||
pd.set_option("display.width", 250)
|
||||
cols = ["regime", "c", "n_train", "method", "rms_al", "rms_seed", "rms_e", "rmse", "rmse_low", "rmse_band", "kappa",
|
||||
"cov90", "cov90_al", "cov90_seed", "frac_dvar_ge_dmse"]
|
||||
print(s[(s.c == 1.0) & s.regime.isin(["R10", "R0", "Rm5"])][cols].round(3).to_string(index=False))
|
||||
print(json.dumps(meta, indent=1, default=float))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user