Foundations to Frontier
Tests
A. Mathematical Foundations › A12 Geometry for ML

Riemannian Geometry Basics

A manifold becomes a geometric space once you can measure lengths and angles on it. This topic introduces the Riemannian metric, curve length, geodesics (the straightest paths), the exponential and logarithm maps, parallel transport and curvature, including the Gauss–Bonnet theorem: on a sphere, triangle angles add up to more than 180°. It then turns geometry into algorithms: Riemannian gradient descent, the Karcher (Fréchet) mean, and slerp interpolation. In the research exercise you find an eigenvector by optimizing on the sphere, average widely spread star-tracker directions, and see why naive interpolation of directions or attitudes fails.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Measuring on curved spaces

An aeroplane flying from New York to Tokyo heads north over Alaska. On a flat map that looks like a detour, but on the globe it’s the shortest route: a great circle. On curved surfaces, “straight” means don’t turn left or right, and such paths are called geodesics.

Curved spaces break flat-geometry rules. Draw a triangle on a ball and its angles add up to more than 180°. You can detect the curvature without ever leaving the surface.

Measuring curvature from inside: a triangle on a sphere
A 85.8°B 85.8°C 85.8°
angle sum 257.3° (flat: 180°) · excess 1.3494 rad · area from side lengths 1.3494 · arrow rotated by 1.3494 rad after one loop (angles are measured modulo a full turn)
Green arrow: start at A. Grey: the same arrow carried along each side without turning (parallel transport). Orange: back at A. On a flat sheet it would return unchanged and the angles would sum to 180°. On the unit sphere (curvature K = 1), both the angle excess and the rotation equal the enclosed area: the Gauss–Bonnet theorem. Shrink the triangle and the surface looks flat. A gyroscope carried around a loop on Earth, or a robot arm's frame moved around a closed path, picks up the same kind of rotation.
Why engineers care

Spacecraft attitude, robot orientations, camera directions, probability distributions and the weights of some neural networks all live on curved spaces. Averaging, interpolating or optimizing them as if they were flat gives wrong answers: off-manifold points, uneven motion and wasted fuel. Riemannian geometry gives the correct versions of these operations.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The shortest path between two points on a sphere is part of a…
  2. 2. On a sphere, the angles of a triangle add up to…
  3. 3. A geodesic is a path that…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

The metric tensor

A Riemannian metric gives an inner product gx(u,v)=u⊤G(x)vg_x(u, v) = u^\top G(x)v on each tangent space, with G(x) symmetric positive definite and varying smoothly. The length of a curve is

L(γ)=∫abγ˙(t)⊤G(γ(t))γ˙(t) dt.L(\gamma) = \int_a^b\sqrt{\dot\gamma(t)^\top G(\gamma(t))\dot\gamma(t)}\,dt.

Distance is the infimum of lengths over all curves joining the two points.

  • Polar coordinates in the plane: ds2=dr2+r2dθ2ds^2 = dr^2 + r^2d\theta^2, so G=diag⁡(1,r2)G = \operatorname{diag}(1, r^2).
  • Unit sphere in colatitude θ and longitude φ: ds2=dθ2+sin⁡2θ dφ2ds^2 = d\theta^2 + \sin^2\theta\,d\varphi^2. A circle of colatitude θ has length 2πsin⁡θ2\pi\sin\theta.
  • Embedded surfaces inherit their metric from the ambient dot product.

Geodesics

Geodesics are locally length-minimizing curves with constant speed. On the unit sphere they are great circles: γ(t)=cos⁡(t∥v∥)p+sin⁡(t∥v∥) v/∥v∥\gamma(t) = \cos(t\|v\|)p + \sin(t\|v\|)\,v/\|v\|.

📝 Quick check (Level 1)
0/3 answered
  1. 1. In polar coordinates, the metric is…
  2. 2. Length of the latitude circle at colatitude 90° (the equator) on the unit sphere:
  3. 3. The metric tensor G(x) must be…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Exponential and logarithm maps

  • exp⁡p(v)\exp_p(v) follows the geodesic from p with initial velocity v for unit time.
  • log⁡p(q)\log_p(q) is its inverse: the tangent vector at p pointing to q, whose length is the distance d(p,q)d(p, q).

On the unit sphere:

exp⁡p(v)=cos⁡∥v∥ p+sin⁡∥v∥v∥v∥,log⁡p(q)=arccos⁡(p⋅q)q−(p⋅q)p∥q−(p⋅q)p∥.\exp_p(v) = \cos\|v\|\,p + \sin\|v\|\tfrac v{\|v\|},\qquad\log_p(q) = \arccos(p\cdot q)\frac{q - (p\cdot q)p}{\|q - (p\cdot q)p\|}.

These maps turn flat formulas into manifold algorithms:

  • Geodesic interpolation: γ(t)=exp⁡p(tlog⁡pq)\gamma(t) = \exp_p(t\log_pq). This is slerp.
  • Karcher (Fréchet) mean: arg⁡min⁡m∑id(m,pi)2\arg\min_m\sum_id(m, p_i)^2. Iterate m←exp⁡m(1N∑log⁡mpi)m\leftarrow\exp_m\big(\tfrac1N\sum\log_mp_i\big).
  • Riemannian gradient descent: the Riemannian gradient is the Euclidean gradient projected onto the tangent space (for an embedded submanifold). Step with x←exp⁡x(−ηgrad⁡f)x\leftarrow\exp_x(-\eta\operatorname{grad}f), or with a cheaper retraction (Absil, Mahony and Sepulchre, 2008).

