Skip to main content

Torch modules and utilities of equivariant/invariant learning

Project description

Symmetric Learning

PyPI version Python Version

Lightweight python package for doing geometric deep learning using ESCNN. This package simply holds:

  • Generic equivariant torch models and modules that are not present in ESCNN.
  • Linear algebra utilities when working with symmetric vector spaces.
  • Statistics utilities for symmetric random variables.

Installation

pip install symm-learning
# or
git clone https://github.com/Danfoa/symmetric_learning
cd symmetric_learning
pip install -e .

Structure


Linear Algebra

  • lstsq: Symmetry-aware computation of the least-squares solution to a linear system of equations with symmetric input-output data.
  • invariant_orthogonal_projector: Computes the orthogonal projection to the invariant subspace of a symmetric vector space.

Statistics

  • var_mean: Symmetry-aware computation of the variance and mean of a symmetric random variable.
  • cov: Symmetry-aware computation of the covariance / cross-covariance of two symmetric random variables.

Models

  • iMLP: Invariant MLP for learning invariant functions.
  • eMLP: Equivariant MLP for learning equivariant functions.

Torch Modules

Change2DisentangledBasis

Module for changing the basis of a tensor to a disentangled / isotypic basis.

IrrepSubspaceNormPooling

Module for extracting invariant features from a geometric tensor, giving one feature per irreducible subspace/representation.%

EquivMultivariateNormal

Utility layer to parameterize a G-equivariant multivariate Gaussian/Normal distribution:

\begin{aligned}
y &\sim \mathcal{N} \bigl(\mu(x), \Sigma(x)\bigr)& \\
\text{s.t.}
&\rho_Y(g)\mu(x) = \mu \bigl(\rho_X(g)\cdot x\bigr) \\
&\rho_Y(g)\Sigma(x)\rho_Y(g)^{\top} = \Sigma\bigl(\rho_X(g)\cdot x\bigr),
\quad \forall\, g \in G.
\end{aligned}

Such that the conditional probability distribution of y given x is $\mathbb{G}$-invariant to the simultaneous group action on $\mathcal{X}$ and $\mathcal{Y}$:

$$ P(y \mid x) = P(\rho_Y(g) y \mid \rho_X(g) x) \quad \forall g \in \mathbb{G}. $$

This means that if you want to parameterize a $\mathbb{G}$-equivariant stochastic function $y = f(x)$ using neural networks, you can use any backbone architecture whose output are the input parameters of a EquivMultivariateNormal distribution, as shown below:

from escnn.group import CyclicGroup
from escnn.nn import FieldType
from symm_learning.models.emlp import EMLP
from symm_learning.nn.equiv_multivariate_gaussian import EquivMultivariateNormal

G = CyclicGroup(3)
x_type = FieldType(escnn.gspaces.no_base_space(G), representations=[G.regular_representation])
y_type = FieldType(escnn.gspaces.no_base_space(G), representations=[G.regular_representation] * 1)
# Instanciate the output equivariant multivariate normal distribution in order to get the NN output type
e_normal = EquivMultivariateNormal(y_type, diagonal=True)
# Instanciate your NN model to output the parameters of the distribution
nn = EMLP(in_type=x_type, out_type=e_normal.in_type)
# Sample from the distribution
x = x_type(torch.randn(10, x_type.size))
z = nn(x) # (B, dim_y + n_dof_cov)
dist = e_normal.get_distribution(z) # instance of  torch.distributions.MultivariateNormal
y = dist.sample()  # (B, n)

Here, $z$ is a (batch_size, dim_y + n_dof_cov) input tensor with the first dim_y entries defining the mean of the distribution $\mu(x)$ and the next n_dof_cov entries define the free degrees of freedom from the symmetry constrained covariance matrix. See below

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

symm_learning-0.2.4.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

symm_learning-0.2.4-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file symm_learning-0.2.4.tar.gz.

File metadata

  • Download URL: symm_learning-0.2.4.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for symm_learning-0.2.4.tar.gz
Algorithm Hash digest
SHA256 d4e7335ba10cbf5e79818b59aed5748754f12b4161250895c60cde36d5f57ef1
MD5 f0667221bc75b88918059d7ab7679a3d
BLAKE2b-256 f74170e26b3ef0bf1f656a97d95f1c64236a6d68f90c80f831bba04f232e54e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for symm_learning-0.2.4.tar.gz:

Publisher: publish2pypi.yaml on Danfoa/symmetric_learning

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file symm_learning-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: symm_learning-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for symm_learning-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2d16faf3f65e81aeb4745946faaca8dc1bd28776f01ec0d0a278de9dac67f274
MD5 8e30a48d66a41a9e5afa1a30e867ee5c
BLAKE2b-256 9a4d59ccf58406e2105480e855f731bf3c7b4d7fa06c169a18cc295e247762cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for symm_learning-0.2.4-py3-none-any.whl:

Publisher: publish2pypi.yaml on Danfoa/symmetric_learning

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page