Special Orthogonal Group

\(\operatorname{SO}(n)\) is the special orthogonal group, that is, the square matrices with orthonormal columns and positive determinant:

\[\operatorname{SO}(n) = \{X \in \mathbb{R}^{n\times n}\:\mid\:X^\intercal X = \mathrm{I}_n,\,\det(X) = 1\}\]
class geotorch.SO(size, triv='expm', lower=True)[source]

Manifold of square orthogonal matrices with positive determinant parametrized in terms of its Lie algebra, the skew-symmetric matrices.

Parameters
  • size (torch.size) – Size of the tensor to be parametrized

  • triv (str or callable) – Optional. A map that maps skew-symmetric onto \(\operatorname{SO}(n)\) surjectively. It can be one of ["expm", "cayley"] or a custom callable. Default: "expm"

  • lower (bool) – Optional. Uses the lower triangular part of the matrix to parametrize the skew-symmetric matrices. Default: True

sample(distribution='uniform', init_=None)[source]

Returns a randomly sampled orthogonal matrix according to the specified distribution. The options are:

  • "uniform": Samples a tensor distributed according to the Haar measure on \(\operatorname{SO}(n)\)

  • "torus": Samples a block-diagonal skew-symmetric matrix. The blocks are of the form \(\begin{pmatrix} 0 & b \\ -b & 0\end{pmatrix}\) where \(b\) is distributed according to init_. This matrix will be then projected onto \(\operatorname{SO}(n)\) using self.triv

Parameters
  • distribution (string) – Optional. One of ["uniform", "torus"]. Default: "uniform"

  • init_ (callable) – Optional. To be used with the "torus" option. A function that takes a tensor and fills it in place according to some distribution. See torch.init. Default: \(\operatorname{Uniform}(-\pi, \pi)\)

in_manifold(X, in_so=False, eps=0.0001)[source]

Checks that a matrix is in the manifold.

For tensors with more than 2 dimensions the first dimensions are treated as batch dimensions.

Parameters
  • X (torch.Tensor) – The matrix to be checked

  • in_so (bool) – Optional. Checks that the matrix is orthogonal and has positive determinant. Otherwise just orthogonality is checked. Default: False

  • eps (float) – Optional. Tolerance to numerical errors. Default: 1e-4

geotorch.so.uniform_init_(tensor)[source]

Fills in the input tensor in place with an orthogonal matrix. If square, the matrix will have positive determinant. The tensor will be distributed according to the Haar measure. The input tensor must have at least 2 dimensions. For tensors with more than 2 dimensions the first dimensions are treated as batch dimensions.

Parameters

tensor (torch.Tensor) – a 2-dimensional tensor or a batch of them

geotorch.so.torus_init_(tensor, init_=None, triv=<built-in method matrix_exp of type object>)[source]

Fills in the input tensor in place as a block-diagonal skew-symmetric matrix. The blocks are of the form \(\begin{pmatrix} 0 & b \\ -b & 0\end{pmatrix}\) where \(b\) is distributed according to init_. This matrix is then projected onto the manifold using triv.

The input tensor must have at least 2 dimension. For tensors with more than 2 dimensions the first dimensions are treated as batch dimensions.

Parameters
  • tensor (torch.Tensor) – a 2-dimensional tensor

  • init_ (callable) –

    Optional. A function that takes a tensor and fills it in place according to some distribution. See torch.init. Default: \(\operatorname{Uniform}(-\pi, \pi)\)

  • triv (callable) – Optional. A function that maps skew-symmetric matrices to orthogonal matrices.