Taming Symmetry: A Dive into Lie Groups with Python

11 min read Original article โ†—

Lie groups play a crucial role in Geometric Deep Learning by modeling symmetries such as rotation, translation, and scaling. This enables non-linear models to generalize effectively for tasks like object detection and transformations in generative models.

Geometric Deep Learning, World Models use complex math to overcome limitations of traditional deep learning. We make that math practical through hands-on tutorials.

  1. Why this Matters

  2. Key Takeaways

  3. Lie Groups Basics

    ๐Ÿ›๏ธ Quest for Symmetry

    ๐Ÿ›๏ธ Differential Geometry

    ๐Ÿ›๏ธ Smooth Manifolds

    ๐Ÿ›๏ธ Exponential & Logarithm Maps

    ๐Ÿ›๏ธ Lie Groups

    ๐Ÿ›๏ธ Lie Algebras

  4. Lie Groups Deep Dive

    ๐Ÿ“š Geomstats

    โš™๏ธ Python Environment

    โš™๏ธ Setup

    โš™๏ธ Special Orthogonal Group

    โš™๏ธ Special Euclidean Group

    Animation

  5. References

  6. Q&A

  7. Paper Review

๐Ÿ‘‰ Patrick Nicolas is a 30-year software engineering veteran and consultant specializing in Geometric Deep Learning and World Models, author of Scala for Machine Learning, and writer of Geometric Learning in Python.

Purpose: Identifying symmetries in datasets and models is essential for analyzing complex problems and simplifying deep learning architectures.

Audience: Data scientists and engineers curious about Lie groups and their applications in machine learning.

Value: Develop practical expertise in Lie groups and Lie algebras through hands-on exploration of the 3-dimensional Special Orthogonal (SO3) and Special Euclidean (SE3) groups.

  • Lie groups simplify manifold analysis by capturing and utilizing symmetries present in datasets.

  • Lie algebra enables the study of complex nonlinear transformations by working with a simpler linear structure in the tangent space.

  • The Geomstats library equips data scientists with differential geometry tools, including manifolds and Lie groups, to facilitate the development of nonlinear statistical and machine learning models.

  • Among these, SO(3) and SE(3) are particularly well-suited for learning, as their manifold and algebraic structures can be easily visualized and interpreted.

This article leverages the Python Geomstats, introduced in a previous article Overview of Geomstats for Geometric Learning

Symmetry is the organizing principle behind geometric deep learning. It tells you what should not change (invariance) or how things should change (equivariance) when you transform the input

The terms symmetry, invariance and equivariance can be confusing.

  • Symmetry (Webster dictionary): The property of remaining invariant under certain changes (as of orientation in space, of the sign of the electric charge, of parity, or of the direction of time flow) โ€”used of physical phenomena and of equations describing them

  • Invariance: The output doesnโ€™t change when the input is transformed. Example: a cat classifier still predicts โ€œcatโ€ for an upside-down photo.

  • Equivariance: The output changes in a predictable way under the same transformation. Example: rotate an image, and the predicted segmentation mask rotates accordingly.

A function f is invariant, given a group G if for any transformation g

\(g \in G, \ x \in X \ \ \ \ f(g(x))=f(x) \)

A function f is equivariant, given a group G if for any transformation g, a group action on input rho|x and a group action on outputs rho|y

\(g \in G, \ \ x \in X \ \ \ \ f(\rho_{x}(g))(x)=\rho_{y}(g)(f(x)) \)

The relation is simplified in the case the group actions are identical and no group actions.

\(g \in G, \ \ x \in X \ \ \ \ f(g)(x)=g(f(x)) \)

The concept of symmetry and invariance can be easily illustrated in the context of computer vision. Vision models are often trained to be invariant to common geometric transforms:

  • Translation: horizontal/vertical shifts; the object is recognized regardless of image location.

  • Rotation: turning the image by some angle.

  • Scaling: resizing the object.

  • Affine transforms: compositions of translation, rotation, scaling, and shear; they preserve straightness and parallel lines.

I highly recommend that readers unfamiliar with the fundamental concepts of differential geometry and their significance in Geometric Deep Learning explore Introduction to Geometric Deep Learning [ref 1]

Lie groups are mathematical structures that combine the properties of groups and smooth manifolds, meaning they support both algebraic and differentiable operations. Named after the Norwegian mathematician Sophus Lie, these groups play a fundamental role in continuous symmetries, particularly in physics and geometry.

A Lie algebra is the tangent space at the identity element of a Lie group, equipped with a special operation called the Lie bracket, which encodes the infinitesimal structure of the group.

โš ๏ธ A thorough tutorial and explanation of Lie groups, Lie algebras, and geometric priors for deep learning models is beyond the scope of this article. Instead, the following sections concentrate on experiments involving key elements and operations on Lie groups using the Geomstats Python library.

  • Continuity and Differentiability: Lie groups are differentiable manifolds, allowing the application of calculus.

  • Group Structure: They satisfy closure, associativity, identity, and inverse properties.

  • Infinitesimal Generators: The corresponding Lie algebra describes local (infinitesimal) symmetries, making them useful for transformations.

