Skip to content

Commit 0ec72bf

Browse files
Circle CICircle CI
authored andcommitted
CircleCI update of dev docs (3290).
1 parent 066dd42 commit 0ec72bf

File tree

442 files changed

+109905
-105714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

442 files changed

+109905
-105714
lines changed

master/_downloads/006964755fe89c4eeb7c8b8016e96890/plot_otda_semi_supervised.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@
110110
pl.figure(2, figsize=(8, 4))
111111

112112
pl.subplot(1, 2, 1)
113-
pl.imshow(ot_sinkhorn_un.coupling_, interpolation="nearest")
113+
pl.imshow(ot_sinkhorn_un.coupling_, interpolation="nearest", cmap="gray_r")
114114
pl.xticks([])
115115
pl.yticks([])
116116
pl.title("Optimal coupling\nUnsupervised DA")
117117

118118
pl.subplot(1, 2, 2)
119-
pl.imshow(ot_sinkhorn_semi.coupling_, interpolation="nearest")
119+
pl.imshow(ot_sinkhorn_semi.coupling_, interpolation="nearest", cmap="gray_r")
120120
pl.xticks([])
121121
pl.yticks([])
122122
pl.title("Optimal coupling\nSemi-supervised DA")
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Low rank Gromov-Wasterstein between samples\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>Example added in release: 0.9.4.</p></div>\n\nComparison between entropic Gromov-Wasserstein and Low Rank Gromov Wasserstein [67]\non two curves in 2D and 3D, both sampled with 200 points.\n\nThe squared Euclidean distance is considered as the ground cost for both samples.\n\n[67] Scetbon, M., Peyr\u00e9, G. & Cuturi, M. (2022).\n\"Linear-Time GromovWasserstein Distances using Low Rank Couplings and Costs\".\nIn International Conference on Machine Learning (ICML), 2022.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"# Author: Laur\u00e8ne David <[email protected]>\n#\n# License: MIT License\n#\n# sphinx_gallery_thumbnail_number = 3"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"import numpy as np\nimport matplotlib.pylab as pl\nimport ot.plot\nimport time"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Generate data\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"n_samples = 200\n\n# Generate 2D and 3D curves\ntheta = np.linspace(-4 * np.pi, 4 * np.pi, n_samples)\nz = np.linspace(1, 2, n_samples)\nr = z**2 + 1\nx = r * np.sin(theta)\ny = r * np.cos(theta)\n\n# Source and target distribution\nX = np.concatenate([x.reshape(-1, 1), z.reshape(-1, 1)], axis=1)\nY = np.concatenate([x.reshape(-1, 1), y.reshape(-1, 1), z.reshape(-1, 1)], axis=1)"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"## Plot data\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"Plot the source and target samples\n\n"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {
68+
"collapsed": false
69+
},
70+
"outputs": [],
71+
"source": [
72+
"fig = pl.figure(1, figsize=(10, 4))\n\nax = fig.add_subplot(121)\nax.plot(X[:, 0], X[:, 1], color=\"blue\", linewidth=6)\nax.tick_params(\n left=False, right=False, labelleft=False, labelbottom=False, bottom=False\n)\nax.set_title(\"2D curve (source)\")\n\nax2 = fig.add_subplot(122, projection=\"3d\")\nax2.plot(Y[:, 0], Y[:, 1], Y[:, 2], c=\"red\", linewidth=6)\nax2.tick_params(\n left=False, right=False, labelleft=False, labelbottom=False, bottom=False\n)\nax2.view_init(15, -50)\nax2.set_title(\"3D curve (target)\")\n\npl.tight_layout()\npl.show()"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"## Entropic Gromov-Wasserstein\n\n"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {
86+
"collapsed": false
87+
},
88+
"outputs": [],
89+
"source": [
90+
"# Compute cost matrices\nC1 = ot.dist(X, X, metric=\"sqeuclidean\")\nC2 = ot.dist(Y, Y, metric=\"sqeuclidean\")\n\n# Scale cost matrices\nr1 = C1.max()\nr2 = C2.max()\n\nC1 = C1 / r1\nC2 = C2 / r2\n\n\n# Solve entropic gw\nreg = 5 * 1e-3\n\nstart = time.time()\ngw, log = ot.gromov.entropic_gromov_wasserstein(\n C1, C2, tol=1e-3, epsilon=reg, log=True, verbose=False\n)\n\nend = time.time()\ntime_entropic = end - start\n\nentropic_gw_loss = np.round(log[\"gw_dist\"], 3)\n\n# Plot entropic gw\npl.figure(2)\npl.imshow(gw, interpolation=\"nearest\", aspect=\"auto\", cmap=\"gray_r\")\npl.title(\"Entropic Gromov-Wasserstein (loss={})\".format(entropic_gw_loss))\npl.show()"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"metadata": {},
96+
"source": [
97+
"## Low rank squared euclidean cost matrices\n%%\n\n"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {
104+
"collapsed": false
105+
},
106+
"outputs": [],
107+
"source": [
108+
"# Compute the low rank sqeuclidean cost decompositions\nA1, A2 = ot.lowrank.compute_lr_sqeuclidean_matrix(X, X, rescale_cost=False)\nB1, B2 = ot.lowrank.compute_lr_sqeuclidean_matrix(Y, Y, rescale_cost=False)\n\n# Scale the low rank cost matrices\nA1, A2 = A1 / np.sqrt(r1), A2 / np.sqrt(r1)\nB1, B2 = B1 / np.sqrt(r2), B2 / np.sqrt(r2)"
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"## Low rank Gromov-Wasserstein\n%%\n\n"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"metadata": {
122+
"collapsed": false
123+
},
124+
"outputs": [],
125+
"source": [
126+
"# Solve low rank gromov-wasserstein with different ranks\nlist_rank = [10, 50]\nlist_P_GW = []\nlist_loss_GW = []\nlist_time_GW = []\n\nfor rank in list_rank:\n start = time.time()\n\n Q, R, g, log = ot.lowrank_gromov_wasserstein_samples(\n X,\n Y,\n reg=0,\n rank=rank,\n rescale_cost=False,\n cost_factorized_Xs=(A1, A2),\n cost_factorized_Xt=(B1, B2),\n seed_init=49,\n numItermax=1000,\n log=True,\n stopThr=1e-6,\n )\n end = time.time()\n\n P = log[\"lazy_plan\"][:]\n loss = log[\"value\"]\n\n list_P_GW.append(P)\n list_loss_GW.append(np.round(loss, 3))\n list_time_GW.append(end - start)"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"metadata": {},
132+
"source": [
133+
"Plot low rank GW with different ranks\n\n"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {
140+
"collapsed": false
141+
},
142+
"outputs": [],
143+
"source": [
144+
"pl.figure(3, figsize=(10, 4))\n\npl.subplot(1, 2, 1)\npl.imshow(list_P_GW[0], interpolation=\"nearest\", aspect=\"auto\", cmap=\"gray_r\")\npl.title(\"Low rank GW (rank=10, loss={})\".format(list_loss_GW[0]))\n\npl.subplot(1, 2, 2)\npl.imshow(list_P_GW[1], interpolation=\"nearest\", aspect=\"auto\", cmap=\"gray_r\")\npl.title(\"Low rank GW (rank=50, loss={})\".format(list_loss_GW[1]))\n\npl.tight_layout()\npl.show()"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"metadata": {},
150+
"source": [
151+
"Compare computation time between entropic GW and low rank GW\n\n"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {
158+
"collapsed": false
159+
},
160+
"outputs": [],
161+
"source": [
162+
"print(\"Entropic GW: {:.2f}s\".format(time_entropic))\nprint(\"Low rank GW (rank=10): {:.2f}s\".format(list_time_GW[0]))\nprint(\"Low rank GW (rank=50): {:.2f}s\".format(list_time_GW[1]))"
163+
]
164+
}
165+
],
166+
"metadata": {
167+
"kernelspec": {
168+
"display_name": "Python 3",
169+
"language": "python",
170+
"name": "python3"
171+
},
172+
"language_info": {
173+
"codemirror_mode": {
174+
"name": "ipython",
175+
"version": 3
176+
},
177+
"file_extension": ".py",
178+
"mimetype": "text/x-python",
179+
"name": "python",
180+
"nbconvert_exporter": "python",
181+
"pygments_lexer": "ipython3",
182+
"version": "3.10.18"
183+
}
184+
},
185+
"nbformat": 4,
186+
"nbformat_minor": 0
187+
}

master/_downloads/059a63fc6cb655dcd2f1c9a61bb9d7ec/plot_OT_2D_samples.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"\n# Optimal Transport between 2D empirical distributions\n\nIllustration of 2D optimal transport between distributions that are weighted\nsum of Diracs. The OT matrix is plotted with the samples.\n"
7+
"\n# Optimal Transport between empirical distributions\n\nIllustration of optimal transport between distributions in 2D that are weighted\nsum of Diracs. The OT matrix is plotted with the samples.\n"
88
]
99
},
1010
{
@@ -51,7 +51,7 @@
5151
},
5252
"outputs": [],
5353
"source": [
54-
"pl.figure(1)\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"Source and target distributions\")\n\npl.figure(2)\npl.imshow(M, interpolation=\"nearest\")\npl.title(\"Cost matrix M\")"
54+
"pl.figure(1)\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"Source and target distributions\")\n\npl.figure(2)\npl.imshow(M, interpolation=\"nearest\", cmap=\"gray_r\")\npl.title(\"Cost matrix M\")"
5555
]
5656
},
5757
{
@@ -69,7 +69,7 @@
6969
},
7070
"outputs": [],
7171
"source": [
72-
"G0 = ot.solve(M, a, b).plan\n\npl.figure(3)\npl.imshow(G0, interpolation=\"nearest\")\npl.title(\"OT matrix G0\")\n\npl.figure(4)\not.plot.plot2D_samples_mat(xs, xt, G0, c=[0.5, 0.5, 1])\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"OT matrix with samples\")"
72+
"G0 = ot.solve(M, a, b).plan\n\npl.figure(3)\npl.imshow(G0, interpolation=\"nearest\", cmap=\"gray_r\")\npl.title(\"OT matrix G0\")\n\npl.figure(4)\not.plot.plot2D_samples_mat(xs, xt, G0, c=[0.5, 0.5, 1])\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"OT matrix with samples\")"
7373
]
7474
},
7575
{
@@ -87,7 +87,7 @@
8787
},
8888
"outputs": [],
8989
"source": [
90-
"# reg term\nlambd = 1e-1\n\nGs = ot.sinkhorn(a, b, M, lambd)\n\npl.figure(5)\npl.imshow(Gs, interpolation=\"nearest\")\npl.title(\"OT matrix sinkhorn\")\n\npl.figure(6)\not.plot.plot2D_samples_mat(xs, xt, Gs, color=[0.5, 0.5, 1])\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"OT matrix Sinkhorn with samples\")\n\npl.show()"
90+
"# reg term\nlambd = 1e-1\n\nGs = ot.sinkhorn(a, b, M, lambd)\n\npl.figure(5)\npl.imshow(Gs, interpolation=\"nearest\", cmap=\"gray_r\")\npl.title(\"OT matrix sinkhorn\")\n\npl.figure(6)\not.plot.plot2D_samples_mat(xs, xt, Gs, color=[0.5, 0.5, 1])\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"OT matrix Sinkhorn with samples\")\n\npl.show()"
9191
]
9292
},
9393
{
@@ -105,7 +105,7 @@
105105
},
106106
"outputs": [],
107107
"source": [
108-
"# reg term\nlambd = 1e-1\n\nGes = ot.bregman.empirical_sinkhorn(xs, xt, lambd)\n\npl.figure(7)\npl.imshow(Ges, interpolation=\"nearest\")\npl.title(\"OT matrix empirical sinkhorn\")\n\npl.figure(8)\not.plot.plot2D_samples_mat(xs, xt, Ges, color=[0.5, 0.5, 1])\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"OT matrix Sinkhorn from samples\")\n\npl.show()"
108+
"# reg term\nlambd = 1e-1\n\nGes = ot.bregman.empirical_sinkhorn(xs, xt, lambd)\n\npl.figure(7)\npl.imshow(Ges, interpolation=\"nearest\", cmap=\"gray_r\")\npl.title(\"OT matrix empirical sinkhorn\")\n\npl.figure(8)\not.plot.plot2D_samples_mat(xs, xt, Ges, color=[0.5, 0.5, 1])\npl.plot(xs[:, 0], xs[:, 1], \"+b\", label=\"Source samples\")\npl.plot(xt[:, 0], xt[:, 1], \"xr\", label=\"Target samples\")\npl.legend(loc=0)\npl.title(\"OT matrix Sinkhorn from samples\")\n\npl.show()"
109109
]
110110
}
111111
],
Binary file not shown.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# OT between GMM : plan and maps in 1D\n\nIllustration of the GMM plan for\nthe Mixture Wasserstein between two GMM in 1D,\nas well as the two maps T_mean and T_rand.\nT_mean is the barycentric projection of the GMM coupling,\nand T_rand takes a random gaussian image between two components,\naccording to the coupling and the GMMs.\nSee [69] for details.\n.. [69] Delon, J., & Desolneux, A. (2020). A Wasserstein-type distance in the space of Gaussian mixture models. SIAM Journal on Imaging Sciences, 13(2), 936-970.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"# Author: Eloi Tanguy <eloi.tanguy@u-paris>\n# Remi Flamary <[email protected]>\n# Julie Delon <[email protected]>\n#\n# License: MIT License\n\n# sphinx_gallery_thumbnail_number = 1\n\nimport numpy as np\nfrom ot.plot import plot1D_mat, rescale_for_imshow_plot\nfrom ot.gmm import gmm_ot_plan_density, gmm_pdf, gmm_ot_apply_map\nimport matplotlib.pyplot as plt"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"## Generate GMMOT plan plot it\n\n"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": false
33+
},
34+
"outputs": [],
35+
"source": [
36+
"ks = 2\nkt = 3\nd = 1\neps = 0.1\nm_s = np.array([[1], [2]])\nm_t = np.array([[3], [4.2], [5]])\nC_s = np.array([[[0.05]], [[0.06]]])\nC_t = np.array([[[0.03]], [[0.07]], [[0.04]]])\nw_s = np.array([0.4, 0.6])\nw_t = np.array([0.4, 0.2, 0.4])\n\nn = 500\na_x, b_x = 0, 3\nx = np.linspace(a_x, b_x, n)\na_y, b_y = 2, 6\ny = np.linspace(a_y, b_y, n)\nplan_density = gmm_ot_plan_density(\n x[:, None], y[:, None], m_s, m_t, C_s, C_t, w_s, w_t, plan=None, atol=2e-2\n)\n\na = gmm_pdf(x[:, None], m_s, C_s, w_s)\nb = gmm_pdf(y[:, None], m_t, C_t, w_t)\nplt.figure(figsize=(8, 8))\nplot1D_mat(\n a,\n b,\n plan_density,\n title=\"GMM OT plan\",\n plot_style=\"xy\",\n a_label=\"Source distribution\",\n b_label=\"Target distribution\",\n)"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"## Generate GMMOT maps and plot them over plan\n\n"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {
50+
"collapsed": false
51+
},
52+
"outputs": [],
53+
"source": [
54+
"plt.figure(figsize=(8, 8))\nax_s, ax_t, ax_M = plot1D_mat(\n a,\n b,\n plan_density,\n plot_style=\"xy\",\n title=\"GMM OT plan with T_mean and T_rand maps\",\n a_label=\"Source distribution\",\n b_label=\"Target distribution\",\n)\nT_mean = gmm_ot_apply_map(x[:, None], m_s, m_t, C_s, C_t, w_s, w_t, method=\"bary\")[:, 0]\nx_rescaled, T_mean_rescaled = rescale_for_imshow_plot(x, T_mean, n, a_y=a_y, b_y=b_y)\n\nax_M.plot(\n x_rescaled, T_mean_rescaled, label=\"T_mean\", alpha=0.5, linewidth=5, color=\"aqua\"\n)\n\nT_rand = gmm_ot_apply_map(\n x[:, None], m_s, m_t, C_s, C_t, w_s, w_t, method=\"rand\", seed=0\n)[:, 0]\nx_rescaled, T_rand_rescaled = rescale_for_imshow_plot(x, T_rand, n, a_y=a_y, b_y=b_y)\n\nax_M.scatter(\n x_rescaled, T_rand_rescaled, label=\"T_rand\", alpha=0.5, s=20, color=\"orange\"\n)\n\nax_M.legend(loc=\"upper left\", fontsize=13)"
55+
]
56+
}
57+
],
58+
"metadata": {
59+
"kernelspec": {
60+
"display_name": "Python 3",
61+
"language": "python",
62+
"name": "python3"
63+
},
64+
"language_info": {
65+
"codemirror_mode": {
66+
"name": "ipython",
67+
"version": 3
68+
},
69+
"file_extension": ".py",
70+
"mimetype": "text/x-python",
71+
"name": "python",
72+
"nbconvert_exporter": "python",
73+
"pygments_lexer": "ipython3",
74+
"version": "3.10.18"
75+
}
76+
},
77+
"nbformat": 4,
78+
"nbformat_minor": 0
79+
}

0 commit comments

Comments
 (0)