- 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>
25 lines
785 B
Python
25 lines
785 B
Python
import torch
|
||
|
||
from ml_porosity.losses.legacy_v2 import LegacyV2Loss, pcc_loss, shape_loss
|
||
from ml_porosity.models.cnn_gru import CNNGRU
|
||
|
||
|
||
def test_cnn_gru_shape():
|
||
m = CNNGRU(in_ch=9, d=16)
|
||
assert m(torch.randn(2, 9, 126)).shape == (2, 1, 126)
|
||
|
||
|
||
def test_shape_loss_redundant_with_pcc():
|
||
# plan §1.1 #7: L_shape = 2·L_PCC − 2/L (z-score uses the unbiased std, Σx² = L − 1)
|
||
torch.manual_seed(0)
|
||
p, t = torch.randn(4, 1, 126), torch.randn(4, 1, 126)
|
||
assert torch.allclose(shape_loss(p, t), 2 * pcc_loss(p, t) - 2 / 126, atol=1e-5)
|
||
|
||
|
||
def test_legacy_loss_finite_and_differentiable():
|
||
m = CNNGRU(in_ch=9, d=8)
|
||
x, y = torch.randn(2, 9, 64), torch.randn(2, 1, 64)
|
||
loss = LegacyV2Loss()(m(x), y)
|
||
loss.backward()
|
||
assert torch.isfinite(loss)
|