Taming Symmetry: A Dive into Lie Groups with Python

Taming Symmetry: A Dive into Lie Groups with Python

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.

🎯 Introduction
🎨 Theory
    Smooth Manifolds
    Exponential & Logarithm Maps
    Lie Groups
    Lie Algebras
    Geomstats 
⚙️ Hands-on with Python
    Environment
    Special Orthogonal Group
References        

What you will learn: 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.



The complete article, featuring design principles, detailed implementation, in-depth analysis, and exercises, is available at Taming Symmetries: A Dive into Lie Groups



🎯 Introduction

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

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.

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.


Key Properties:

  • Continuity & 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.

Applicability to Machine Learning

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.

🎨 Theory

Smooth Manifolds


📌📌 I highly recommend readers to get acquainted with manifolds to browse through two previous articles

  1. Riemannian Manifolds: 1 Foundation
  2. Riemannian Manifolds: 2 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 234] that provide foundational knowledge in differential geometry and tensor calculus, catering to both beginners and experts.

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.

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.

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.

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


Exponential & Logarithm Maps

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:

Article content

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

Article content

The exponential and logarithm maps are illustrated below:

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

Lie Groups

Lie groups play a crucial role in Geometric Deep Learning by modeling symmetriessuch 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 56].

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:

Article content

Example of Lie Groups


General Linear Group of invertible matrices

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.

Article content

Symmetric Positive Definite Group

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.

Article content

  • [1] Specifies the symmetry condition
  • [2] Ensures the positive definite condition

Special Orthogonal Group

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.

Article content

  • [1] Enforces orthogonally for which the 2 or 3 unit of rotations are mutually perpendicular
  • [2] Ensures rotation and preserves orientation.

Special Euclidean Group

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.

Article content

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.

Article content

Lie Algebras

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.

Article content
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.


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.

Geomstats 

Geomstats is a free, open-source Python library designed for conducting machine learning on data lying on nonlinear manifolds, an area known as Geometric Learning.

The core concept of Geomstats is to incorporate differential geometry principles, such as manifolds and Lie groups, into the development of statistical and machine learning models. This open-source, object-oriented library follows Scikit-Learn’s API conventions for seamless integration [ref 7, 8].

Geomstats serves as a practical tool for gaining hands-on experience with geometric learning fundamentals while also supporting future research in the field.

The Geomstats library is described in detail in the following article  Overview of Geomstats for Geometric Learning of this newsletter.

⚙️ Hands-on with Python

This article emphasizes the practical applications of Lie theory. As such, this section explores the commonly used Lie group: SO(3)

Environment

  • Libraries: Python 3.12, Geomstats 2.8.0
  • Source code: Github.com/geometriclearning/geometry/lie
  • To enhance the readability of the algorithm implementations, we have omitted non-essential code elements like error checking, comments, exceptions, validation of class and method arguments, scoping qualifiers, and import statements.

Special Orthogonal Group

The Special Orthogonal Group SO(3) is the Lie group that represents rotations in 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.


📌 The term ‘Special’ refers to the fact that SO(3) is actually a subgroup of Orthogonal matrices with a relaxed condition det(R) +/- 1



The Lie algebra of SO(3) is defined as group of skew-symmetric 3x3 matrices A:

Article content

Any skew-symmetric 3x3 matrix in Lie algebra can be defined as a linear combination of the following 3 fundamental generators of rotations about x, y and z axes:

Article content

📌 ConventionElements of Lie Algebra are written with the Fracktur font.


First let’s define a structure, LieElement, to define an element of the SO3 group with the following attributes:

  • group_element as a Numpy array representing a data point on the manifold
  • identity_element as the reference point for the tangent space and Lie algebra
  • descriptor as an optional description of the Lie element for visualization purpose.

Article content

Next we wrap the creation and manipulation of elements of the SO(3) into a class LieSO3Group with two constructors:

  • __init__: Default constructor that create a new element in the SO3 manifold, group_element, using the element in Lie Algebra (3x3 rotation matrix) algebra_element and a reference point , identity_element.
  • build: Alternative constructor for which the parameters are the vector as a 9 float values list and an array representing the identity matrix if defined.

Article content

We use the constructors of the LieSO3Group class to generate two points on the SO3 manifold, so3_element_1 and so3_element_2. These points are represented as vectors in 3-dimensional Euclidean space for visualization purposes.

