Files
ML-Porosity/ml_porosity/volve/folds.py
lamlvh 0cfe202a8b 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>
2026-10-29 12:18:22 +00:00

75 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Nested blind folds for P4 (plan §5.2).
Outer fold: test well u, training wells T_out = blind_training_wells(u, scheme) (`lowo`: every other well; `slot`:
every well outside the slot group of u). Inner folds: leave one well of T_out out, under both schemes — under
`slot` an inner validation well may share a slot with inner training wells, so inner validation can be optimistic
there (recorded deviation in protocol_volve).
Every model sees seismic only through blind keys: the input of a non-training well u under key K is placed in time
by the TD model of the wells K, with T_in ⊆ K ⊆ W∖{u} (never u's own picks or DT). Validation of v in T_out uses
K = T_in; the outer test of u uses K = T_out. Training wells use their calibrated reference path.
"""
from __future__ import annotations
import itertools
from ml_porosity.data.volve_wells import blind_key, blind_training_wells
def outer_folds(wells: list[str], scheme: str, p4: dict) -> list[tuple[str, tuple[str, ...]]]:
"""[(test well u, T_out)] in `wells` order; T_out sorted."""
out = []
for u in wells:
train = tuple(sorted(blind_training_wells(u, scheme, p4)))
if u in train or not train:
raise RuntimeError(f"invalid outer fold for {u}: {train}")
out.append((u, train))
return out
def inner_folds(outer_train: tuple[str, ...]) -> list[tuple[str, tuple[str, ...]]]:
"""[(validation well v, T_in = T_out ∖ {v})], leave-one-well-out within the outer training set."""
train = tuple(sorted(outer_train))
if len(train) < 2:
raise ValueError("inner LOWO needs at least two outer training wells")
return [(v, tuple(w for w in train if w != v)) for v in train]
def nested_folds(wells: list[str], schemes: list[str], p4: dict) -> list[dict]:
"""Every (scheme, test well, validation well, T_out, T_in), with the blind key of each role."""
rows = []
for scheme in schemes:
for u, t_out in outer_folds(wells, scheme, p4):
for v, t_in in inner_folds(t_out):
if u in t_in or v in t_in:
raise RuntimeError("held-out well entered an inner training set")
rows.append(dict(scheme=scheme, test=u, validation=v, outer_train=t_out, inner_train=t_in,
validation_key=blind_key(t_in), test_key=blind_key(t_out)))
return rows
def training_sets(wells: list[str], schemes: list[str], p4: dict) -> list[tuple[str, ...]]:
"""Distinct inner training sets over all schemes (one trajectory per set, method, seed and σ_a arm)."""
return sorted({f["inner_train"] for f in nested_folds(wells, schemes, p4)}, key=lambda s: (-len(s), s))
def prediction_targets(wells: list[str], train: tuple[str, ...]) -> list[tuple[str, str]]:
"""(well, key) inputs predicted by a model trained on `train`: training wells on their reference path
(key 'reference'), every other well u on every blind key K with train ⊆ K ⊆ W∖{u}. Covers the validation
(K = T_in) and outer-test (K = T_out ⊋ T_in) inputs of every fold that trains on `train`."""
train = tuple(sorted(train))
out = [(w, "reference") for w in train]
for u in wells:
if u in train:
continue
rest = [w for w in wells if w != u and w not in train]
for k in range(len(rest) + 1):
for extra in itertools.combinations(rest, k):
out.append((u, blind_key(train + extra)))
return out
def target_name(well: str, key: str) -> str:
return f"{well}|{key}"