Lie groups provide a powerful mathematical framework for encoding symmetry, invariance, and geometric structure in machine learning models.

  1. Data Augmentation & Invariance

    • Many datasets exhibit symmetries (e.g., images are invariant to rotations and translations).

    • Lie groups help define equivariant neural networks that maintain these symmetries.

  2. Geometric Deep Learning

    • Lie groups are used in manifold learning, graph neural networks (GNNs), and generative models to impose structured constraints. (i.g., SE(3)-equivariant networks in molecular modeling respect 3D rotational and translational symmetry).

  3. Optimization & Lie Algebra Representations

    • Optimization problems in deep learning can be formulated on Lie groups (e.g., in Riemannian optimization, where parameters evolve on curved manifolds).

    • The exponential and logarithm maps of Lie groups facilitate structured gradient-based learning.

  4. Physics-Inspired AI

    • In reinforcement learning and robotics, Lie groups model rigid body motion essential to robotsโ€™ perception and control.

๐Ÿ“Œ I highly recommend readers to get acquainted with manifolds to browse through two previous articles

  1. Riemannian Manifolds: Foundational Concepts

  2. Riemannian Manifolds: Hands-on with Hypersphere

Letโ€™ start with a brief review of the key mathematical concepts behind the Lie groups:

Differential geometry is an extensive and intricate area that exceeds what can be covered in a single article or blog post. There are numerous outstanding publications, papers and tutorials [ref 2, 3, 4] that provide foundational knowledge in differential geometry and tensor calculus, catering to both beginners and experts.

A manifold is a topological space that, around any given point, closely resembles Euclidean space. Specifically, an n-dimensional manifold is a topological space where each point is part of a neighborhood that is homeomorphic to an open subset of n-dimensional Euclidean space. Examples of manifolds include one-dimensional circles, two-dimensional planes and spheres, and the four-dimensional space-time used in general relativity.

A smooth (or differential) manifold is a topological space that locally resembles Euclidean space and allows for smooth (infinitely differentiable) transitions between local coordinate systems. This structure allows for the use of calculus on the manifold.

A Riemannian manifold is a smooth manifold that comes with a metric tensor, providing a way to measure distances and angles.

The tangent space at a point on a manifold is the set of tangent vectors at that point, like a line tangent to a circle or a plane tangent to a surface.

Tangent vectors can act as directional derivatives, where you can apply specific formulas to characterize these derivatives.

A geodesic is the shortest path (arc) between two points in a Riemannian manifold.

Given a Riemannian manifold M and a tangent space TM, an exponential map is a map from a subset of a tangent space of a Riemannian manifold.

Given a tangent vector v at a point p on a manifold, there is a unique geodesic Gv that satisfy Gv(0)=p and Gโ€™v(0)=v. The exponential map is defined as expp(v)= Gv(1)

\(exp_{p}: \mathcal{T}_{p}\to \mathcal{M} \ \ \ \ \ \ exp_{p}(v)=G_{v}(1)\)

For the same Riemannian manifold, given a geodesic Gv starting at point p with a direction v., the logarithm map is defined as

\(log_{p}: \mathcal{M} \to \mathcal{T}_{p} \ \ \ \ \ \ log_{p}(G_{v}(1))= v\)

The exponential and logarithm maps are illustrated below:

Fig. 1 Manifold with tangent space and exponential/logarithm maps

โš ๏ธ. Lie groups do not resemble spheres or hyperspheres, but we use them here purely for illustrative purposes.

Lie groups play a crucial role in Geometric Deep Learning by modeling symmetries such as rotation, translation, and scaling.

In differential geometry, a Lie group is a mathematical structure that combines the properties of both a group and a smooth manifold. It allows for the application of both algebraic and geometric techniques. As a group, it has an operation (like multiplication) that satisfies certain axioms (closure, associativity, identity, and invertibility) [ref 5, 6].

A 'real' Lie group is a set G with two structures: G is a group and G is a (smooth, real) manifold. These structures agree in the following sense multiplication (a.k.a. product or composition) and inversion are smooth maps.

A morphism of Lie groups is a smooth map which also preserves the group operation:

\(f(gh)=f(g)f(h) \ \ \ \ \ \ f(I_{d})=I_{d}\)

Here are some commonly used Lie groups.

The General Linear Group, denoted as GL(n,R) (or GL(n,C) for complex values) is the set of all invertible nร—n matrices with real entries, equipped with matrix multiplication as the group operation. It is a Lie group because it forms a smooth differentiable manifold and supports continuous transformations.

