summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2020-04-20 22:12:36 +0200
committerRémi Flamary <remi.flamary@gmail.com>2020-04-20 22:12:36 +0200
commit9eaf77a8e8e116d3269c9f35f4d8012119d1312d (patch)
treedc349beb5a8b077ac8269a66635c5a9fc092c123 /docs
parent21949bbc3469234f88972bdfe973f68eb9e62794 (diff)
new example laplacian regularization
Diffstat (limited to 'docs')
-rw-r--r--docs/cache_nbrun2
-rw-r--r--docs/source/auto_examples/auto_examples_jupyter.zipbin168344 -> 173848 bytes
-rw-r--r--docs/source/auto_examples/auto_examples_python.zipbin112497 -> 116265 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.pngbin0 -> 50923 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.pngbin0 -> 146777 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.pngbin23282 -> 24385 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.pngbin19156 -> 19423 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.pngbin47315 -> 46197 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.pngbin19186 -> 19295 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.pngbin0 -> 25970 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.pngbin28023 -> 29112 bytes
-rw-r--r--docs/source/auto_examples/index.rst20
-rw-r--r--docs/source/auto_examples/plot_otda_laplacian.ipynb126
-rw-r--r--docs/source/auto_examples/plot_otda_laplacian.py127
-rw-r--r--docs/source/auto_examples/plot_otda_laplacian.rst233
-rw-r--r--docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb6
-rw-r--r--docs/source/auto_examples/plot_partial_wass_and_gromov.py24
-rw-r--r--docs/source/auto_examples/plot_partial_wass_and_gromov.rst50
18 files changed, 545 insertions, 43 deletions
diff --git a/docs/cache_nbrun b/docs/cache_nbrun
index 2dfa274..ac49515 100644
--- a/docs/cache_nbrun
+++ b/docs/cache_nbrun
@@ -1 +1 @@
-{"plot_otda_color_images.ipynb": "128d0435c08ebcf788913e4adcd7dd00", "plot_partial_wass_and_gromov.ipynb": "161d802bbaa3f7678c05ae113e857085", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_screenkhorn_1D.ipynb": "af7b8a74a1be0f16f2c3908f5a178de0", "plot_OT_L1_vs_L2.ipynb": "288230c4e679d752a511353c96c134cb", "plot_otda_semi_supervised.ipynb": "568b39ffbdf6621dd6de162df42f4f21", "plot_fgw.ipynb": "f4de8e6939ce2b1339b3badc1fef0f37", "plot_otda_d2.ipynb": "07ef3212ff3123f16c32a5670e0167f8", "plot_compute_emd.ipynb": "299f6fffcdbf48b7c3268c0136e284f8", "plot_barycenter_fgw.ipynb": "9e813d3b07b7c0c0fcc35a778ca1243f", "plot_convolutional_barycenter.ipynb": "fdd259bfcd6d5fe8001efb4345795d2f", "plot_optim_OTreg.ipynb": "bddd8e49f092873d8980d41ae4974e19", "plot_UOT_1D.ipynb": "2658d5164165941b07539dae3cb80a0f", "plot_OT_1D_smooth.ipynb": "f3e1f0e362c9a78071a40c02b85d2305", "plot_barycenter_1D.ipynb": "f6fa5bc13d9811f09792f73b4de70aa0", "plot_otda_mapping.ipynb": "1bb321763f670fc945d77cfc91471e5e", "plot_OT_1D.ipynb": "0346a8c862606d11f36d0aa087ecab0d", "plot_gromov_barycenter.ipynb": "a7999fcc236d90a0adeb8da2c6370db3", "plot_UOT_barycenter_1D.ipynb": "dd9b857a8c66d71d0124d4a2c30a51dd", "plot_otda_mapping_colors_images.ipynb": "16faae80d6ea8b37d6b1f702149a10de", "plot_stochastic.ipynb": "64f23a8dcbab9823ae92f0fd6c3aceab", "plot_otda_linear_mapping.ipynb": "82417d9141e310bf1f2c2ecdb550094b", "plot_otda_classes.ipynb": "8836a924c9b562ef397af12034fa1abb", "plot_free_support_barycenter.ipynb": "be9d0823f9d7774a289311b9f14548eb", "plot_gromov.ipynb": "de06b1dbe8de99abae51c2e0b64b485d", "plot_otda_jcpot.ipynb": "65482cbfef5c6c1e5e73998aeb5f4b10", "plot_OT_2D_samples.ipynb": "9a9496792fa4216b1059fc70abca851a", "plot_barycenter_lp_vs_entropic.ipynb": "334840b69a86898813e50a6db0f3d0de"} \ No newline at end of file
+{"plot_otda_color_images.ipynb": "128d0435c08ebcf788913e4adcd7dd00", "plot_partial_wass_and_gromov.ipynb": "82242f8390df1d04806b333b745c72cf", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_screenkhorn_1D.ipynb": "af7b8a74a1be0f16f2c3908f5a178de0", "plot_otda_laplacian.ipynb": "d92cc0e528b9277f550daaa6f9d18415", "plot_OT_L1_vs_L2.ipynb": "288230c4e679d752a511353c96c134cb", "plot_otda_semi_supervised.ipynb": "568b39ffbdf6621dd6de162df42f4f21", "plot_fgw.ipynb": "f4de8e6939ce2b1339b3badc1fef0f37", "plot_otda_d2.ipynb": "07ef3212ff3123f16c32a5670e0167f8", "plot_compute_emd.ipynb": "299f6fffcdbf48b7c3268c0136e284f8", "plot_barycenter_fgw.ipynb": "9e813d3b07b7c0c0fcc35a778ca1243f", "plot_convolutional_barycenter.ipynb": "fdd259bfcd6d5fe8001efb4345795d2f", "plot_optim_OTreg.ipynb": "bddd8e49f092873d8980d41ae4974e19", "plot_UOT_1D.ipynb": "2658d5164165941b07539dae3cb80a0f", "plot_OT_1D_smooth.ipynb": "f3e1f0e362c9a78071a40c02b85d2305", "plot_barycenter_1D.ipynb": "f6fa5bc13d9811f09792f73b4de70aa0", "plot_otda_mapping.ipynb": "1bb321763f670fc945d77cfc91471e5e", "plot_OT_1D.ipynb": "0346a8c862606d11f36d0aa087ecab0d", "plot_gromov_barycenter.ipynb": "a7999fcc236d90a0adeb8da2c6370db3", "plot_UOT_barycenter_1D.ipynb": "dd9b857a8c66d71d0124d4a2c30a51dd", "plot_otda_mapping_colors_images.ipynb": "16faae80d6ea8b37d6b1f702149a10de", "plot_stochastic.ipynb": "64f23a8dcbab9823ae92f0fd6c3aceab", "plot_otda_linear_mapping.ipynb": "82417d9141e310bf1f2c2ecdb550094b", "plot_otda_classes.ipynb": "8836a924c9b562ef397af12034fa1abb", "plot_free_support_barycenter.ipynb": "be9d0823f9d7774a289311b9f14548eb", "plot_gromov.ipynb": "de06b1dbe8de99abae51c2e0b64b485d", "plot_otda_jcpot.ipynb": "65482cbfef5c6c1e5e73998aeb5f4b10", "plot_OT_2D_samples.ipynb": "9a9496792fa4216b1059fc70abca851a", "plot_barycenter_lp_vs_entropic.ipynb": "334840b69a86898813e50a6db0f3d0de"} \ No newline at end of file
diff --git a/docs/source/auto_examples/auto_examples_jupyter.zip b/docs/source/auto_examples/auto_examples_jupyter.zip
index 6e2ed41..069a0f3 100644
--- a/docs/source/auto_examples/auto_examples_jupyter.zip
+++ b/docs/source/auto_examples/auto_examples_jupyter.zip
Binary files differ
diff --git a/docs/source/auto_examples/auto_examples_python.zip b/docs/source/auto_examples/auto_examples_python.zip
index 3eeec84..e04aed4 100644
--- a/docs/source/auto_examples/auto_examples_python.zip
+++ b/docs/source/auto_examples/auto_examples_python.zip
Binary files differ
diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png
new file mode 100644
index 0000000..66ef851
--- /dev/null
+++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png
Binary files differ
diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png
new file mode 100644
index 0000000..f9a4959
--- /dev/null
+++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png
Binary files differ
diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png
index 81e3ac1..f944550 100644
--- a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png
Binary files differ
diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png
index 08ad04a..45542c1 100644
--- a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png
Binary files differ
diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png
index 0bde5df..83e0d41 100644
--- a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png
Binary files differ
diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png
index 170c6d6..a1ba204 100644
--- a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png
Binary files differ
diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png
new file mode 100644
index 0000000..db37d2b
--- /dev/null
+++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png
Binary files differ
diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png
index a57889e..0f630f1 100644
--- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png
+++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png
Binary files differ
diff --git a/docs/source/auto_examples/index.rst b/docs/source/auto_examples/index.rst
index 60536b6..9f05263 100644
--- a/docs/source/auto_examples/index.rst
+++ b/docs/source/auto_examples/index.rst
@@ -313,6 +313,26 @@ This is a gallery of all the POT example files.
.. raw:: html
+ <div class="sphx-glr-thumbcontainer" tooltip="This example introduces a domain adaptation in a 2D setting and OTDA approach with Laplacian re...">
+
+.. only:: html
+
+ .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png
+
+ :ref:`sphx_glr_auto_examples_plot_otda_laplacian.py`
+
+.. raw:: html
+
+ </div>
+
+
+.. toctree::
+ :hidden:
+
+ /auto_examples/plot_otda_laplacian
+
+.. raw:: html
+
<div class="sphx-glr-thumbcontainer" tooltip="OT for domain adaptation with image color adaptation [6] with mapping estimation [8].">
.. only:: html
diff --git a/docs/source/auto_examples/plot_otda_laplacian.ipynb b/docs/source/auto_examples/plot_otda_laplacian.ipynb
new file mode 100644
index 0000000..c1e9efe
--- /dev/null
+++ b/docs/source/auto_examples/plot_otda_laplacian.ipynb
@@ -0,0 +1,126 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "%matplotlib inline"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n# OT with Laplacian regularization for domain adaptation\n\n\nThis example introduces a domain adaptation in a 2D setting and OTDA\napproach with Laplacian regularization.\n\n\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "# Authors: Ievgen Redko <ievgen.redko@univ-st-etienne.fr>\n\n# License: MIT License\n\nimport matplotlib.pylab as pl\nimport ot"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Generate data\n-------------\n\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "n_source_samples = 150\nn_target_samples = 150\n\nXs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples)\nXt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Instantiate the different transport algorithms and fit them\n-----------------------------------------------------------\n\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "# EMD Transport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\n\n# Sinkhorn Transport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=.01)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\n\n# EMD Transport with Laplacian regularization\not_emd_laplace = ot.da.EMDLaplaceTransport(reg_lap=100, reg_src=1)\not_emd_laplace.fit(Xs=Xs, Xt=Xt)\n\n# transport source samples onto target samples\ntransp_Xs_emd = ot_emd.transform(Xs=Xs)\ntransp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=Xs)\ntransp_Xs_emd_laplace = ot_emd_laplace.transform(Xs=Xs)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Fig 1 : plots source and target samples\n---------------------------------------\n\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "pl.figure(1, figsize=(10, 5))\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')\npl.xticks([])\npl.yticks([])\npl.legend(loc=0)\npl.title('Source samples')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')\npl.xticks([])\npl.yticks([])\npl.legend(loc=0)\npl.title('Target samples')\npl.tight_layout()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Fig 2 : plot optimal couplings and transported samples\n------------------------------------------------------\n\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "param_img = {'interpolation': 'nearest'}\n\npl.figure(2, figsize=(15, 8))\npl.subplot(2, 3, 1)\npl.imshow(ot_emd.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nEMDTransport')\n\npl.figure(2, figsize=(15, 8))\npl.subplot(2, 3, 2)\npl.imshow(ot_sinkhorn.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSinkhornTransport')\n\npl.subplot(2, 3, 3)\npl.imshow(ot_emd_laplace.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nEMDLaplaceTransport')\n\npl.subplot(2, 3, 4)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nEmdTransport')\npl.legend(loc=\"lower left\")\n\npl.subplot(2, 3, 5)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nSinkhornTransport')\n\npl.subplot(2, 3, 6)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_emd_laplace[:, 0], transp_Xs_emd_laplace[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nEMDLaplaceTransport')\npl.tight_layout()\n\npl.show()"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+} \ No newline at end of file
diff --git a/docs/source/auto_examples/plot_otda_laplacian.py b/docs/source/auto_examples/plot_otda_laplacian.py
new file mode 100644
index 0000000..67c8f67
--- /dev/null
+++ b/docs/source/auto_examples/plot_otda_laplacian.py
@@ -0,0 +1,127 @@
+# -*- coding: utf-8 -*-
+"""
+======================================================
+OT with Laplacian regularization for domain adaptation
+======================================================
+
+This example introduces a domain adaptation in a 2D setting and OTDA
+approach with Laplacian regularization.
+
+"""
+
+# Authors: Ievgen Redko <ievgen.redko@univ-st-etienne.fr>
+
+# License: MIT License
+
+import matplotlib.pylab as pl
+import ot
+
+##############################################################################
+# Generate data
+# -------------
+
+n_source_samples = 150
+n_target_samples = 150
+
+Xs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples)
+Xt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples)
+
+
+##############################################################################
+# Instantiate the different transport algorithms and fit them
+# -----------------------------------------------------------
+
+# EMD Transport
+ot_emd = ot.da.EMDTransport()
+ot_emd.fit(Xs=Xs, Xt=Xt)
+
+# Sinkhorn Transport
+ot_sinkhorn = ot.da.SinkhornTransport(reg_e=.01)
+ot_sinkhorn.fit(Xs=Xs, Xt=Xt)
+
+# EMD Transport with Laplacian regularization
+ot_emd_laplace = ot.da.EMDLaplaceTransport(reg_lap=100, reg_src=1)
+ot_emd_laplace.fit(Xs=Xs, Xt=Xt)
+
+# transport source samples onto target samples
+transp_Xs_emd = ot_emd.transform(Xs=Xs)
+transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=Xs)
+transp_Xs_emd_laplace = ot_emd_laplace.transform(Xs=Xs)
+
+##############################################################################
+# Fig 1 : plots source and target samples
+# ---------------------------------------
+
+pl.figure(1, figsize=(10, 5))
+pl.subplot(1, 2, 1)
+pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')
+pl.xticks([])
+pl.yticks([])
+pl.legend(loc=0)
+pl.title('Source samples')
+
+pl.subplot(1, 2, 2)
+pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')
+pl.xticks([])
+pl.yticks([])
+pl.legend(loc=0)
+pl.title('Target samples')
+pl.tight_layout()
+
+
+##############################################################################
+# Fig 2 : plot optimal couplings and transported samples
+# ------------------------------------------------------
+
+param_img = {'interpolation': 'nearest'}
+
+pl.figure(2, figsize=(15, 8))
+pl.subplot(2, 3, 1)
+pl.imshow(ot_emd.coupling_, **param_img)
+pl.xticks([])
+pl.yticks([])
+pl.title('Optimal coupling\nEMDTransport')
+
+pl.figure(2, figsize=(15, 8))
+pl.subplot(2, 3, 2)
+pl.imshow(ot_sinkhorn.coupling_, **param_img)
+pl.xticks([])
+pl.yticks([])
+pl.title('Optimal coupling\nSinkhornTransport')
+
+pl.subplot(2, 3, 3)
+pl.imshow(ot_emd_laplace.coupling_, **param_img)
+pl.xticks([])
+pl.yticks([])
+pl.title('Optimal coupling\nEMDLaplaceTransport')
+
+pl.subplot(2, 3, 4)
+pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',
+ label='Target samples', alpha=0.3)
+pl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys,
+ marker='+', label='Transp samples', s=30)
+pl.xticks([])
+pl.yticks([])
+pl.title('Transported samples\nEmdTransport')
+pl.legend(loc="lower left")
+
+pl.subplot(2, 3, 5)
+pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',
+ label='Target samples', alpha=0.3)
+pl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys,
+ marker='+', label='Transp samples', s=30)
+pl.xticks([])
+pl.yticks([])
+pl.title('Transported samples\nSinkhornTransport')
+
+pl.subplot(2, 3, 6)
+pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',
+ label='Target samples', alpha=0.3)
+pl.scatter(transp_Xs_emd_laplace[:, 0], transp_Xs_emd_laplace[:, 1], c=ys,
+ marker='+', label='Transp samples', s=30)
+pl.xticks([])
+pl.yticks([])
+pl.title('Transported samples\nEMDLaplaceTransport')
+pl.tight_layout()
+
+pl.show()
diff --git a/docs/source/auto_examples/plot_otda_laplacian.rst b/docs/source/auto_examples/plot_otda_laplacian.rst
new file mode 100644
index 0000000..12cd7b9
--- /dev/null
+++ b/docs/source/auto_examples/plot_otda_laplacian.rst
@@ -0,0 +1,233 @@
+.. only:: html
+
+ .. note::
+ :class: sphx-glr-download-link-note
+
+ Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_laplacian.py>` to download the full example code
+ .. rst-class:: sphx-glr-example-title
+
+ .. _sphx_glr_auto_examples_plot_otda_laplacian.py:
+
+
+======================================================
+OT with Laplacian regularization for domain adaptation
+======================================================
+
+This example introduces a domain adaptation in a 2D setting and OTDA
+approach with Laplacian regularization.
+
+
+
+.. code-block:: default
+
+
+ # Authors: Ievgen Redko <ievgen.redko@univ-st-etienne.fr>
+
+ # License: MIT License
+
+ import matplotlib.pylab as pl
+ import ot
+
+
+
+
+
+
+
+
+Generate data
+-------------
+
+
+.. code-block:: default
+
+
+ n_source_samples = 150
+ n_target_samples = 150
+
+ Xs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples)
+ Xt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples)
+
+
+
+
+
+
+
+
+
+Instantiate the different transport algorithms and fit them
+-----------------------------------------------------------
+
+
+.. code-block:: default
+
+
+ # EMD Transport
+ ot_emd = ot.da.EMDTransport()
+ ot_emd.fit(Xs=Xs, Xt=Xt)
+
+ # Sinkhorn Transport
+ ot_sinkhorn = ot.da.SinkhornTransport(reg_e=.01)
+ ot_sinkhorn.fit(Xs=Xs, Xt=Xt)
+
+ # EMD Transport with Laplacian regularization
+ ot_emd_laplace = ot.da.EMDLaplaceTransport(reg_lap=100, reg_src=1)
+ ot_emd_laplace.fit(Xs=Xs, Xt=Xt)
+
+ # transport source samples onto target samples
+ transp_Xs_emd = ot_emd.transform(Xs=Xs)
+ transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=Xs)
+ transp_Xs_emd_laplace = ot_emd_laplace.transform(Xs=Xs)
+
+
+
+
+
+
+
+
+Fig 1 : plots source and target samples
+---------------------------------------
+
+
+.. code-block:: default
+
+
+ pl.figure(1, figsize=(10, 5))
+ pl.subplot(1, 2, 1)
+ pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')
+ pl.xticks([])
+ pl.yticks([])
+ pl.legend(loc=0)
+ pl.title('Source samples')
+
+ pl.subplot(1, 2, 2)
+ pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')
+ pl.xticks([])
+ pl.yticks([])
+ pl.legend(loc=0)
+ pl.title('Target samples')
+ pl.tight_layout()
+
+
+
+
+
+.. image:: /auto_examples/images/sphx_glr_plot_otda_laplacian_001.png
+ :class: sphx-glr-single-img
+
+
+
+
+
+Fig 2 : plot optimal couplings and transported samples
+------------------------------------------------------
+
+
+.. code-block:: default
+
+
+ param_img = {'interpolation': 'nearest'}
+
+ pl.figure(2, figsize=(15, 8))
+ pl.subplot(2, 3, 1)
+ pl.imshow(ot_emd.coupling_, **param_img)
+ pl.xticks([])
+ pl.yticks([])
+ pl.title('Optimal coupling\nEMDTransport')
+
+ pl.figure(2, figsize=(15, 8))
+ pl.subplot(2, 3, 2)
+ pl.imshow(ot_sinkhorn.coupling_, **param_img)
+ pl.xticks([])
+ pl.yticks([])
+ pl.title('Optimal coupling\nSinkhornTransport')
+
+ pl.subplot(2, 3, 3)
+ pl.imshow(ot_emd_laplace.coupling_, **param_img)
+ pl.xticks([])
+ pl.yticks([])
+ pl.title('Optimal coupling\nEMDLaplaceTransport')
+
+ pl.subplot(2, 3, 4)
+ pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',
+ label='Target samples', alpha=0.3)
+ pl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys,
+ marker='+', label='Transp samples', s=30)
+ pl.xticks([])
+ pl.yticks([])
+ pl.title('Transported samples\nEmdTransport')
+ pl.legend(loc="lower left")
+
+ pl.subplot(2, 3, 5)
+ pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',
+ label='Target samples', alpha=0.3)
+ pl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys,
+ marker='+', label='Transp samples', s=30)
+ pl.xticks([])
+ pl.yticks([])
+ pl.title('Transported samples\nSinkhornTransport')
+
+ pl.subplot(2, 3, 6)
+ pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',
+ label='Target samples', alpha=0.3)
+ pl.scatter(transp_Xs_emd_laplace[:, 0], transp_Xs_emd_laplace[:, 1], c=ys,
+ marker='+', label='Transp samples', s=30)
+ pl.xticks([])
+ pl.yticks([])
+ pl.title('Transported samples\nEMDLaplaceTransport')
+ pl.tight_layout()
+
+ pl.show()
+
+
+
+.. image:: /auto_examples/images/sphx_glr_plot_otda_laplacian_002.png
+ :class: sphx-glr-single-img
+
+
+.. rst-class:: sphx-glr-script-out
+
+ Out:
+
+ .. code-block:: none
+
+ /home/rflamary/PYTHON/POT/examples/plot_otda_laplacian.py:127: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
+ pl.show()
+
+
+
+
+
+.. rst-class:: sphx-glr-timing
+
+ **Total running time of the script:** ( 0 minutes 1.195 seconds)
+
+
+.. _sphx_glr_download_auto_examples_plot_otda_laplacian.py:
+
+
+.. only :: html
+
+ .. container:: sphx-glr-footer
+ :class: sphx-glr-footer-example
+
+
+
+ .. container:: sphx-glr-download sphx-glr-download-python
+
+ :download:`Download Python source code: plot_otda_laplacian.py <plot_otda_laplacian.py>`
+
+
+
+ .. container:: sphx-glr-download sphx-glr-download-jupyter
+
+ :download:`Download Jupyter notebook: plot_otda_laplacian.ipynb <plot_otda_laplacian.ipynb>`
+
+
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb b/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb
index 0f69ec1..539d575 100644
--- a/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb
+++ b/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb
@@ -51,7 +51,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Compute partial Wasserstein plans and distance,\nby transporting 50% of the mass\n----------------------------------------------\n\n"
+ "Compute partial Wasserstein plans and distance\n----------------------------------------------\n\n"
]
},
{
@@ -87,7 +87,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Compute partial Gromov-Wasserstein plans and distance,\nby transporting 100% and 2/3 of the mass\n-----------------------------------------------------\n\n"
+ "Compute partial Gromov-Wasserstein plans and distance\n-----------------------------------------------------\n\n"
]
},
{
@@ -98,7 +98,7 @@
},
"outputs": [],
"source": [
- "C1 = sp.spatial.distance.cdist(xs, xs)\nC2 = sp.spatial.distance.cdist(xt, xt)\n\nprint('-----m = 1')\nm = 1\nres0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m,\n log=True)\nres, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,\n m=m, log=True)\n\nprint('Partial Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))\nprint('Entropic partial Wasserstein distance (m = 1): ' +\n str(log['partial_gw_dist']))\n\npl.figure(1, (10, 5))\npl.title(\"mass to be transported m = 1\")\npl.subplot(1, 2, 1)\npl.imshow(res0, cmap='jet')\npl.title('Partial Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(res, cmap='jet')\npl.title('Entropic partial Wasserstein')\npl.show()\n\nprint('-----m = 2/3')\nm = 2 / 3\nres0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)\nres, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,\n m=m, log=True)\n\nprint('Partial Wasserstein distance (m = 2/3): ' +\n str(log0['partial_gw_dist']))\nprint('Entropic partial Wasserstein distance (m = 2/3): ' +\n str(log['partial_gw_dist']))\n\npl.figure(1, (10, 5))\npl.title(\"mass to be transported m = 2/3\")\npl.subplot(1, 2, 1)\npl.imshow(res0, cmap='jet')\npl.title('Partial Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(res, cmap='jet')\npl.title('Entropic partial Wasserstein')\npl.show()"
+ "C1 = sp.spatial.distance.cdist(xs, xs)\nC2 = sp.spatial.distance.cdist(xt, xt)\n\n# transport 100% of the mass\nprint('-----m = 1')\nm = 1\nres0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)\nres, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,\n m=m, log=True)\n\nprint('Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))\nprint('Entropic Wasserstein distance (m = 1): ' + str(log['partial_gw_dist']))\n\npl.figure(1, (10, 5))\npl.title(\"mass to be transported m = 1\")\npl.subplot(1, 2, 1)\npl.imshow(res0, cmap='jet')\npl.title('Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(res, cmap='jet')\npl.title('Entropic Wasserstein')\npl.show()\n\n# transport 2/3 of the mass\nprint('-----m = 2/3')\nm = 2 / 3\nres0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)\nres, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,\n m=m, log=True)\n\nprint('Partial Wasserstein distance (m = 2/3): ' +\n str(log0['partial_gw_dist']))\nprint('Entropic partial Wasserstein distance (m = 2/3): ' +\n str(log['partial_gw_dist']))\n\npl.figure(1, (10, 5))\npl.title(\"mass to be transported m = 2/3\")\npl.subplot(1, 2, 1)\npl.imshow(res0, cmap='jet')\npl.title('Partial Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(res, cmap='jet')\npl.title('Entropic partial Wasserstein')\npl.show()"
]
}
],
diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.py b/docs/source/auto_examples/plot_partial_wass_and_gromov.py
index 01141f2..9f95a70 100644
--- a/docs/source/auto_examples/plot_partial_wass_and_gromov.py
+++ b/docs/source/auto_examples/plot_partial_wass_and_gromov.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""
-==========================
+==================================================
Partial Wasserstein and Gromov-Wasserstein example
-==========================
+==================================================
This example is designed to show how to use the Partial (Gromov-)Wassertsein
distance computation in POT.
@@ -52,8 +52,7 @@ pl.show()
#############################################################################
#
-# Compute partial Wasserstein plans and distance,
-# by transporting 50% of the mass
+# Compute partial Wasserstein plans and distance
# ----------------------------------------------
p = ot.unif(n_samples + n_noise)
@@ -115,34 +114,33 @@ pl.show()
#############################################################################
#
-# Compute partial Gromov-Wasserstein plans and distance,
-# by transporting 100% and 2/3 of the mass
+# Compute partial Gromov-Wasserstein plans and distance
# -----------------------------------------------------
C1 = sp.spatial.distance.cdist(xs, xs)
C2 = sp.spatial.distance.cdist(xt, xt)
+# transport 100% of the mass
print('-----m = 1')
m = 1
-res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m,
- log=True)
+res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)
res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,
m=m, log=True)
-print('Partial Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))
-print('Entropic partial Wasserstein distance (m = 1): ' +
- str(log['partial_gw_dist']))
+print('Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))
+print('Entropic Wasserstein distance (m = 1): ' + str(log['partial_gw_dist']))
pl.figure(1, (10, 5))
pl.title("mass to be transported m = 1")
pl.subplot(1, 2, 1)
pl.imshow(res0, cmap='jet')
-pl.title('Partial Wasserstein')
+pl.title('Wasserstein')
pl.subplot(1, 2, 2)
pl.imshow(res, cmap='jet')
-pl.title('Entropic partial Wasserstein')
+pl.title('Entropic Wasserstein')
pl.show()
+# transport 2/3 of the mass
print('-----m = 2/3')
m = 2 / 3
res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)
diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.rst b/docs/source/auto_examples/plot_partial_wass_and_gromov.rst
index 7f47f83..2d51210 100644
--- a/docs/source/auto_examples/plot_partial_wass_and_gromov.rst
+++ b/docs/source/auto_examples/plot_partial_wass_and_gromov.rst
@@ -9,9 +9,9 @@
.. _sphx_glr_auto_examples_plot_partial_wass_and_gromov.py:
-==========================
+==================================================
Partial Wasserstein and Gromov-Wasserstein example
-==========================
+==================================================
This example is designed to show how to use the Partial (Gromov-)Wassertsein
distance computation in POT.
@@ -90,8 +90,7 @@ spaces and add some random noise.
-Compute partial Wasserstein plans and distance,
-by transporting 50% of the mass
+Compute partial Wasserstein plans and distance
----------------------------------------------
@@ -132,9 +131,9 @@ by transporting 50% of the mass
.. code-block:: none
- Partial Wasserstein distance (m = 0.5): 0.29721185147886475
- Entropic partial Wasserstein distance (m = 0.5): 0.31204119793315976
- /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:77: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
+ Partial Wasserstein distance (m = 0.5): 0.507323938973194
+ Entropic partial Wasserstein distance (m = 0.5): 0.5205305886057896
+ /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:76: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
pl.show()
@@ -191,14 +190,13 @@ two Gaussian distributions in 2- and 3-dimensional spaces.
.. code-block:: none
- /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:113: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
+ /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:112: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
pl.show()
-Compute partial Gromov-Wasserstein plans and distance,
-by transporting 100% and 2/3 of the mass
+Compute partial Gromov-Wasserstein plans and distance
-----------------------------------------------------
@@ -208,27 +206,27 @@ by transporting 100% and 2/3 of the mass
C1 = sp.spatial.distance.cdist(xs, xs)
C2 = sp.spatial.distance.cdist(xt, xt)
+ # transport 100% of the mass
print('-----m = 1')
m = 1
- res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m,
- log=True)
+ res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)
res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,
m=m, log=True)
- print('Partial Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))
- print('Entropic partial Wasserstein distance (m = 1): ' +
- str(log['partial_gw_dist']))
+ print('Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))
+ print('Entropic Wasserstein distance (m = 1): ' + str(log['partial_gw_dist']))
pl.figure(1, (10, 5))
pl.title("mass to be transported m = 1")
pl.subplot(1, 2, 1)
pl.imshow(res0, cmap='jet')
- pl.title('Partial Wasserstein')
+ pl.title('Wasserstein')
pl.subplot(1, 2, 2)
pl.imshow(res, cmap='jet')
- pl.title('Entropic partial Wasserstein')
+ pl.title('Entropic Wasserstein')
pl.show()
+ # transport 2/3 of the mass
print('-----m = 2/3')
m = 2 / 3
res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)
@@ -263,18 +261,18 @@ by transporting 100% and 2/3 of the mass
.. code-block:: none
-----m = 1
- Partial Wasserstein distance (m = 1): 56.18870587756925
- Entropic partial Wasserstein distance (m = 1): 57.63642536818668
- /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:144: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
+ Wasserstein distance (m = 1): 63.65368600872179
+ Entropic Wasserstein distance (m = 1): 65.23659085946916
+ /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:141: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
pl.show()
-----m = 2/3
- Partial Wasserstein distance (m = 2/3): 0.18550643334550976
- Entropic partial Wasserstein distance (m = 2/3): 1.0781947761552997
- /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:159: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
+ Partial Wasserstein distance (m = 2/3): 0.23235485397666825
+ Entropic partial Wasserstein distance (m = 2/3): 1.4645434781619244
+ /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:157: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
pl.subplot(1, 2, 1)
- /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:162: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
+ /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:160: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
pl.subplot(1, 2, 2)
- /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:165: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
+ /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:163: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
pl.show()
@@ -283,7 +281,7 @@ by transporting 100% and 2/3 of the mass
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** ( 0 minutes 1.656 seconds)
+ **Total running time of the script:** ( 0 minutes 1.543 seconds)
.. _sphx_glr_download_auto_examples_plot_partial_wass_and_gromov.py: