scipy.stats.special_ortho_group#

scipy.stats.special_ortho_group = <scipy.stats._multivariate.special_ortho_group_gen object>[source]#

A Special Orthogonal matrix (SO(N)) random variable.

Return a random rotation matrix, drawn from the Haar distribution (the only uniform distribution on SO(N)) with a determinant of +1.

The dim keyword specifies the dimension N.

Parameters:
dimscalar

Dimension of matrices

seed{None, int, np.random.RandomState, np.random.Generator}, optional

Used for drawing random variates. If seed is None, the RandomState singleton is used. If seed is an int, a new RandomState instance is used, seeded with seed. If seed is already a RandomState or Generator instance, then that object is used. Default is None.

Methods

rvs(dim=None, size=1, random_state=None)

Draw random samples from SO(N).

Notes

The rvs method returns a random rotation matrix drawn from the Haar distribution, the only uniform distribution on SO(N). The algorithm generates a Haar-distributed orthogonal matrix in O(N) using the rvs method of ortho_group, then adjusts the matrix to ensure that the determinant is +1.

For a random rotation in three dimensions, see scipy.spatial.transform.Rotation.random.

Examples

>>> import numpy as np
>>> from scipy.stats import special_ortho_group
>>> x = special_ortho_group.rvs(3)
>>> np.dot(x, x.T)
array([[  1.00000000e+00,   1.13231364e-17,  -2.86852790e-16],
       [  1.13231364e-17,   1.00000000e+00,  -1.46845020e-16],
       [ -2.86852790e-16,  -1.46845020e-16,   1.00000000e+00]])
>>> import scipy.linalg
>>> scipy.linalg.det(x)
1.0

This generates one random matrix from SO(3). It is orthogonal and has a determinant of 1.

Alternatively, the object may be called (as a function) to fix the dim parameter, returning a “frozen” special_ortho_group random variable:

>>> rv = special_ortho_group(5)
>>> # Frozen object with the same methods but holding the
>>> # dimension parameter fixed.