.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_screenkhorn_1D.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_screenkhorn_1D.py: =============================== 1D Screened optimal transport =============================== This example illustrates the computation of Screenkhorn [26]. [26] Alaya M. Z., Bérar M., Gasso G., Rakotomamonjy A. (2019). Screening Sinkhorn Algorithm for Regularized Optimal Transport, Advances in Neural Information Processing Systems 33 (NeurIPS). .. GENERATED FROM PYTHON SOURCE LINES 13-24 .. code-block:: default # Author: Mokhtar Z. Alaya # # License: MIT License import numpy as np import matplotlib.pylab as pl import ot.plot from ot.datasets import make_1D_gauss as gauss from ot.bregman import screenkhorn .. GENERATED FROM PYTHON SOURCE LINES 25-27 Generate data ------------- .. GENERATED FROM PYTHON SOURCE LINES 29-43 .. code-block:: default n = 100 # nb bins # bin positions x = np.arange(n, dtype=np.float64) # Gaussian distributions a = gauss(n, m=20, s=5) # m= mean, s= std b = gauss(n, m=60, s=10) # loss matrix M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) M /= M.max() .. GENERATED FROM PYTHON SOURCE LINES 44-46 Plot distributions and loss matrix ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 48-59 .. code-block:: default pl.figure(1, figsize=(6.4, 3)) pl.plot(x, a, 'b', label='Source distribution') pl.plot(x, b, 'r', label='Target distribution') pl.legend() # plot distributions and loss matrix pl.figure(2, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png :alt: plot screenkhorn 1D :srcset: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png :alt: Cost matrix M :srcset: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 60-62 Solve Screenkhorn ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 62-72 .. code-block:: default # Screenkhorn lambd = 2e-03 # entropy parameter ns_budget = 30 # budget number of points to be keeped in the source distribution nt_budget = 30 # budget number of points to be keeped in the target distribution G_screen = screenkhorn(a, b, M, lambd, ns_budget, nt_budget, uniform=False, restricted=True, verbose=True) pl.figure(4, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, G_screen, 'OT matrix Screenkhorn') pl.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png :alt: OT matrix Screenkhorn :srcset: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/circleci/project/ot/bregman.py:3318: UserWarning: Bottleneck module is not installed. Install it from https://pypi.org/project/Bottleneck/ for better performance. warnings.warn( epsilon = 0.020986042861303855 kappa = 3.7476531411890917 Cardinality of selected points: |Isel| = 30 |Jsel| = 30 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.251 seconds) .. _sphx_glr_download_auto_examples_plot_screenkhorn_1D.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_screenkhorn_1D.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_screenkhorn_1D.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_