|
1 | 1 | import numpy as np |
2 | 2 | import pytest |
3 | 3 |
|
4 | | -from aspire.abinitio import JSync, g_sync |
| 4 | +from aspire.abinitio import JSync, compare_rots_sym, g_sync |
5 | 5 | from aspire.abinitio.commonline_utils import ( |
6 | 6 | _complete_third_row_to_rot, |
7 | 7 | _estimate_third_rows, |
@@ -186,3 +186,30 @@ def test_g_sync(symmetry): |
186 | 186 | np.testing.assert_allclose( |
187 | 187 | gs[best_g] @ gt_rots_synced_to_clean, desynced_clean_rots |
188 | 188 | ) |
| 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