-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bwgd_barycenter
- Loading branch information
Showing
9 changed files
with
327 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# CFF file for POT contributors | ||
|
||
cff-version: 1.2.0 | ||
title: POT Python Optimal Transport | ||
message: >- | ||
If you use this software, please cite it using the | ||
metadata from this file. | ||
type: software | ||
authors: | ||
- given-names: Rémi | ||
family-names: Flamary | ||
affiliation: École Polytechnique | ||
orcid: 'https://orcid.org/0000-0002-4212-6627' | ||
- given-names: Cédric | ||
family-names: Vincent-Cuaz | ||
affiliation: EPFL | ||
- given-names: Nicolas | ||
family-names: Courty | ||
affiliation: Université Bretagne Sud | ||
- given-names: Alexandre | ||
family-names: Gramfort | ||
affiliation: INRIA | ||
- given-names: Oleksii | ||
family-names: Kachaiev | ||
affiliation: Università degli Studi di Genova | ||
- given-names: Huy | ||
family-names: Quang Tran | ||
affiliation: Université Bretagne Sud | ||
- given-names: Laurène | ||
family-names: David | ||
affiliation: Institut Polytechnique de Paris | ||
- given-names: Clément | ||
family-names: Bonet | ||
affiliation: ENSAE - CREST | ||
- given-names: Nathan | ||
family-names: Cassereau | ||
affiliation: IDRIS-CNRS | ||
- given-names: Théo | ||
family-names: Gnassounou | ||
affiliation: INRIA | ||
- given-names: Eloi | ||
family-names: Tanguy | ||
affiliation: Université Paris-Cité | ||
- given-names: Julie | ||
family-names: Delon | ||
affiliation: Université Paris-Cité | ||
- given-names: Antoine | ||
family-names: Collas | ||
affiliation: INRIA | ||
- given-names: Sonia | ||
family-names: Mazelet | ||
affiliation: Ecole Polytechnique | ||
- given-names: Laetitia | ||
family-names: Chapel | ||
affiliation: Institut Agro Rennes-Angers, IRISA | ||
- given-names: Tanguy | ||
family-names: Kerdoncuff | ||
affiliation: Université de Lyon | ||
- given-names: Xizheng | ||
family-names: Yu | ||
affiliation: Brown University | ||
- given-names: Matthew | ||
family-names: Feickert | ||
affiliation: University of Wisconsin-Madison | ||
- given-names: Paul | ||
family-names: Krzakala | ||
affiliation: Telecom Paris | ||
- given-names: Tianlin | ||
family-names: Liu | ||
affiliation: University of Basel | ||
- given-names: Eduardo | ||
family-names: Fernandes Montesuma | ||
affiliation: Université Paris-Saclay & CEA-List | ||
orcid: 'https://orcid.org/0000-0003-3850-4602' | ||
identifiers: | ||
- type: url | ||
value: 'https://github.com/PythonOT/POT' | ||
description: Code | ||
repository-code: 'https://github.com/PythonOT/POT' | ||
url: 'https://pythonot.github.io/' | ||
keywords: | ||
- optimal transport | ||
- python | ||
- sinkhorn | ||
- wasserstein | ||
- gromov-wasserstein | ||
license: MIT | ||
version: 0.9.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
================================================ | ||
Different gradient computations for regularized optimal transport | ||
================================================ | ||
This example illustrates the differences in terms of computation time between the gradient options for the Sinkhorn solver. | ||
""" | ||
|
||
# Author: Sonia Mazelet <sonia.mazelet@polytechnique.edu> | ||
# | ||
# License: MIT License | ||
|
||
# sphinx_gallery_thumbnail_number = 1 | ||
|
||
import matplotlib.pylab as pl | ||
import ot | ||
from ot.backend import torch | ||
|
||
|
||
############################################################################## | ||
# Time comparison of the Sinkhorn solver for different gradient options | ||
# ------------- | ||
|
||
|
||
# %% parameters | ||
|
||
n_trials = 10 | ||
times_autodiff = torch.zeros(n_trials) | ||
times_envelope = torch.zeros(n_trials) | ||
times_last_step = torch.zeros(n_trials) | ||
|
||
n_samples_s = 300 | ||
n_samples_t = 300 | ||
n_features = 5 | ||
reg = 0.03 | ||
|
||
# Time required for the Sinkhorn solver and gradient computations, for different gradient options over multiple Gaussian distributions | ||
for i in range(n_trials): | ||
x = torch.rand((n_samples_s, n_features)) | ||
y = torch.rand((n_samples_t, n_features)) | ||
a = ot.utils.unif(n_samples_s) | ||
b = ot.utils.unif(n_samples_t) | ||
M = ot.dist(x, y) | ||
|
||
a = torch.tensor(a, requires_grad=True) | ||
b = torch.tensor(b, requires_grad=True) | ||
M = M.clone().detach().requires_grad_(True) | ||
|
||
# autodiff provides the gradient for all the outputs (plan, value, value_linear) | ||
ot.tic() | ||
res_autodiff = ot.solve(M, a, b, reg=reg, grad="autodiff") | ||
res_autodiff.value.backward() | ||
times_autodiff[i] = ot.toq() | ||
|
||
a = a.clone().detach().requires_grad_(True) | ||
b = b.clone().detach().requires_grad_(True) | ||
M = M.clone().detach().requires_grad_(True) | ||
|
||
# envelope provides the gradient for value | ||
ot.tic() | ||
res_envelope = ot.solve(M, a, b, reg=reg, grad="envelope") | ||
res_envelope.value.backward() | ||
times_envelope[i] = ot.toq() | ||
|
||
a = a.clone().detach().requires_grad_(True) | ||
b = b.clone().detach().requires_grad_(True) | ||
M = M.clone().detach().requires_grad_(True) | ||
|
||
# last_step provides the gradient for all the outputs, but only for the last iteration of the Sinkhorn algorithm | ||
ot.tic() | ||
res_last_step = ot.solve(M, a, b, reg=reg, grad="last_step") | ||
res_last_step.value.backward() | ||
times_last_step[i] = ot.toq() | ||
|
||
pl.figure(1, figsize=(5, 3)) | ||
pl.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) | ||
pl.boxplot( | ||
([times_autodiff, times_envelope, times_last_step]), | ||
tick_labels=["autodiff", "envelope", "last_step"], | ||
showfliers=False, | ||
) | ||
pl.ylabel("Time (s)") | ||
pl.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.