The first SO3 element uses the identity as the reference for a fundamental generator of rotations around Y axis: Ly=  [[ 1. 0. 0.] [ 0. 0. -1.] [ 0. 0. 0.]]

The second SO3 element uses the same reference for a fundamental generator of rotations around Z axis: Lz= [[ 0. -1. 0.] [ 1. 0. 0.] [ 0. 0. 0.]]

Article content

Output for so3_group2

Algebra element:
[[ 0. -1.  0.]
 [ 1.  0.  0.]
 [ 0.  0.  0.]]
SO3 group element:
[[ 9.19666190e-01 -9.97270378e-01 -3.85335888e-17]
 [ 9.97270378e-01  9.19666190e-01 -3.85335888e-17]
 [ 0.00000000e+00  0.00000000e+00  1.00000000e+00]]        

Let’s visualize the SO3 group element corresponding to the two algebra elements Ly and Lz

Article content
Fig. 3 Visualization of SO3 group element for Ly and Lz unit at identity

It would be insightful to verify the computation of a Lie algebra element from an SO(3) group element using the logarithm map. The validation process involves the following steps:

  1. Generate an SO(3) group element by applying the exponential map to a rotation in the tangent space (Lie algebra).
  2. Retrieve the corresponding Lie algebra element from the computed SO(3) group element using the logarithm map.
  3. Compare the extracted Lie algebra element with the original rotation matrix to assess the accuracy of the computation.

This 3-step process is illustrated below.

Article content
Fig. 4 Visualization of validation of the computation of exponential and logarithm maps (Algebra → [Exp] →Group →[Log]→ Algebra)

First let’s implement the computation of an algebra element from an existing SO3 group element.

Article content

The method utilizes the implementation of the logarithm map, log in the Geomstats library. 

Article content

Output:

Algebra element:
[[ 0.  0.  1.]
 [ 0.  0.  0.]
 [-1.  0.  0.]]
SO3 group element:
[[ 9.19666190e-01  0.00000000e+00  9.97270378e-01]
 [ 0.00000000e+00  1.00000000e+00  0.00000000e+00]
 [-9.97270378e-01 -3.85335888e-17  9.19666190e-01]]
Computed algebra element:
[[ 3.25136469e-17  0.00000000e+00  1.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [-1.00000000e+00 -5.55111512e-17  1.62568234e-17]]        

As we can see, the computed algebra element is equal (+/- rounding error) to the original rotation Ly.



The evaluation of the Special Euclidean Group SE(3) is available in the full article Taming Symmetries: A Dive into Lie Groups



📘 References

  1. Introduction to Geometric Deep Learning - P. Nicolas - Substack
  2. Introduction to Differential Geometry - J. Robbin, D. Salamon - ETH Zurich
  3. Geometric Methods and Manifold Learning - M. Belkin - Ohio State University
  4. Algebra, Topology, Differential Calculus, and Optimization Theory For Computer Science and Machine Learning - J. Gallier and J. Quaintance - Department of Computer and Information Science - University of Pennsylvania
  5. Basics of Classical Lie groups: The Exponential Map, Lie Groups, and Lie Algebras University of Pennsylvania
  6. Introduction to Lie Groups and Lie Algebras - A. Kirillov, Jr - SUNY at Stony Brook
  7. Overview of Geomstats for Geometric Learning P. Nicolas - Substack
  8. Geomstats Library - GitHub



Patrick Nicolas has over 25 years of experience in software and data engineering, architecture design and end-to-end deployment and support with extensive knowledge in machine learning. He has been director of data engineering at Aideo Technologies since 2017 and he is the author of "Scala for Machine Learning", Packt Publishing ISBN 978-1-78712-238-3 and Hands-on Geometric Deep Learning Newsletter on Substack


#GeometricDeepLearning #LieGroup #LieAlgebra #SO3 #SE3

Danielle Marie Armstrong

DARINGHOOD Core & Culture Progress | Systembiografin, Dramaturgin, Astrologin, Quantenpraktikerin, Ontologin | LifeScript Consultant, Creative Coach | Mentoring, Training & Supervision.

2mo

Thank you, Patrick Nicolas

To view or add a comment, sign in

Explore topics