Curvature

The Gaussian curvature K of a surface measures how geodesics spread: the sphere has K = 1/R², the plane 0, and the hyperbolic plane −1. Gauss–Bonnet for a geodesic triangle T: α+β+γ=π+∫TK dA\alpha + \beta + \gamma = \pi + \int_TK\,dA. Equivalently, carrying a vector around T by parallel transport rotates it by ∫TK dA\int_TK\,dA (holonomy).

🐍 Exercise 1: geometry on the sphere
Implement exp and log maps, geodesic distance, triangle angles from log maps, and curve length under a metric tensor. Verify Gauss–Bonnet on the octant triangle and the lengths of circles under the polar and spherical metrics.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The length of log_p(q) equals…
  2. 2. On an embedded manifold, the Riemannian gradient is…
  3. 3. A triangle in the hyperbolic plane (K = −1) has angle sum…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Why exp and log are inverse on the sphere

Let v=log⁡pqv = \log_pq with θ=arccos⁡(p⋅q)\theta = \arccos(p\cdot q) and unit u=(q−(p⋅q)p)/∥⋅∥u = (q - (p\cdot q)p)/\|\cdot\|. Then q=cos⁡θ p+sin⁡θ uq = \cos\theta\,p + \sin\theta\,u, because ∥q−cos⁡θ p∥=sin⁡θ\|q - \cos\theta\,p\| = \sin\theta. So exp⁡p(θu)=q\exp_p(\theta u) = q. ∎

The Riemannian gradient is the projection

For f restricted to a submanifold M, grad⁡f(x)\operatorname{grad}f(x) is the unique tangent vector with ⟨grad⁡f,v⟩=Df(x)[v]\langle\operatorname{grad}f, v\rangle = Df(x)[v] for all tangent v. Since Df(x)[v]=∇f⋅v=(Px∇f)⋅vDf(x)[v] = \nabla f\cdot v = (P_x\nabla f)\cdot v for tangent v, we get grad⁡f=Px∇f\operatorname{grad}f = P_x\nabla f. ∎ On the sphere, Px=I−xx⊤P_x = I - xx^\top. For the Rayleigh quotient f=x⊤Axf = x^\top Ax, the critical points Px(2Ax)=0P_x(2Ax) = 0 are exactly the eigenvectors.

Holonomy of a latitude circle

Carry a vector around the circle of colatitude θ. It returns rotated by the enclosed cap area, 2π(1−cos⁡θ)2\pi(1 - \cos\theta). Up to a whole turn, this equals 2π times the sine of the latitude: the angle a Foucault pendulum’s swing plane turns in one sidereal day.

Exercise 3.1: holonomy at colatitude 60°

2π(1−cos⁡60°)=π2\pi(1 - \cos60°) = \pi: the vector comes back pointing the opposite way.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Critical points of xᵀAx on the unit sphere are…
  2. 2. Holonomy around a geodesic triangle on the unit sphere equals…
  3. 3. The projection onto the tangent space of the sphere at x is…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Optimizing, averaging and interpolating on the sphere

  • Eigenvector by optimization: Riemannian gradient ascent of xᵀAx on the unit sphere in R⁵⁰ reaches the top eigenvalue (8.9868) in 760 steps. Every iterate stays on the sphere to 1e−12; no penalty or renormalization is needed.
  • Averaging directions: 40 widely spread unit direction measurements, as from a star tracker. The Karcher mean and the normalized Euclidean mean differ by 6.8°. The Karcher mean has the lower sum of squared geodesic distances (48.15 vs 48.70 rad²), as it must, because it is the minimizer.
  • Interpolating: over a 160° turn, slerp moves at exactly constant angular speed. Normalized linear interpolation varies its speed by a factor of 32.8. That is why attitude controllers and animation systems slerp quaternions (a12-3).
🐍 Exercise 2 (research): Riemannian optimization, means and interpolation
Implement Riemannian gradient ascent for the Rayleigh quotient on the sphere, the Karcher mean, slerp and nlerp. Check the eigenvector, compare the Karcher and Euclidean means on spread data, and measure the speed variation of each interpolation.

Riemannian geometry in AI, robotics and aerospace

  • Optimization on manifolds: orthogonality constraints (Stiefel manifolds), low-rank matrices, PCA and eigenproblems, and SPD covariance matrices (Absil et al., 2008; Boumal, 2023). Libraries: Manopt and Geoopt.
  • Geometric deep learning: hyperbolic embeddings for hierarchies (Nickel and Kiela, 2017); diffusion models on manifolds.
  • Robotics and aerospace: attitude estimation and control on SO(3); geodesic motion planning; averaging rotations and directions.
  • Statistics: Fréchet means, principal geodesic analysis, and the information-geometric metric on distributions (a12-5).

References

  1. J. Lee (2018). Introduction to Riemannian Manifolds, 2nd ed. Springer.
  2. M. do Carmo (1992). Riemannian Geometry. Birkhäuser.
  3. P.-A. Absil, R. Mahony, R. Sepulchre (2008). Optimization Algorithms on Matrix Manifolds. Princeton.
  4. N. Boumal (2023). An Introduction to Optimization on Smooth Manifolds. Cambridge.
  5. H. Karcher (1977). “Riemannian center of mass and mollifier smoothing.” Comm. Pure Appl. Math., 30.
  6. K. Shoemake (1985). “Animating rotation with quaternion curves.” SIGGRAPH.
  7. M. Nickel, D. Kiela (2017). “Poincaré embeddings for learning hierarchical representations.” NeurIPS.