Files
ML-Porosity/ml_porosity/models/cnn_gru.py
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

37 lines
1.3 KiB
Python
Raw Permalink 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.
"""Dilated CNN + 2-layer bidirectional GRU + 1×1 skip head.
Ported verbatim from `test 2/train_open_patch_v2.py` (class CNNGRU); the architecture is unchanged.
"""
from __future__ import annotations
import torch
import torch.nn as nn
class CNNGRU(nn.Module):
def __init__(self, in_ch: int, d: int = 64, pdrop: float = 0.05):
super().__init__()
self.cnn = nn.Sequential(
nn.Conv1d(in_ch, d, kernel_size=5, padding=2, dilation=1), nn.ReLU(),
nn.Dropout(pdrop),
nn.Conv1d(d, d, kernel_size=5, padding=4, dilation=2), nn.ReLU(),
nn.Dropout(pdrop),
nn.Conv1d(d, d, kernel_size=5, padding=8, dilation=4), nn.ReLU(),
)
self.gru = nn.GRU(
input_size=d, hidden_size=d, num_layers=2,
batch_first=True, bidirectional=True, dropout=0.0,
)
self.head = nn.Conv1d(2 * d, 1, kernel_size=1)
self.head_skip = nn.Conv1d(in_ch, 1, kernel_size=1)
self.bias = nn.Parameter(torch.zeros(1))
def forward(self, x: torch.Tensor) -> torch.Tensor:
# x: (B, C, L) -> (B, 1, L)
h = self.cnn(x)
h2, _ = self.gru(h.transpose(1, 2))
y_main = self.head(h2.transpose(1, 2))
y_skip = self.head_skip(x)
return y_main + y_skip + self.bias.view(1, 1, 1)