\(\begin{matrix} 2\ast 2 \ \ Invertible \ Matrix \ on \ \mathbb{R} & GL(2, \mathbb{R}) =\left\{ \begin{bmatrix} a & b \\ c & d \end{bmatrix} \ a, b, c, d \in \mathbb{R}, \ \ ad-bc \neq 0 \right\} \\ 2\ast2 \ \ Invertible \ Matrix \ on \ \mathbb{C} & GL(2, \mathbb{C})=\left\{ \begin{bmatrix} a & b \\ c & d \end{bmatrix} \ a, b, c, d \in \mathbb{C}, \ \ ad-bc \neq 0 \right\} \\ 3\ast3 \ \ Invertible \ Matrix \ on \ \mathbb{R} & GL(3, \mathbb{R})=\left\{ \begin{bmatrix} a & b & c\\ d & e & f \\ g & h & i \end{bmatrix} \ a, b, c, d, e, f, g, h, i \in \mathbb{R}, \ det \neq 0 \right\} \\ \end{matrix}\)

The Symmetric Positive Definite (SPD) Group, denoted as SPD(n), is the Lie group of all nร—n real symmetric positive definite matrices. It plays a crucial role in statistics, machine learning, optimization, and Riemannian geometry.

\(SPD(n)=\left\{ S\in \mathbb{R}^{n\ast n} \ | \ \ S^{T}=S, \ [1] \ \ \ \ x^{T}Sx \gt 0, \ \ \forall x\neq 0 \ \ [2] \right\}\)

  1. Specifies the symmetry condition

  2. Ensures the positive definite condition

The Special Orthogonal Groups SO(2) (resp. SO(3)) are the Lie groups that represents rotations in 2-dimensional (resp. 3-dimensional) space. It is widely used in robotics, physics, computer vision, and geometric deep learning to describe rigid body rotations without scaling or reflection.

\(\begin{matrix} 2D \ Rotation & SO(2)=\left\{ R \in \mathbb{R}^{2 \ast 2} \ | \ R.R^{-1}=I_{d}, \ [1] \ \ \ det(R)=1 \ \ [2] \right\} \\ 3D \ Rotation & SO(3)=\left\{ A \in \mathbb{R}^{3 \ast 3} \ | \ R.R^{-1}=I_{d}, \ [1] \ det(R)=1 \ \ [2]\right\} \end{matrix}\)

  1. Enforces orthogonally for which the 2 or 3 unit of rotations are mutually perpendicular

  2. Ensures rotation and preserves orientation

The Euclidean group is a subset of the broader affine transformation group. It contains the translational and orthogonal groups as subgroups. The Special Euclidean Group is a subgroup of Euclidean group. Any element of SE(n) can be represented as a combination of a translation and an orthogonal transformation, where the translation B can either precede or follow the orthogonal transformation A.

In robotics and physics, an element of SE(3) is often referred to as a rigid transformation, since it describes a rotation + translation without scaling or deformation.

\(SE(3)=\left\{ \begin{vmatrix} R & t \\ 0 & 1 \end{vmatrix} \in \mathbb{R}^{4 \ast 4} \ \ | \ R \in SO(3), t \in \mathbb{R}^{3} \right\}\)

An element is represented as a 4ร—4 homogeneous transformation matrix for which R is a SO(3) rotation matrix and t is a 3-dimensional translation vector.

Lie algebra can be viewed as the tangent space to the Lie group at the identity. Lie algebra can be viewed as the tangent space to the Lie group at the identity which linearize the group element near the identity.

For example, the group SO(n) of rotations is the group of orientation-preserving isometries of the Euclidean space. The Lie algebra so(n, R) consisting of real skew symmetric n ร— n matrices is the corresponding set of infinitesimal rotations.

Fig. 2 Visualization of SO3 Lie groups and its algebra of 3x3 skewed asymmetric matrices

โš ๏ธ Visualizing the SO(3) manifold in three dimensions is inherently challenging. In this example, we represent the space of rotations as a solid ball, where the center corresponds to the identity rotation and each point within the ball encodes a rotation using the axis-angle representation. Reference SO(3) Visualization

Theoretically, a Lie algebra is a mathematical structure used to study continuous symmetries, consisting of a vector space equipped with a bilinear operation called the Lie bracket, which satisfies

  • antisymmetry ([X,Y]=โˆ’[Y,X][X,Y]=โˆ’[Y,X])

  • Jacobi identity ([X,[Y,Z]]+[Y,[Z,X]]+[Z,[X,Y]]=0[X,[Y,Z]]+[Y,[Z,X]]+[Z,[X,Y]]=0).

The Lie bracket deserves a lengthly analysis and will be described in a future article.

๐Ÿ“Œ The terminology used for Lie groups and Lie algebras can sometimes be confusing, as it differs from traditional differential geometry definitions.

  • The identity element is often used instead of the base point in differential geometry.

  • A group element in Lie theory corresponds to what is traditionally called a point on the manifold.

  • An element of the Lie algebra corresponds to a tangent vector

This article adheres to the semi-official Lie group terminology for consistency.

๐Ÿ”“ The rest of this deep dive is exclusive to paid subscribers. By upgrading, you unlock this full article along with a comprehensive archive of engineering articles, paper review, concept breakdowns, code walkthrough, GitHub repository and Q&A.