Skip to content

Commit

Permalink
Merge pull request #28 from compSPI/itr_ref_grid_so3
Browse files Browse the repository at this point in the history
Uniform discritization of SO(3) via random rotation matrices
  • Loading branch information
geoffwoollard authored Apr 3, 2022
2 parents af520c3 + f7baaa9 commit 4a5ef1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dependencies:
- pytorch
- pip :
- git+https://github.com/compSPI/simSPI.git
- geomstats

10 changes: 9 additions & 1 deletion reconstructSPI/iterative_refinement/expectation_maximization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Iterative refinement with Bayesian expectation maximization."""

import numpy as np
from geomstats.geometry import special_orthogonal
from simSPI.transfer import eval_ctf


Expand Down Expand Up @@ -299,6 +300,10 @@ def build_ctf_array(self):
def grid_SO3_uniform(n_rotations):
"""Generate uniformly distributed rotations in SO(3).
A note on functionality - the geomstats random_uniform library only produces
rotations onto one hemisphere. So, the rotations are randomly inverted, giving
them equal probability to fall in either hemisphere.
Parameters
----------
n_rotations : int
Expand All @@ -310,7 +315,10 @@ def grid_SO3_uniform(n_rotations):
Array describing rotations.
Shape (n_rotations, 3, 3)
"""
rots = np.ones((n_rotations, 3, 3))
geom = special_orthogonal.SpecialOrthogonal(3, "matrix")
rots = geom.random_uniform(n_rotations)
negatives = np.tile(np.random.randint(2, size=n_rotations) * 2 - 1, (3, 3, 1)).T
rots[:] *= negatives
return rots

@staticmethod
Expand Down

0 comments on commit 4a5ef1f

Please sign in to comment.