.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/others/plot_GMMOT_plan.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_others_plot_GMMOT_plan.py: ==================================================== GMM Plan 1D ==================================================== Illustration of the GMM plan for the Mixture Wasserstein between two GMM in 1D, as well as the two maps T_mean and T_rand. T_mean is the barycentric projection of the GMM coupling, and T_rand takes a random gaussian image between two components, according to the coupling and the GMMs. See [69] for details. .. [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. .. GENERATED FROM PYTHON SOURCE LINES 18-32 .. code-block:: Python # Author: Eloi Tanguy # Remi Flamary # Julie Delon # # License: MIT License # sphinx_gallery_thumbnail_number = 1 import numpy as np from ot.plot import plot1D_mat, rescale_for_imshow_plot from ot.gmm import gmm_ot_plan_density, gmm_pdf, gmm_ot_apply_map import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 33-35 Generate GMMOT plan plot it --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-69 .. code-block:: Python ks = 2 kt = 3 d = 1 eps = 0.1 m_s = np.array([[1], [2]]) m_t = np.array([[3], [4.2], [5]]) C_s = np.array([[[0.05]], [[0.06]]]) C_t = np.array([[[0.03]], [[0.07]], [[0.04]]]) w_s = np.array([0.4, 0.6]) w_t = np.array([0.4, 0.2, 0.4]) n = 500 a_x, b_x = 0, 3 x = np.linspace(a_x, b_x, n) a_y, b_y = 2, 6 y = np.linspace(a_y, b_y, n) plan_density = gmm_ot_plan_density( x[:, None], y[:, None], m_s, m_t, C_s, C_t, w_s, w_t, plan=None, atol=2e-2 ) a = gmm_pdf(x[:, None], m_s, C_s, w_s) b = gmm_pdf(y[:, None], m_t, C_t, w_t) plt.figure(figsize=(8, 8)) plot1D_mat( a, b, plan_density, title="GMM OT plan", plot_style="xy", a_label="Source distribution", b_label="Target distribution", ) .. image-sg:: /auto_examples/others/images/sphx_glr_plot_GMMOT_plan_001.png :alt: Source distribution, Target distribution, GMM OT plan :srcset: /auto_examples/others/images/sphx_glr_plot_GMMOT_plan_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (, , ) .. GENERATED FROM PYTHON SOURCE LINES 70-72 Generate GMMOT maps and plot them over plan ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 72-100 .. code-block:: Python plt.figure(figsize=(8, 8)) ax_s, ax_t, ax_M = plot1D_mat( a, b, plan_density, plot_style="xy", title="GMM OT plan with T_mean and T_rand maps", a_label="Source distribution", b_label="Target distribution", ) T_mean = gmm_ot_apply_map(x[:, None], m_s, m_t, C_s, C_t, w_s, w_t, method="bary")[:, 0] x_rescaled, T_mean_rescaled = rescale_for_imshow_plot(x, T_mean, n, a_y=a_y, b_y=b_y) ax_M.plot( x_rescaled, T_mean_rescaled, label="T_mean", alpha=0.5, linewidth=5, color="aqua" ) T_rand = gmm_ot_apply_map( x[:, None], m_s, m_t, C_s, C_t, w_s, w_t, method="rand", seed=0 )[:, 0] x_rescaled, T_rand_rescaled = rescale_for_imshow_plot(x, T_rand, n, a_y=a_y, b_y=b_y) ax_M.scatter( x_rescaled, T_rand_rescaled, label="T_rand", alpha=0.5, s=20, color="orange" ) ax_M.legend(loc="upper left", fontsize=13) .. image-sg:: /auto_examples/others/images/sphx_glr_plot_GMMOT_plan_002.png :alt: Source distribution, Target distribution, GMM OT plan with T_mean and T_rand maps :srcset: /auto_examples/others/images/sphx_glr_plot_GMMOT_plan_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.328 seconds) .. _sphx_glr_download_auto_examples_others_plot_GMMOT_plan.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_GMMOT_plan.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_GMMOT_plan.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_GMMOT_plan.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_