ctt progress 2026-07-02 workspace/tests/test_ctt.py
Browse files- workspace/tests/test_ctt.py +19 -1
workspace/tests/test_ctt.py
CHANGED
|
@@ -3,7 +3,7 @@ import pytest
|
|
| 3 |
torch = pytest.importorskip("torch")
|
| 4 |
|
| 5 |
from cil.models import CTTConfig, CausalTangentTransport, ChartEncoder, TangentNormalizer
|
| 6 |
-
from cil.models.ctt import chamfer_to_target_set, negative_boundary_loss
|
| 7 |
|
| 8 |
|
| 9 |
def test_ctt_variants_preserve_tangent_shape():
|
|
@@ -31,6 +31,24 @@ def test_chart_encoder_and_losses_are_finite():
|
|
| 31 |
|
| 32 |
assert torch.isfinite(chamfer_to_target_set(predicted, positives))
|
| 33 |
assert negative_boundary_loss(predicted, negatives, margin=0.2).item() == pytest.approx(0.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
def test_tangent_normalizer_round_trips():
|
|
|
|
| 3 |
torch = pytest.importorskip("torch")
|
| 4 |
|
| 5 |
from cil.models import CTTConfig, CausalTangentTransport, ChartEncoder, TangentNormalizer
|
| 6 |
+
from cil.models.ctt import chamfer_to_target_set, diversity_loss, negative_boundary_loss
|
| 7 |
|
| 8 |
|
| 9 |
def test_ctt_variants_preserve_tangent_shape():
|
|
|
|
| 31 |
|
| 32 |
assert torch.isfinite(chamfer_to_target_set(predicted, positives))
|
| 33 |
assert negative_boundary_loss(predicted, negatives, margin=0.2).item() == pytest.approx(0.0)
|
| 34 |
+
assert diversity_loss(predicted).item() >= 0.0
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_gated_residual_matches_documented_formula():
|
| 38 |
+
model = CausalTangentTransport(
|
| 39 |
+
CTTConfig(chart_feature_dim=10, chart_dim=2, tangent_dim=2, hidden_dim=4, variant="gated_residual")
|
| 40 |
+
)
|
| 41 |
+
for parameter in model.delta.parameters():
|
| 42 |
+
parameter.data.zero_()
|
| 43 |
+
for parameter in model.gate.parameters():
|
| 44 |
+
parameter.data.zero_()
|
| 45 |
+
model.delta[-1].bias.data[:] = torch.tensor([4.0, -2.0])
|
| 46 |
+
model.gate[2].bias.data[:] = torch.tensor([0.0, 0.0])
|
| 47 |
+
|
| 48 |
+
xi = torch.tensor([[2.0, 6.0]])
|
| 49 |
+
output = model(torch.zeros(1, 2), torch.zeros(1, 2), xi)
|
| 50 |
+
|
| 51 |
+
assert torch.allclose(output, torch.tensor([[3.0, 2.0]]), atol=1.0e-6)
|
| 52 |
|
| 53 |
|
| 54 |
def test_tangent_normalizer_round_trips():
|