Note
Go to the end to download the full example code.
Row and column alignments with CO-Optimal Transport
This example is designed to show how to use the CO-Optimal Transport [47]_ in POT. CO-Optimal Transport allows to calculate the distance between two arbitrary-size matrices, and to align their rows and columns. In this example, we consider two random matrices \(X_1\) and \(X_2\) defined by \((X_1)_{i,j} = \cos(\frac{i}{n_1} \pi) + \cos(\frac{j}{d_1} \pi) + \sigma \mathcal N(0,1)\) and \((X_2)_{i,j} = \cos(\frac{i}{n_2} \pi) + \cos(\frac{j}{d_2} \pi) + \sigma \mathcal N(0,1)\).
# Author: Remi Flamary <remi.flamary@unice.fr>
# Quang Huy Tran <quang-huy.tran@univ-ubs.fr>
# License: MIT License
# sphinx_gallery_thumbnail_number = 2
from matplotlib.patches import ConnectionPatch
import matplotlib.pylab as pl
import numpy as np
from ot.coot import co_optimal_transport as coot
from ot.coot import co_optimal_transport2 as coot2
Generating two random matrices
n1 = 20
n2 = 10
d1 = 16
d2 = 8
sigma = 0.2
X1 = (
np.cos(np.arange(n1) * np.pi / n1)[:, None]
+ np.cos(np.arange(d1) * np.pi / d1)[None, :]
+ sigma * np.random.randn(n1, d1)
)
X2 = (
np.cos(np.arange(n2) * np.pi / n2)[:, None]
+ np.cos(np.arange(d2) * np.pi / d2)[None, :]
+ sigma * np.random.randn(n2, d2)
)
Visualizing the matrices