Quickstart Guide

Quickstart guide to the POT toolbox.

For better readability, only the use of POT is provided and the plotting code with matplotlib is hidden (but is available in the source file of the example).

Note

We use here the unified API of POT which is more flexible and allows to solve a wider range of problems with just a few functions. The classical API is still available (the unified API one is a convenient wrapper around the classical one) and we provide pointers to the classical API when needed.

# Author: Remi Flamary
#
# License: MIT License
# sphinx_gallery_thumbnail_number = 18

# Import necessary libraries

import numpy as np
import pylab as pl

import ot

2D data example

We first generate two sets of samples in 2D that 25 and 50 samples respectively located on circles. The weights of the samples are uniform.

# Problem size
n1 = 25
n2 = 50

# Generate random data
np.random.seed(0)
a = ot.utils.unif(n1)  # weights of points in the source domain
b = ot.utils.unif(n2)  # weights of points in the target domain

x1 = np.random.randn(n1, 2)
x1 /= np.sqrt(np.sum(x1**2, 1, keepdims=True)) / 2

x2 = np.random.randn(n2, 2)
x2 /= np.sqrt(np.sum(x2**2, 1, keepdims=True)) / 4

# Compute the cost matrix
C = ot.dist(x1, x2)  # Squared Euclidean cost matrix by default