Sinkhorn Distances: Lightspeed Computation of Optimal Transport
Authors: Marco Cuturi
Published: 2013
Venue: NeurIPS
Link: PDF
Summary
This paper introduces Sinkhorn distances, an efficient approximation to optimal transport (Wasserstein) distances using entropic regularization. The key insight is that adding entropy to the transport problem makes it solvable via simple matrix scaling iterations, enabling fast computation of distances between probability distributions.
Key Contributions
1. Entropic Regularization
Add entropy term to optimal transport:
where is the entropy.
2. Sinkhorn's Algorithm
The optimal has the form where .
Iterate until convergence:
3. Computational Speedup
Sinkhorn complexity: vs. for exact OT.
For large , this is orders of magnitude faster.
Mathematical Framework
Optimal Transport Problem
Given:
- Source distribution (probability simplex)
- Target distribution
- Cost matrix
Find optimal transport plan:
where .
Entropic OT
The regularized problem:
Optimal Solution Structure
Theorem: The optimal satisfies:
where and satisfy:
Sinkhorn Algorithm
Basic Iteration
import numpy as np
def sinkhorn_distance(M, r, c, lambda_reg=1.0, max_iter=100, tol=1e-9):
"""
Compute Sinkhorn distance using matrix scaling.
Parameters:
-----------
M : cost matrix (n, m)
r : source distribution (n,)
c : target distribution (m,)
lambda_reg : regularization strength
max_iter : maximum iterations
tol : convergence tolerance
Returns:
--------
distance : Sinkhorn distance
P : optimal transport plan
"""
n, m = M.shape
# Gibbs kernel
K = np.exp(-lambda_reg * M)
# Initialize scaling vectors
u = np.ones(n)
v = np.ones(m)
for iteration in range(max_iter):
u_prev = u.copy()
# Sinkhorn iterations
u = r / (K @ v + 1e-10)
v = c / (K.T @ u + 1e-10)
# Check convergence
if np.max(np.abs(u - u_prev)) < tol:
break
# Optimal transport plan
P = np.diag(u) @ K @ np.diag(v)
# Sinkhorn distance
distance = np.sum(P * M)
return distance, P
def sinkhorn_log_stabilized(M, r, c, lambda_reg=1.0, max_iter=100, tol=1e-9):
"""
Log-stabilized Sinkhorn for numerical stability.
"""
n, m = M.shape
# Work in log space
log_r = np.log(r + 1e-10)
log_c = np.log(c + 1e-10)
f = np.zeros(n) # log(u)
g = np.zeros(m) # log(v)
for iteration in range(max_iter):
f_prev = f.copy()
# Log-space iterations
f = log_r - logsumexp(-lambda_reg * M + g[None, :], axis=1)
g = log_c - logsumexp(-lambda_reg * M.T + f[None, :], axis=1)
if np.max(np.abs(f - f_prev)) < tol:
break
# Compute distance
log_P = f[:, None] + g[None, :] - lambda_reg * M
P = np.exp(log_P)
distance = np.sum(P * M)
return distance, P
def logsumexp(x, axis=None):
"""Numerically stable logsumexp."""
x_max = np.max(x, axis=axis, keepdims=True)
result = np.log(np.sum(np.exp(x - x_max), axis=axis))
return result + np.squeeze(x_max, axis=axis) if axis is not None else result + x_max.item()
GPU-Accelerated Version
import torch
def sinkhorn_gpu(M, r, c, lambda_reg=1.0, max_iter=100):
"""
GPU-accelerated Sinkhorn using PyTorch.
"""
K = torch.exp(-lambda_reg * M)
u = torch.ones_like(r)
for _ in range(max_iter):
u = r / (K @ (c / (K.T @ u)))
v = c / (K.T @ u)
P = torch.diag(u) @ K @ torch.diag(v)
return torch.sum(P * M), P
Sinkhorn Divergence
To remove entropic bias, use Sinkhorn divergence:
This satisfies (unlike raw Sinkhorn distance).
Sinkhorn Kernel
Define a kernel on probability distributions:
This is positive definite for appropriate .
Theoretical Properties
Approximation Quality
The approximation improves as .
Convergence Rate
Sinkhorn converges linearly:
where .
Differentiability
is differentiable w.r.t. , , and :
where are the optimal dual variables.
Applications
1. Domain Adaptation
Align source and target distributions:
2. Generative Models
Wasserstein GAN with Sinkhorn:
3. Document Comparison
Word Mover's Distance:
with word embedding distances as cost.
4. Color Transfer
Transport color histogram from source to target image.
5. Shape Matching
Compare point clouds or probability measures on shapes.
Complexity Comparison
| Method | Time | Space | Differentiable |
|---|---|---|---|
| LP Solver | ✗ | ||
| Network Simplex | ✗ | ||
| Sinkhorn | ✓ | ||
| Sliced OT | ✓ |
Extensions
1. Unbalanced OT
Allow mass creation/destruction:
2. Gromov-Wasserstein
For comparing metric measure spaces:
3. Multi-Marginal OT
Transport between distributions simultaneously.
Citation
@inproceedings{cuturi2013sinkhorn,
title={Sinkhorn distances: Lightspeed computation of optimal transport},
author={Cuturi, Marco},
booktitle={Advances in Neural Information Processing Systems},
volume={26},
year={2013}
}
Further Reading
- Peyré, G. & Cuturi, M. (2019). Computational optimal transport
- Genevay, A., et al. (2018). Learning generative models with Sinkhorn divergences
- Feydy, J., et al. (2019). Interpolating between optimal transport and MMD