data_transfer / bbflow_base /tests /test_alignment.py
hanghang214's picture
Add files using upload-large-folder tool
24599ef verified
Raw History Blame Contribute Delete
1.24 kB
import torch
from bbflow.models.latent import LatentEncoder
from scripts.probe_condition_ensemble_cov import align_to_reference as probe_align_to_reference
def _known_rotation_case():
reference = torch.tensor(
[
[0.0, 0.0, 0.0],
[2.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 3.0],
[1.0, 2.0, 4.0],
],
dtype=torch.float32,
)
rotation = torch.tensor(
[[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]],
dtype=torch.float32,
)
translation = torch.tensor([4.0, -3.0, 2.0])
moving = reference @ rotation + translation
mask = torch.ones(reference.shape[0])
return reference, moving, mask
def test_latent_kabsch_recovers_known_row_vector_rotation():
reference, moving, mask = _known_rotation_case()
aligned = LatentEncoder.align_to_reference(moving[None], reference, mask)
assert torch.allclose(aligned[0], reference, atol=1e-5, rtol=1e-5)
def test_probe_kabsch_recovers_known_row_vector_rotation():
reference, moving, mask = _known_rotation_case()
aligned = probe_align_to_reference(moving[None], reference, mask)
assert torch.allclose(aligned[0], reference, atol=1e-5, rtol=1e-5)