liveBook · Manning

Riemannian distance

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

Riemannian distance is the shortest distance between points on a curved space measured along that space rather than through its surrounding space.

Riemannian distance measures the shortest route between points while staying on a curved space. On a sphere, it is the great-circle or geodesic path, not a straight line through the sphere’s interior. section 11.6

For points represented as unit vectors, their distance equals the arccosine of their dot product. This turns spherical geometry into a compact calculation usable inside trainable optimization models. section 11.6

Celestial points on a sphere

Right ascension and declination locate objects on the celestial sphere. Converting these coordinates to three-dimensional unit vectors allows sphere_dist to measure angular separation along the sphere. section 11.6

Listing 11.3 Solving a function optimization problem using supervised learning
import torch
from torch import nn
import numpy as np
from tqdm import tqdm
import matplotlib.pyplot as plt
  
def celestial_to_euclidean(ra, dec):             #1
    x = np.cos(dec)*np.cos(ra)
    y = np.cos(dec)*np.sin(ra)
    z = np.sin(dec)
    return x, y, z
  
def euclidean_to_celestial(x, y, z):             #2
    sindec = z
    cosdec = (x*x + y*y).sqrt()
    sinra = y / cosdec
    cosra = x / cosdec
    ra = torch.atan2(sinra, cosra)
    dec = torch.atan2(sindec, cosdec)
    return ra, dec
  
def sphere_dist(x,y):                            #3
    if x.ndim == 1:
        x = x.unsqueeze(0)
    if y.ndim == 1:
        y = y.unsqueeze(0)
    assert x.ndim == y.ndim == 2
    inner = (x*y).sum(-1)
    return torch.arccos(inner)

Inspect coordinate conversions and the PyTorch implementation of spherical distance. section 11.6

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Defines geodesic distance and implements dot-product arccosine evaluation, restricting treatment to spherical geometry.
Examples
Uses celestial coordinates, three-dimensional unit vectors, and a PyTorch sphere_dist function as concrete examples.
What it assumes
Assumes familiarity with vectors, dot products, arccosine, and representing spherical points in three-dimensional Euclidean space.
What you can do after
Apply it via a dot product and arccosine to measure angular separation between spherical points.
How it connects
Connects Riemannian distance with great-circle distance, geodesic paths, celestial coordinates, spheres, and supervised learning.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.