26.02.2019 · We can easily see that the optimal transport corresponds to assigning each point in the support of p ( x) p ( x) to the point right above in the support of …
wassdistance/layers.py /Jump toCode definitionsSinkhornDistance Class __init__ Function forward Function M Function _cost_matrix Function ave Function. 93 lines (79 sloc) 3.4 KB. class SinkhornDistance ( nn. Module ): outputs an approximation of the regularized OT cost for point clouds. elements in the output, 'sum': the output will be summed.
By adding an entropic regularization, Sinkhorn distance (Cuturi, 2013) has been widely computed since it is friendly to high dimensional cases (Altschuler ...
Feb 26, 2019 · We can easily see that the optimal transport corresponds to assigning each point in the support of p ( x) p ( x) to the point right above in the support of q ( x) q ( x). For all points, the distance is 1, and since the distributions are uniform, the mass moved per point is 1/5. Therefore, the Wasserstein distance is 5 × 1 5 = 1 5 × 1 5 = 1.
11.03.2019 · %matplotlib inline import matplotlib.pyplot as plt import numpy as np np.random.seed(42) n_points = 5 a = np.array([[i, 0] for i in range(n_points)]) b = np.array([[i, 1 ... import torch from layers import SinkhornDistance x = torch.tensor(a, dtype=torch.float) y = torch.tensor(b, dtype=torch.float) ...
Dec 04, 2020 · To do so we need to construct, for each line i, a (8x4) repeated version of tensor a [i]. This will do: a_i = torch.stack (8* [a [i]], dim=0) Then we calculate the distance between a [i] and each batch in b: dist (a_i.unsqueeze (1), b.unsqueeze (1)) Having a total of batch lines we can construct our final tensor stack. Here's the complete code:
wassdistance/layers.py /Jump toCode definitionsSinkhornDistance Class __init__ Function forward Function M Function _cost_matrix Function ave Function. 93 lines (79 sloc) 3.4 KB. class SinkhornDistance ( nn. Module ): outputs an …
jf(x) f(y)j d(x;y), dbeing the underlying metric on the space. import torch from layers import SinkhornDistance x = torch . The Wasserstein package computes Wasserstein distances and related quantities efficiently. The Wasserstein distance has also been used to measure similarity between word embeddings of documents or between signals or spectra. 1-Wasserstein …