Skip to content

[MRG] Initialization for Low Rank Sinkhorn solver #588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f49f6b4
new file for lr sinkhorn
laudavid Oct 24, 2023
3c4b50f
lr sinkhorn, solve_sample, OTResultLazy
laudavid Oct 24, 2023
3034e57
add test functions + small modif lr_sin/solve_sample
laudavid Oct 25, 2023
085863a
add import to __init__
laudavid Oct 26, 2023
9becafc
modify low rank, remove solve_sample,OTResultLazy
laudavid Nov 3, 2023
855234d
pull from master
laudavid Nov 3, 2023
6ea251c
new file for lr sinkhorn
laudavid Oct 24, 2023
965e4d6
lr sinkhorn, solve_sample, OTResultLazy
laudavid Oct 24, 2023
fd5e26d
add test functions + small modif lr_sin/solve_sample
laudavid Oct 25, 2023
3df3b77
add import to __init__
laudavid Oct 26, 2023
fae28f7
Merge branch 'master' of https://github.com/hi-paris/POT into lowrank_v2
laudavid Nov 3, 2023
ab5475b
remove test solve_sample
laudavid Nov 3, 2023
f1c8cdd
add value, value_linear, lazy_plan
laudavid Nov 8, 2023
b1a2136
Merge branch 'PythonOT:master' into master
laudavid Nov 8, 2023
9e51a83
Merge branch 'master' of https://github.com/hi-paris/POT into lowrank_v2
laudavid Nov 8, 2023
df01cff
add comments to lr algorithm
laudavid Nov 8, 2023
a0b0a9d
Merge branch 'PythonOT:master' into master
laudavid Nov 9, 2023
7075c8b
Merge branch 'master' of https://github.com/hi-paris/POT into lowrank_v2
laudavid Nov 9, 2023
5f2af0e
Merge branch 'PythonOT:master' into lowrank_v2
laudavid Nov 9, 2023
5bc9de9
modify test functions + add comments to lowrank
laudavid Nov 9, 2023
c66951b
Merge branch 'lowrank_v2' of https://github.com/hi-paris/POT into low…
laudavid Nov 9, 2023
6040e6f
modify __init__ with lowrank
laudavid Nov 9, 2023
a7fdffd
debug lowrank + test
laudavid Nov 14, 2023
d90c186
debug test function low_rank
laudavid Nov 14, 2023
ea3a3e0
error test
laudavid Nov 14, 2023
f6a36bf
Merge branch 'PythonOT:master' into master
laudavid Nov 15, 2023
fe067fd
Merge branch 'master' of https://github.com/hi-paris/POT into lowrank_v2
laudavid Nov 15, 2023
5d3ed32
Merge branch 'PythonOT:master' into lowrank_v2
laudavid Nov 15, 2023
3e6b9aa
Merge branch 'lowrank_v2' of https://github.com/hi-paris/POT into low…
laudavid Nov 15, 2023
165e8f5
final debug of lowrank + add new test functions
laudavid Nov 15, 2023
de54bb9
branch up to date with master
laudavid Nov 17, 2023
bdcfaf6
Merge branch 'master' of https://github.com/hi-paris/POT into lowrank_v2
laudavid Nov 22, 2023
d0d9f46
Merge branch 'master' of https://github.com/hi-paris/POT into lowrank_v2
laudavid Nov 24, 2023
ec96836
Merge branch 'PythonOT:master' into lowrank_v2
laudavid Nov 24, 2023
8c6ac67
Debug tests + add lowrank to solve_sample
laudavid Nov 24, 2023
fafc5f6
Merge branch 'lowrank_v2' of https://github.com/hi-paris/POT into low…
laudavid Nov 24, 2023
bc7af6b
fix torch backend for lowrank
laudavid Nov 25, 2023
b40705c
fix jax backend and skip tf
laudavid Nov 28, 2023
55c8d2b
fix pep 8 tests
laudavid Nov 28, 2023
218c54a
merge master + doc for lowrank
laudavid Dec 5, 2023
e25c91d
add lowrank init + test functions
laudavid Dec 6, 2023
0436e95
Add init strategies in lowrank + example (PythonOT#588)
laudavid Dec 18, 2023
3649633
modified lowrank
laudavid Dec 20, 2023
78091a0
merge with upstream POT
laudavid Dec 20, 2023
5c4c4a8
changes from code review
laudavid Dec 20, 2023
477deed
fix error test pep8
laudavid Dec 20, 2023
077184f
fix linux-minimal-deps + code review
laudavid Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ The numerous contributors to this library are listed [here](CONTRIBUTORS.md).

POT has benefited from the financing or manpower from the following partners:

<img src="https://pythonot.github.io/master/_static/images/logo_anr.jpg" alt="ANR" style="height:60px;"/><img src="https://pythonot.github.io/master/_static/images/logo_cnrs.jpg" alt="CNRS" style="height:60px;"/><img src="https://pythonot.github.io/master/_static/images/logo_3ia.jpg" alt="3IA" style="height:60px;"/>
<img src="https://pythonot.github.io/master/_static/images/logo_anr.jpg" alt="ANR" style="height:60px;"/><img src="https://pythonot.github.io/master/_static/images/logo_cnrs.jpg" alt="CNRS" style="height:60px;"/><img src="https://pythonot.github.io/master/_static/images/logo_3ia.jpg" alt="3IA" style="height:60px;"/><img src="https://pythonot.github.io/master/_static/images/logo_hiparis.png" alt="Hi!PARIS" style="height:60px;"/>



## Contributions and code of conduct
Expand Down
Binary file added docs/source/_static/images/logo_hiparis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions examples/others/plot_lowrank_sinkhorn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*-
"""
========================================
Low rank Sinkhorn
========================================

This example illustrates the computation of Low Rank Sinkhorn [26].

[65] Scetbon, M., Cuturi, M., & Peyré, G. (2021).
"Low-rank Sinkhorn factorization". In International Conference on Machine Learning.
"""

# Author: Laurène David <laurene.david@ip-paris.fr>
#
# License: MIT License
#
# sphinx_gallery_thumbnail_number = 2

import numpy as np
import matplotlib.pylab as pl
import ot.plot
from ot.datasets import make_1D_gauss as gauss

##############################################################################
# Generate data
# -------------

#%% parameters

n = 100
m = 120

# Gaussian distribution
a = gauss(n, m=int(n / 3), s=25 / np.sqrt(2)) + 1.5 * gauss(n, m=int(5 * n / 6), s=15 / np.sqrt(2))
a = a / np.sum(a)

b = 2 * gauss(m, m=int(m / 5), s=30 / np.sqrt(2)) + gauss(m, m=int(m / 2), s=35 / np.sqrt(2))
b = b / np.sum(b)

# Source and target distribution
X = np.arange(n).reshape(-1, 1)
Y = np.arange(m).reshape(-1, 1)


##############################################################################
# Solve Low rank sinkhorn
# ------------

#%%
# Solve low rank sinkhorn
Q, R, g, log = ot.lowrank_sinkhorn(X, Y, a, b, rank=10, init="random", gamma_init="rescale", rescale_cost=True, warn=False, log=True)
P = log["lazy_plan"][:]

ot.plot.plot1D_mat(a, b, P, 'OT matrix Low rank')


##############################################################################
# Sinkhorn vs Low Rank Sinkhorn
# -----------------------
# Compare Sinkhorn and Low rank sinkhorn with different regularizations and ranks.

#%% Sinkhorn

# Compute cost matrix for sinkhorn OT
M = ot.dist(X, Y)
M = M / np.max(M)

# Solve sinkhorn with different regularizations using ot.solve
list_reg = [0.05, 0.005, 0.001]
list_P_Sin = []

for reg in list_reg:
P = ot.solve(M, a, b, reg=reg, max_iter=2000, tol=1e-8).plan
list_P_Sin.append(P)

#%% Low rank sinkhorn

# Solve low rank sinkhorn with different ranks using ot.solve_sample
list_rank = [3, 10, 50]
list_P_LR = []

for rank in list_rank:
P = ot.solve_sample(X, Y, a, b, method='lowrank', rank=rank).plan
P = P[:]
list_P_LR.append(P)


#%%

# Plot sinkhorn vs low rank sinkhorn
pl.figure(1, figsize=(10, 4))

pl.subplot(1, 3, 1)
pl.imshow(list_P_Sin[0], interpolation='nearest')
pl.axis('off')
pl.title('Sinkhorn (reg=0.05)')

pl.subplot(1, 3, 2)
pl.imshow(list_P_Sin[1], interpolation='nearest')
pl.axis('off')
pl.title('Sinkhorn (reg=0.005)')

pl.subplot(1, 3, 3)
pl.imshow(list_P_Sin[2], interpolation='nearest')
pl.axis('off')
pl.title('Sinkhorn (reg=0.001)')
pl.show()


#%%

pl.figure(2, figsize=(10, 4))

pl.subplot(1, 3, 1)
pl.imshow(list_P_LR[0], interpolation='nearest')
pl.axis('off')
pl.title('Low rank (rank=3)')

pl.subplot(1, 3, 2)
pl.imshow(list_P_LR[1], interpolation='nearest')
pl.axis('off')
pl.title('Low rank (rank=10)')

pl.subplot(1, 3, 3)
pl.imshow(list_P_LR[2], interpolation='nearest')
pl.axis('off')
pl.title('Low rank (rank=50)')

pl.tight_layout()
Loading