Files
ML-Porosity/README.md
lamlvh cee2ff0859 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>
2026-10-27 06:03:33 +00:00

60 lines
6.6 KiB
Markdown
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.
# ML-Porosity
Dự đoán porosity từ seismic F3 khi well tie không chắc chắn. Kế hoạch: [docs/plan.md](docs/plan.md); tiến độ: `report.html`.
## Cài đặt
```bash
python -m venv .venv
.venv/bin/pip install -r requirements-lock.txt
.venv/bin/pip install --no-deps -e .
```
Dữ liệu F3 Demo 2023 đặt ở `data/F3_Demo_2023/F3_Demo_2023/`, dữ liệu Volve ở `data/Volve/`, LAS và TD của NLOG ở `data/NLOG/` (hoặc trỏ `ML_POROSITY_F3_ROOT` tới thư mục chứa `.survey`). Kết quả ghi vào `outputs/` (đổi bằng `ML_POROSITY_OUTPUTS`).
## Chạy
```bash
scripts/run_p0.sh # toàn bộ pipeline P0 và test
scripts/run_p1.sh # P1: tie QC, LOWO baseline (khoảng 16 phút với GPU)
scripts/run_p2.sh # P2: prior warp F3, QC D2, test, lưới D2, H1, tổng hợp (GPU cuda:1; đổi bằng DEVICE=...)
scripts/run_p3_dev.sh # chuẩn bị P3 trên dev 900/901: screen, train, stability, sigma_a, f3, h3 (+ stability_m5, b3d_old, train_sa)
```
Log và runtime: mỗi lần chạy `run_p*.sh` tạo `logs/runs/<YYYYmmdd-HHMMSS>_p*/`, mỗi bước là một thư mục con có `log.txt` (stdout + stderr, cả của worker, đầu dòng có thời gian đã trôi) và `meta.json` (lệnh, git commit + hash mã nguồn, biến luồng, thiết bị, wall/CPU time, RSS và VRAM đỉnh, mã thoát). Mỗi bước thêm một dòng vào `logs/index.csv`. Chạy lẻ một script thì bọc bằng `scripts/runlog.sh`:
```bash
scripts/runlog.sh scripts/15_diag_train.py --rids 900 901 --device cuda:1 # file .py chạy bằng .venv/bin/python
scripts/runlog.sh -n ten_rieng --note "ghi chú" -- <lệnh bất kỳ>
scripts/runlog.sh ls # các lần chạy gần nhất, cả lần đang chạy
```
`logs/runs/` không đẩy lên git; `logs/index.csv` thì có thể commit. Các dòng có `source=backfill` là lần chạy trước ngày 27/10/2026, dựng lại từ log còn lại và transcript (trường nào không đo được thì để trống). Chạy lại sau khi bị ngắt: `11_run_d2.py`, `14_diag_posterior.py`, `15_diag_train.py` bỏ qua các ô đã có CSV kết quả; `05_lowo.py` và `12_h1_blur.py` chạy lại từ đầu.
P2 theo `configs/protocol_p2.yaml` (khoá bằng `configs/protocol_p2.sha256`) và bộ sinh `configs/d2_synth.yaml`. P3 (sau khi cổng G-B của P2 trượt) theo `configs/protocol_p3.yaml` (khoá bằng `configs/protocol_p3.sha256` và tag git `protocol-p3`) và `configs/d2_synth_p3.yaml` (cùng bộ sinh, thêm các chế độ SNR × mật độ anchor); mọi lựa chọn của P3 dựa trên dev 900/901, tổng hợp ở `outputs/p2/diag/p3dev/summary.md`; lưới chính dùng realization 8–15.
Biến môi trường máy đặt sẵn `OMP_NUM_THREADS=40` (cả MKL, OpenBLAS): các script nhiều worker tự giới hạn luồng, còn khi chạy tay thì đặt rõ `OMP_NUM_THREADS`, `MKL_NUM_THREADS`, `OPENBLAS_NUM_THREADS` (và `CUDA_VISIBLE_DEVICES=` cho việc chỉ dùng CPU). Lý thuyết (Mệnh đề 1–2, chọn λ, các baseline là trường hợp riêng của RML): [docs/theory.md](docs/theory.md).
| Script | Việc |
| --- | --- |
| `scripts/00_data_manifest.py [--check] [--dataset f3\|volve\|nlog]` | Ghi/kiểm SHA-256 theo `data_manifest/*.json` (F3: 279 file) |
| `scripts/01_build_wells.py` | Vị trí giếng từ `.survey`, 4 TDR (legacy, calibrated, anchors, wlt), log sang thời gian có chống alias, trích patch seismic → `outputs/f3_wells.npz` |
| `scripts/02_td_qc.py` | Lệch của các nguồn TD so với marker → `outputs/figures/td_drift.png`, `outputs/td_qc.csv` |
| `scripts/03_train.py --config configs/b2_smoke.yaml` | CNN–GRU v2 + loss gốc (B2), split tách rời train/val/test (chạy thử P0) |
| `scripts/04_wavelet_tie.py` | Wavelet, synthetic 4 giếng, misregistration còn lại và ngưỡng nhiễu → `outputs/tie_qc.csv`, `outputs/figures/ties.png` |
| `scripts/05_lowo.py` | LOWO 5 seed cho B0a, B0b, B1, B2, B3a, B3b theo `configs/protocol.yaml` (kiểm hash trong `configs/protocol.sha256`) |
| `scripts/06_summarize_p1.py` | Bảng macro/theo giếng, calibration, G-A → `outputs/p1/summary.md`, `outputs/figures/p1_lowo.png` |
| `scripts/07_volve_interp_qc.py` | QC horizon, well picks, checkshot và cube ST10010 của Volve theo `configs/d3_volve.yaml` → `outputs/volve/` |
| `scripts/08_d1_label_check.py` | Kiểm tra D-1: porosity theo RHOB đo của NLOG so với nhãn sonic PHIE_DT → `outputs/d1/` |
| `scripts/09_fit_warp_prior_f3.py` | Fit prior warp GP Matérn-3/2 (type-II ML) trên marker TD của F3, kiểm tra leave-one-anchor-out → `outputs/p2/warp_prior_f3.json`, `outputs/figures/p2_f3_drift.png`. File json đã ghi hash trong protocol P2: không chạy lại khi đã có |
| `scripts/10_build_d2.py` | QC bộ sinh D2 so với F3 (nhãn, anchor, drift) → `outputs/d2/qc.json`, `outputs/figures/p2_d2_qc.png` |
| `scripts/11_run_d2.py --dev\|--main [--workers 6] [--device cuda:1]` | Mỗi ô (realization, c, N): đăng ký warp giếng train, huấn luyện Oracle, B3a–B3d, B4a–B4d, M1, M2 với 5 seed, chấm điểm trên 8 giếng test → `outputs/p2/{dev,main}/`. `--dev` chọn ngân sách bước; `--main` cần protocol khớp hash |
| `scripts/12_h1_blur.py [--workers 6] [--device cuda:1]` | H1: huấn luyện MSE với nhãn lệch δ ~ N(0, σ²), so hàm truyền đo được với exp(−2π²σ²f²) → `outputs/p2/h1/` |
| `scripts/13_summarize_p2.py [--mode main\|dev]` | Cổng G-B, bản đồ pha v1, H1, H3 (M2-ens so với B5), H4, chẩn đoán warp → `outputs/p2/summary/<mode>/`, `outputs/figures/p2_*.png` |
| `scripts/14_diag_posterior.py [--snr] [--anchor-density] [--sigma-a-reg] [--particles] [--smc-seeds] [--device cuda:1]` | Chẩn đoán posterior warp trên dev: SMC tôi luyện có điều kiện seismic (γ = 1/κ, pha phase_R ước lượng qua log Z), sai số warp, độ phủ, σ_post → `outputs/p2/diag/…` |
| `scripts/15_diag_train.py [--post-dir] [--methods] [--budgets-from] [--save-preds]` | Huấn luyện trên dev với nhãn từ posterior SMC (B3d-Sa, M2-Sa…) và các baseline, cổng kiểu G-B, ensemble kiểu H3 → `outputs/p2/diag/train*/` |
| `scripts/16_f3_posterior.py [--device cuda:1]` | Đặt F3 lên trục σ_post (chỉ mô tả): posterior SMC trên 4 giếng F3 → `outputs/p2/diag/f3_posterior/` |
| `scripts/17_summarize_p3_dev.py [--only …]` | Tổng hợp dev cho P3: screen, train/dose-response H2b, B(σ), stability, σ_a, F3 → `outputs/p2/diag/p3dev/summary.md` |
`test 2/` là bản lưu trữ code luận văn, không sửa.