Skip to content

Commit 0524dc9

Browse files
committed
test compare_rots_sym
1 parent f4d723e commit 0524dc9

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

tests/test_commonline_utils.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from aspire.abinitio import JSync, g_sync
4+
from aspire.abinitio import JSync, compare_rots_sym, g_sync
55
from aspire.abinitio.commonline_utils import (
66
_complete_third_row_to_rot,
77
_estimate_third_rows,
@@ -186,3 +186,30 @@ def test_g_sync(symmetry):
186186
np.testing.assert_allclose(
187187
gs[best_g] @ gt_rots_synced_to_clean, desynced_clean_rots
188188
)
189+
190+
191+
@pytest.mark.parametrize("symmetry", ["C3", "C4", "D3", "D4", "T", "O"])
192+
def test_compare_rots_sym(symmetry):
193+
"""
194+
This method find the mean squared error between all pairs of rotations
195+
taking into account each rotation being multiplied by an arbitrary
196+
symmetry group element. In this test we check that a set of rotations
197+
multiplied by random symmetry group elements gives a zero MSE when compared
198+
to the original set.
199+
"""
200+
n = 100
201+
dtype = np.float64
202+
203+
# Get symmetry group matrices
204+
gs = SymmetryGroup.parse(symmetry).matrices
205+
206+
# Build set of ground truth rotations
207+
gt_rots = Rotation.generate_random_rotations(n, dtype=dtype).matrices
208+
209+
# Multiply by random group elements
210+
g_idx = np.random.randint(len(gs), size=n)
211+
rots_with_sym = gs[g_idx] @ gt_rots
212+
213+
# Check MSE is zero
214+
MSE = compare_rots_sym(rots_with_sym, gt_rots, symmetry)
215+
np.testing.assert_allclose(MSE, 0, atol=np.finfo(dtype).eps)

0 commit comments

Comments
 (0)