From e65606ae498bd611f6a994868c2a66dfbea403cd Mon Sep 17 00:00:00 2001 From: Rémi Flamary Date: Mon, 20 Apr 2020 15:19:09 +0200 Subject: big update examples --- .../thumb/sphx_glr_plot_otda_mapping_thumb.png | Bin 15931 -> 17274 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png') diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png index bd7c939..2c0ddb1 100644 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png and b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png differ -- cgit v1.2.3 From a303cc6b483d3cd958c399621e22e40574bcbbc8 Mon Sep 17 00:00:00 2001 From: Rémi Flamary Date: Tue, 21 Apr 2020 17:48:37 +0200 Subject: [MRG] Actually run sphinx-gallery (#146) * generate gallery * remove mock * add sklearn to requirermnt?txt for example * remove latex from fgw example * add networks for graph example * remove all * add requirement.txt rtd * rtd debug * update readme * eradthedoc with redirection * add conf rtd --- README.md | 10 +- docs/requirements.txt | 1 + docs/requirements_rtd.txt | 14 + docs/rtd/conf.py | 6 + .../source/auto_examples/auto_examples_jupyter.zip | Bin 173848 -> 0 bytes docs/source/auto_examples/auto_examples_python.zip | Bin 116265 -> 0 bytes .../images/sphx_glr_plot_OT_1D_001.png | Bin 21371 -> 0 bytes .../images/sphx_glr_plot_OT_1D_002.png | Bin 25480 -> 0 bytes .../images/sphx_glr_plot_OT_1D_003.png | Bin 17109 -> 0 bytes .../images/sphx_glr_plot_OT_1D_004.png | Bin 19057 -> 0 bytes .../images/sphx_glr_plot_OT_1D_005.png | Bin 17080 -> 0 bytes .../images/sphx_glr_plot_OT_1D_007.png | Bin 19019 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_001.png | Bin 21371 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_002.png | Bin 25480 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_003.png | Bin 17109 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_004.png | Bin 19399 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_005.png | Bin 20645 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_006.png | Bin 19338 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_007.png | Bin 19405 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_009.png | Bin 20630 -> 0 bytes .../images/sphx_glr_plot_OT_1D_smooth_010.png | Bin 19232 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_001.png | Bin 20647 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_002.png | Bin 20913 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_003.png | Bin 9718 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_004.png | Bin 83429 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_005.png | Bin 14451 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_006.png | Bin 100176 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_007.png | Bin 10845 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_008.png | Bin 20218 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_009.png | Bin 14611 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_010.png | Bin 97487 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_013.png | Bin 10846 -> 0 bytes .../images/sphx_glr_plot_OT_2D_samples_014.png | Bin 20361 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_001.png | Bin 11772 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_002.png | Bin 17044 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_003.png | Bin 38543 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_004.png | Bin 14185 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_005.png | Bin 18499 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_006.png | Bin 20885 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_007.png | Bin 14186 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_008.png | Bin 18765 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_009.png | Bin 21300 -> 0 bytes .../images/sphx_glr_plot_OT_L1_vs_L2_011.png | Bin 21369 -> 0 bytes .../images/sphx_glr_plot_UOT_1D_001.png | Bin 21238 -> 0 bytes .../images/sphx_glr_plot_UOT_1D_002.png | Bin 25480 -> 0 bytes .../images/sphx_glr_plot_UOT_1D_003.png | Bin 21177 -> 0 bytes .../images/sphx_glr_plot_UOT_1D_006.png | Bin 21288 -> 0 bytes .../images/sphx_glr_plot_UOT_barycenter_1D_001.png | Bin 22411 -> 0 bytes .../images/sphx_glr_plot_UOT_barycenter_1D_002.png | Bin 42664 -> 0 bytes .../images/sphx_glr_plot_UOT_barycenter_1D_003.png | Bin 107250 -> 0 bytes .../images/sphx_glr_plot_UOT_barycenter_1D_004.png | Bin 104158 -> 0 bytes .../images/sphx_glr_plot_UOT_barycenter_1D_005.png | Bin 105997 -> 0 bytes .../images/sphx_glr_plot_UOT_barycenter_1D_006.png | Bin 103234 -> 0 bytes .../auto_examples/images/sphx_glr_plot_WDA_001.png | Bin 56604 -> 0 bytes .../auto_examples/images/sphx_glr_plot_WDA_003.png | Bin 87031 -> 0 bytes .../images/sphx_glr_plot_barycenter_1D_001.png | Bin 20509 -> 0 bytes .../images/sphx_glr_plot_barycenter_1D_002.png | Bin 41597 -> 0 bytes .../images/sphx_glr_plot_barycenter_1D_003.png | Bin 111987 -> 0 bytes .../images/sphx_glr_plot_barycenter_1D_004.png | Bin 109220 -> 0 bytes .../images/sphx_glr_plot_barycenter_1D_005.png | Bin 108756 -> 0 bytes .../images/sphx_glr_plot_barycenter_1D_006.png | Bin 105765 -> 0 bytes .../images/sphx_glr_plot_barycenter_fgw_001.png | Bin 131826 -> 0 bytes .../images/sphx_glr_plot_barycenter_fgw_002.png | Bin 29422 -> 0 bytes ...sphx_glr_plot_barycenter_lp_vs_entropic_001.png | Bin 20509 -> 0 bytes ...sphx_glr_plot_barycenter_lp_vs_entropic_002.png | Bin 46050 -> 0 bytes ...sphx_glr_plot_barycenter_lp_vs_entropic_003.png | Bin 14056 -> 0 bytes ...sphx_glr_plot_barycenter_lp_vs_entropic_004.png | Bin 38250 -> 0 bytes ...sphx_glr_plot_barycenter_lp_vs_entropic_005.png | Bin 13721 -> 0 bytes ...sphx_glr_plot_barycenter_lp_vs_entropic_006.png | Bin 33603 -> 0 bytes ...sphx_glr_plot_barycenter_lp_vs_entropic_007.png | Bin 70939 -> 0 bytes .../images/sphx_glr_plot_compute_emd_001.png | Bin 162714 -> 0 bytes .../images/sphx_glr_plot_compute_emd_002.png | Bin 29344 -> 0 bytes .../images/sphx_glr_plot_compute_emd_003.png | Bin 38755 -> 0 bytes .../images/sphx_glr_plot_compute_emd_004.png | Bin 38817 -> 0 bytes .../sphx_glr_plot_convolutional_barycenter_001.png | Bin 319137 -> 0 bytes .../auto_examples/images/sphx_glr_plot_fgw_001.png | Bin 44869 -> 0 bytes .../auto_examples/images/sphx_glr_plot_fgw_002.png | Bin 21426 -> 0 bytes .../auto_examples/images/sphx_glr_plot_fgw_003.png | Bin 19362 -> 0 bytes .../auto_examples/images/sphx_glr_plot_fgw_004.png | Bin 19490 -> 0 bytes .../auto_examples/images/sphx_glr_plot_fgw_010.png | Bin 44747 -> 0 bytes .../auto_examples/images/sphx_glr_plot_fgw_011.png | Bin 21337 -> 0 bytes .../sphx_glr_plot_free_support_barycenter_001.png | Bin 32177 -> 0 bytes .../images/sphx_glr_plot_gromov_001.png | Bin 41985 -> 0 bytes .../images/sphx_glr_plot_gromov_002.png | Bin 17032 -> 0 bytes .../images/sphx_glr_plot_gromov_003.png | Bin 18393 -> 0 bytes .../images/sphx_glr_plot_gromov_barycenter_001.png | Bin 53475 -> 0 bytes .../images/sphx_glr_plot_optim_OTreg_001.png | Bin 17109 -> 0 bytes .../images/sphx_glr_plot_optim_OTreg_002.png | Bin 19205 -> 0 bytes .../images/sphx_glr_plot_optim_OTreg_003.png | Bin 19473 -> 0 bytes .../images/sphx_glr_plot_optim_OTreg_004.png | Bin 20573 -> 0 bytes .../images/sphx_glr_plot_optim_OTreg_006.png | Bin 19317 -> 0 bytes .../images/sphx_glr_plot_optim_OTreg_008.png | Bin 20484 -> 0 bytes .../images/sphx_glr_plot_otda_classes_001.png | Bin 50069 -> 0 bytes .../images/sphx_glr_plot_otda_classes_002.png | Bin 204858 -> 0 bytes .../images/sphx_glr_plot_otda_classes_003.png | Bin 207861 -> 0 bytes .../images/sphx_glr_plot_otda_color_images_001.png | Bin 145013 -> 0 bytes .../images/sphx_glr_plot_otda_color_images_002.png | Bin 50471 -> 0 bytes .../images/sphx_glr_plot_otda_color_images_003.png | Bin 458180 -> 0 bytes .../images/sphx_glr_plot_otda_color_images_005.png | Bin 326766 -> 0 bytes .../images/sphx_glr_plot_otda_d2_001.png | Bin 134065 -> 0 bytes .../images/sphx_glr_plot_otda_d2_002.png | Bin 243663 -> 0 bytes .../images/sphx_glr_plot_otda_d2_003.png | Bin 108644 -> 0 bytes .../images/sphx_glr_plot_otda_d2_006.png | Bin 107918 -> 0 bytes .../images/sphx_glr_plot_otda_jcpot_001.png | Bin 32425 -> 0 bytes .../images/sphx_glr_plot_otda_jcpot_002.png | Bin 94074 -> 0 bytes .../images/sphx_glr_plot_otda_jcpot_003.png | Bin 93636 -> 0 bytes .../images/sphx_glr_plot_otda_jcpot_004.png | Bin 90494 -> 0 bytes .../images/sphx_glr_plot_otda_laplacian_001.png | Bin 50923 -> 0 bytes .../images/sphx_glr_plot_otda_laplacian_002.png | Bin 146777 -> 0 bytes .../sphx_glr_plot_otda_linear_mapping_001.png | Bin 29711 -> 0 bytes .../sphx_glr_plot_otda_linear_mapping_002.png | Bin 54817 -> 0 bytes .../sphx_glr_plot_otda_linear_mapping_003.png | Bin 591553 -> 0 bytes .../sphx_glr_plot_otda_linear_mapping_004.png | Bin 591554 -> 0 bytes .../images/sphx_glr_plot_otda_mapping_001.png | Bin 36875 -> 0 bytes .../images/sphx_glr_plot_otda_mapping_002.png | Bin 73185 -> 0 bytes .../images/sphx_glr_plot_otda_mapping_003.png | Bin 76079 -> 0 bytes ...phx_glr_plot_otda_mapping_colors_images_001.png | Bin 232377 -> 0 bytes ...phx_glr_plot_otda_mapping_colors_images_002.png | Bin 80795 -> 0 bytes ...phx_glr_plot_otda_mapping_colors_images_003.png | Bin 659363 -> 0 bytes ...phx_glr_plot_otda_mapping_colors_images_004.png | Bin 512309 -> 0 bytes .../sphx_glr_plot_otda_semi_supervised_001.png | Bin 159065 -> 0 bytes .../sphx_glr_plot_otda_semi_supervised_002.png | Bin 37350 -> 0 bytes .../sphx_glr_plot_otda_semi_supervised_003.png | Bin 80862 -> 0 bytes .../sphx_glr_plot_otda_semi_supervised_006.png | Bin 80769 -> 0 bytes .../sphx_glr_plot_partial_wass_and_gromov_001.png | Bin 24385 -> 0 bytes .../sphx_glr_plot_partial_wass_and_gromov_002.png | Bin 19423 -> 0 bytes .../sphx_glr_plot_partial_wass_and_gromov_003.png | Bin 46197 -> 0 bytes .../sphx_glr_plot_partial_wass_and_gromov_004.png | Bin 19295 -> 0 bytes .../images/sphx_glr_plot_screenkhorn_1D_001.png | Bin 21371 -> 0 bytes .../images/sphx_glr_plot_screenkhorn_1D_002.png | Bin 25480 -> 0 bytes .../images/sphx_glr_plot_screenkhorn_1D_003.png | Bin 20953 -> 0 bytes .../images/sphx_glr_plot_stochastic_001.png | Bin 10398 -> 0 bytes .../images/sphx_glr_plot_stochastic_002.png | Bin 10622 -> 0 bytes .../images/sphx_glr_plot_stochastic_003.png | Bin 9080 -> 0 bytes .../images/sphx_glr_plot_stochastic_004.png | Bin 9497 -> 0 bytes .../images/sphx_glr_plot_stochastic_005.png | Bin 9080 -> 0 bytes .../images/sphx_glr_plot_stochastic_006.png | Bin 9131 -> 0 bytes .../images/sphx_glr_plot_stochastic_007.png | Bin 9483 -> 0 bytes .../images/sphx_glr_plot_stochastic_008.png | Bin 9131 -> 0 bytes .../thumb/sphx_glr_plot_OT_1D_smooth_thumb.png | Bin 16046 -> 0 bytes .../images/thumb/sphx_glr_plot_OT_1D_thumb.png | Bin 16046 -> 0 bytes .../thumb/sphx_glr_plot_OT_2D_samples_thumb.png | Bin 19318 -> 0 bytes .../thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png | Bin 10224 -> 0 bytes .../images/thumb/sphx_glr_plot_UOT_1D_thumb.png | Bin 15788 -> 0 bytes .../sphx_glr_plot_UOT_barycenter_1D_thumb.png | Bin 16507 -> 0 bytes .../images/thumb/sphx_glr_plot_WDA_thumb.png | Bin 86417 -> 0 bytes .../thumb/sphx_glr_plot_barycenter_1D_thumb.png | Bin 15004 -> 0 bytes .../thumb/sphx_glr_plot_barycenter_fgw_thumb.png | Bin 31641 -> 0 bytes ...hx_glr_plot_barycenter_lp_vs_entropic_thumb.png | Bin 15004 -> 0 bytes .../thumb/sphx_glr_plot_compute_emd_thumb.png | Bin 84683 -> 0 bytes ...phx_glr_plot_convolutional_barycenter_thumb.png | Bin 60512 -> 0 bytes .../images/thumb/sphx_glr_plot_fgw_thumb.png | Bin 19980 -> 0 bytes ...sphx_glr_plot_free_support_barycenter_thumb.png | Bin 22634 -> 0 bytes .../sphx_glr_plot_gromov_barycenter_thumb.png | Bin 30143 -> 0 bytes .../images/thumb/sphx_glr_plot_gromov_thumb.png | Bin 26133 -> 0 bytes .../thumb/sphx_glr_plot_optim_OTreg_thumb.png | Bin 12036 -> 0 bytes .../thumb/sphx_glr_plot_otda_classes_thumb.png | Bin 25695 -> 0 bytes .../sphx_glr_plot_otda_color_images_thumb.png | Bin 57671 -> 0 bytes .../images/thumb/sphx_glr_plot_otda_d2_thumb.png | Bin 54161 -> 0 bytes .../thumb/sphx_glr_plot_otda_jcpot_thumb.png | Bin 21964 -> 0 bytes .../thumb/sphx_glr_plot_otda_laplacian_thumb.png | Bin 25970 -> 0 bytes .../sphx_glr_plot_otda_linear_mapping_thumb.png | Bin 23519 -> 0 bytes ...x_glr_plot_otda_mapping_colors_images_thumb.png | Bin 92873 -> 0 bytes .../thumb/sphx_glr_plot_otda_mapping_thumb.png | Bin 17274 -> 0 bytes .../sphx_glr_plot_otda_semi_supervised_thumb.png | Bin 67837 -> 0 bytes ...sphx_glr_plot_partial_wass_and_gromov_thumb.png | Bin 29112 -> 0 bytes .../thumb/sphx_glr_plot_screenkhorn_1D_thumb.png | Bin 16046 -> 0 bytes .../thumb/sphx_glr_plot_stochastic_thumb.png | Bin 8350 -> 0 bytes docs/source/auto_examples/index.rst | 620 --------------------- docs/source/auto_examples/plot_OT_1D.ipynb | 137 ----- docs/source/auto_examples/plot_OT_1D.py | 84 --- docs/source/auto_examples/plot_OT_1D.rst | 228 -------- docs/source/auto_examples/plot_OT_1D_smooth.ipynb | 166 ------ docs/source/auto_examples/plot_OT_1D_smooth.py | 110 ---- docs/source/auto_examples/plot_OT_1D_smooth.rst | 282 ---------- docs/source/auto_examples/plot_OT_2D_samples.ipynb | 144 ----- docs/source/auto_examples/plot_OT_2D_samples.py | 128 ----- docs/source/auto_examples/plot_OT_2D_samples.rst | 310 ----------- docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb | 126 ----- docs/source/auto_examples/plot_OT_L1_vs_L2.py | 208 ------- docs/source/auto_examples/plot_OT_L1_vs_L2.rst | 343 ------------ docs/source/auto_examples/plot_UOT_1D.ipynb | 108 ---- docs/source/auto_examples/plot_UOT_1D.py | 76 --- docs/source/auto_examples/plot_UOT_1D.rst | 177 ------ .../auto_examples/plot_UOT_barycenter_1D.ipynb | 126 ----- .../source/auto_examples/plot_UOT_barycenter_1D.py | 164 ------ .../auto_examples/plot_UOT_barycenter_1D.rst | 299 ---------- docs/source/auto_examples/plot_WDA.ipynb | 144 ----- docs/source/auto_examples/plot_WDA.py | 127 ----- docs/source/auto_examples/plot_WDA.rst | 244 -------- docs/source/auto_examples/plot_barycenter_1D.ipynb | 137 ----- docs/source/auto_examples/plot_barycenter_1D.py | 160 ------ docs/source/auto_examples/plot_barycenter_1D.rst | 280 ---------- .../source/auto_examples/plot_barycenter_fgw.ipynb | 173 ------ docs/source/auto_examples/plot_barycenter_fgw.py | 184 ------ docs/source/auto_examples/plot_barycenter_fgw.rst | 320 ----------- .../plot_barycenter_lp_vs_entropic.ipynb | 192 ------- .../plot_barycenter_lp_vs_entropic.py | 286 ---------- .../plot_barycenter_lp_vs_entropic.rst | 532 ------------------ docs/source/auto_examples/plot_compute_emd.ipynb | 126 ----- docs/source/auto_examples/plot_compute_emd.py | 102 ---- docs/source/auto_examples/plot_compute_emd.rst | 211 ------- .../plot_convolutional_barycenter.ipynb | 90 --- .../auto_examples/plot_convolutional_barycenter.py | 92 --- .../plot_convolutional_barycenter.rst | 173 ------ docs/source/auto_examples/plot_fgw.ipynb | 169 ------ docs/source/auto_examples/plot_fgw.py | 173 ------ docs/source/auto_examples/plot_fgw.rst | 329 ----------- .../plot_free_support_barycenter.ipynb | 108 ---- .../auto_examples/plot_free_support_barycenter.py | 69 --- .../auto_examples/plot_free_support_barycenter.rst | 162 ------ docs/source/auto_examples/plot_gromov.ipynb | 126 ----- docs/source/auto_examples/plot_gromov.py | 106 ---- docs/source/auto_examples/plot_gromov.rst | 245 -------- .../auto_examples/plot_gromov_barycenter.ipynb | 126 ----- .../source/auto_examples/plot_gromov_barycenter.py | 247 -------- .../auto_examples/plot_gromov_barycenter.rst | 349 ------------ docs/source/auto_examples/plot_optim_OTreg.ipynb | 144 ----- docs/source/auto_examples/plot_optim_OTreg.py | 129 ----- docs/source/auto_examples/plot_optim_OTreg.rst | 593 -------------------- docs/source/auto_examples/plot_otda_classes.ipynb | 126 ----- docs/source/auto_examples/plot_otda_classes.py | 149 ----- docs/source/auto_examples/plot_otda_classes.rst | 287 ---------- .../auto_examples/plot_otda_color_images.ipynb | 144 ----- .../source/auto_examples/plot_otda_color_images.py | 164 ------ .../auto_examples/plot_otda_color_images.rst | 291 ---------- docs/source/auto_examples/plot_otda_d2.ipynb | 144 ----- docs/source/auto_examples/plot_otda_d2.py | 172 ------ docs/source/auto_examples/plot_otda_d2.rst | 291 ---------- docs/source/auto_examples/plot_otda_jcpot.ipynb | 173 ------ docs/source/auto_examples/plot_otda_jcpot.py | 171 ------ docs/source/auto_examples/plot_otda_jcpot.rst | 336 ----------- .../source/auto_examples/plot_otda_laplacian.ipynb | 126 ----- docs/source/auto_examples/plot_otda_laplacian.py | 127 ----- docs/source/auto_examples/plot_otda_laplacian.rst | 233 -------- .../auto_examples/plot_otda_linear_mapping.ipynb | 180 ------ .../auto_examples/plot_otda_linear_mapping.py | 144 ----- .../auto_examples/plot_otda_linear_mapping.rst | 295 ---------- docs/source/auto_examples/plot_otda_mapping.ipynb | 126 ----- docs/source/auto_examples/plot_otda_mapping.py | 125 ----- docs/source/auto_examples/plot_otda_mapping.rst | 268 --------- .../plot_otda_mapping_colors_images.ipynb | 144 ----- .../plot_otda_mapping_colors_images.py | 173 ------ .../plot_otda_mapping_colors_images.rst | 334 ----------- .../auto_examples/plot_otda_semi_supervised.ipynb | 144 ----- .../auto_examples/plot_otda_semi_supervised.py | 148 ----- .../auto_examples/plot_otda_semi_supervised.rst | 267 --------- .../plot_partial_wass_and_gromov.ipynb | 126 ----- .../auto_examples/plot_partial_wass_and_gromov.py | 163 ------ .../auto_examples/plot_partial_wass_and_gromov.rst | 312 ----------- .../source/auto_examples/plot_screenkhorn_1D.ipynb | 108 ---- docs/source/auto_examples/plot_screenkhorn_1D.py | 68 --- docs/source/auto_examples/plot_screenkhorn_1D.rst | 178 ------ docs/source/auto_examples/plot_stochastic.ipynb | 295 ---------- docs/source/auto_examples/plot_stochastic.py | 208 ------- docs/source/auto_examples/plot_stochastic.rst | 518 ----------------- docs/source/auto_examples/searchindex | Bin 1892352 -> 0 bytes docs/source/conf.py | 26 +- docs/source/index.md | 1 + docs/source/readme.rst | 61 +- examples/plot_fgw.py | 4 +- requirements.txt | 2 +- 262 files changed, 80 insertions(+), 17787 deletions(-) create mode 100644 docs/requirements_rtd.txt create mode 100644 docs/rtd/conf.py delete mode 100644 docs/source/auto_examples/auto_examples_jupyter.zip delete mode 100644 docs/source/auto_examples/auto_examples_python.zip delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_007.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_007.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_009.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_010.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_009.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_010.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_013.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_014.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_007.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_008.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_009.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_011.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_WDA_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_compute_emd_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_compute_emd_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_compute_emd_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_compute_emd_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_fgw_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_fgw_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_fgw_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_fgw_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_fgw_010.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_fgw_011.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_008.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_classes_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_classes_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_classes_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_d2_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_d2_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_d2_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_d2_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_001.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_002.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_003.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_006.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png delete mode 100644 docs/source/auto_examples/images/sphx_glr_plot_stochastic_008.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_lp_vs_entropic_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png delete mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png delete mode 100644 docs/source/auto_examples/index.rst delete mode 100644 docs/source/auto_examples/plot_OT_1D.ipynb delete mode 100644 docs/source/auto_examples/plot_OT_1D.py delete mode 100644 docs/source/auto_examples/plot_OT_1D.rst delete mode 100644 docs/source/auto_examples/plot_OT_1D_smooth.ipynb delete mode 100644 docs/source/auto_examples/plot_OT_1D_smooth.py delete mode 100644 docs/source/auto_examples/plot_OT_1D_smooth.rst delete mode 100644 docs/source/auto_examples/plot_OT_2D_samples.ipynb delete mode 100644 docs/source/auto_examples/plot_OT_2D_samples.py delete mode 100644 docs/source/auto_examples/plot_OT_2D_samples.rst delete mode 100644 docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb delete mode 100644 docs/source/auto_examples/plot_OT_L1_vs_L2.py delete mode 100644 docs/source/auto_examples/plot_OT_L1_vs_L2.rst delete mode 100644 docs/source/auto_examples/plot_UOT_1D.ipynb delete mode 100644 docs/source/auto_examples/plot_UOT_1D.py delete mode 100644 docs/source/auto_examples/plot_UOT_1D.rst delete mode 100644 docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb delete mode 100644 docs/source/auto_examples/plot_UOT_barycenter_1D.py delete mode 100644 docs/source/auto_examples/plot_UOT_barycenter_1D.rst delete mode 100644 docs/source/auto_examples/plot_WDA.ipynb delete mode 100644 docs/source/auto_examples/plot_WDA.py delete mode 100644 docs/source/auto_examples/plot_WDA.rst delete mode 100644 docs/source/auto_examples/plot_barycenter_1D.ipynb delete mode 100644 docs/source/auto_examples/plot_barycenter_1D.py delete mode 100644 docs/source/auto_examples/plot_barycenter_1D.rst delete mode 100644 docs/source/auto_examples/plot_barycenter_fgw.ipynb delete mode 100644 docs/source/auto_examples/plot_barycenter_fgw.py delete mode 100644 docs/source/auto_examples/plot_barycenter_fgw.rst delete mode 100644 docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb delete mode 100644 docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py delete mode 100644 docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst delete mode 100644 docs/source/auto_examples/plot_compute_emd.ipynb delete mode 100644 docs/source/auto_examples/plot_compute_emd.py delete mode 100644 docs/source/auto_examples/plot_compute_emd.rst delete mode 100644 docs/source/auto_examples/plot_convolutional_barycenter.ipynb delete mode 100644 docs/source/auto_examples/plot_convolutional_barycenter.py delete mode 100644 docs/source/auto_examples/plot_convolutional_barycenter.rst delete mode 100644 docs/source/auto_examples/plot_fgw.ipynb delete mode 100644 docs/source/auto_examples/plot_fgw.py delete mode 100644 docs/source/auto_examples/plot_fgw.rst delete mode 100644 docs/source/auto_examples/plot_free_support_barycenter.ipynb delete mode 100644 docs/source/auto_examples/plot_free_support_barycenter.py delete mode 100644 docs/source/auto_examples/plot_free_support_barycenter.rst delete mode 100644 docs/source/auto_examples/plot_gromov.ipynb delete mode 100644 docs/source/auto_examples/plot_gromov.py delete mode 100644 docs/source/auto_examples/plot_gromov.rst delete mode 100644 docs/source/auto_examples/plot_gromov_barycenter.ipynb delete mode 100644 docs/source/auto_examples/plot_gromov_barycenter.py delete mode 100644 docs/source/auto_examples/plot_gromov_barycenter.rst delete mode 100644 docs/source/auto_examples/plot_optim_OTreg.ipynb delete mode 100644 docs/source/auto_examples/plot_optim_OTreg.py delete mode 100644 docs/source/auto_examples/plot_optim_OTreg.rst delete mode 100644 docs/source/auto_examples/plot_otda_classes.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_classes.py delete mode 100644 docs/source/auto_examples/plot_otda_classes.rst delete mode 100644 docs/source/auto_examples/plot_otda_color_images.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_color_images.py delete mode 100644 docs/source/auto_examples/plot_otda_color_images.rst delete mode 100644 docs/source/auto_examples/plot_otda_d2.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_d2.py delete mode 100644 docs/source/auto_examples/plot_otda_d2.rst delete mode 100644 docs/source/auto_examples/plot_otda_jcpot.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_jcpot.py delete mode 100644 docs/source/auto_examples/plot_otda_jcpot.rst delete mode 100644 docs/source/auto_examples/plot_otda_laplacian.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_laplacian.py delete mode 100644 docs/source/auto_examples/plot_otda_laplacian.rst delete mode 100644 docs/source/auto_examples/plot_otda_linear_mapping.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_linear_mapping.py delete mode 100644 docs/source/auto_examples/plot_otda_linear_mapping.rst delete mode 100644 docs/source/auto_examples/plot_otda_mapping.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_mapping.py delete mode 100644 docs/source/auto_examples/plot_otda_mapping.rst delete mode 100644 docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_mapping_colors_images.py delete mode 100644 docs/source/auto_examples/plot_otda_mapping_colors_images.rst delete mode 100644 docs/source/auto_examples/plot_otda_semi_supervised.ipynb delete mode 100644 docs/source/auto_examples/plot_otda_semi_supervised.py delete mode 100644 docs/source/auto_examples/plot_otda_semi_supervised.rst delete mode 100644 docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb delete mode 100644 docs/source/auto_examples/plot_partial_wass_and_gromov.py delete mode 100644 docs/source/auto_examples/plot_partial_wass_and_gromov.rst delete mode 100644 docs/source/auto_examples/plot_screenkhorn_1D.ipynb delete mode 100644 docs/source/auto_examples/plot_screenkhorn_1D.py delete mode 100644 docs/source/auto_examples/plot_screenkhorn_1D.rst delete mode 100644 docs/source/auto_examples/plot_stochastic.ipynb delete mode 100644 docs/source/auto_examples/plot_stochastic.py delete mode 100644 docs/source/auto_examples/plot_stochastic.rst delete mode 100644 docs/source/auto_examples/searchindex create mode 100644 docs/source/index.md (limited to 'docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png') diff --git a/README.md b/README.md index 65193ff..40f43e0 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,18 @@ [![Build Status](https://travis-ci.org/PythonOT/POT.svg?branch=master)](https://travis-ci.org/PythonOT/POT) [![Build Status](https://github.com/PythonOT/POT/workflows/Linux%7CWin%7CMacOS/badge.svg)](https://github.com/PythonOT/POT/actions) [![Codecov Status](https://codecov.io/gh/PythonOT/POT/branch/master/graph/badge.svg)](https://codecov.io/gh/PythonOT/POT) -[![Documentation Status](https://readthedocs.org/projects/pot/badge/?version=latest)](http://pot.readthedocs.io/en/latest/?badge=latest) [![Downloads](https://pepy.tech/badge/pot)](https://pepy.tech/project/pot) [![Anaconda downloads](https://anaconda.org/conda-forge/pot/badges/downloads.svg)](https://anaconda.org/conda-forge/pot) [![License](https://anaconda.org/conda-forge/pot/badges/license.svg)](https://github.com/PythonOT/POT/blob/master/LICENSE) +This open source Python library provide several solvers for optimization +problems related to Optimal Transport for signal, image processing and machine +learning. -This open source Python library provide several solvers for optimization problems related to Optimal Transport for signal, image processing and machine learning. +Website and documentation: [https://PythonOT.github.io/](https://PythonOT.github.io/) -It provides the following solvers: +POT provides the following solvers: * OT Network Flow solver for the linear program/ Earth Movers Distance [1]. * Entropic regularization OT solver with Sinkhorn Knopp Algorithm [2], stabilized version [9][10] and greedy Sinkhorn [22] with optional GPU implementation (requires cupy). @@ -139,7 +141,7 @@ ba=ot.barycenter(A,M,reg) # reg is regularization parameter ### Examples and Notebooks -The examples folder contain several examples and use case for the library. The full documentation is available on [Readthedocs](http://pot.readthedocs.io/). +The examples folder contain several examples and use case for the library. The full documentation is available on [https://PythonOT.github.io/](https://PythonOT.github.io/). Here is a list of the Python notebooks available [here](https://github.com/PythonOT/POT/blob/master/notebooks/) if you want a quick look: diff --git a/docs/requirements.txt b/docs/requirements.txt index 1fe37c2..256706b 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ sphinx_rtd_theme numpydoc memory_profiler pillow +networkx diff --git a/docs/requirements_rtd.txt b/docs/requirements_rtd.txt new file mode 100644 index 0000000..e3999d6 --- /dev/null +++ b/docs/requirements_rtd.txt @@ -0,0 +1,14 @@ +sphinx_gallery +numpydoc +memory_profiler +pillow +networkx +numpy +scipy>=1.0 +cython +matplotlib +autograd +pymanopt==0.2.4; python_version <'3' +pymanopt; python_version >= '3' +cvxopt +scikit-learn \ No newline at end of file diff --git a/docs/rtd/conf.py b/docs/rtd/conf.py new file mode 100644 index 0000000..814db75 --- /dev/null +++ b/docs/rtd/conf.py @@ -0,0 +1,6 @@ +from recommonmark.parser import CommonMarkParser + +source_parsers = {'.md': CommonMarkParser} + +source_suffix = ['.md'] +master_doc = 'index' \ 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 deleted file mode 100644 index 069a0f3..0000000 Binary files a/docs/source/auto_examples/auto_examples_jupyter.zip and /dev/null differ diff --git a/docs/source/auto_examples/auto_examples_python.zip b/docs/source/auto_examples/auto_examples_python.zip deleted file mode 100644 index e04aed4..0000000 Binary files a/docs/source/auto_examples/auto_examples_python.zip and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_001.png deleted file mode 100644 index 2c35176..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_002.png deleted file mode 100644 index dc58146..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_003.png deleted file mode 100644 index 1824cba..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_004.png deleted file mode 100644 index 7a9d992..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_005.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_005.png deleted file mode 100644 index 4421bc7..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_007.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_007.png deleted file mode 100644 index 2dbe49b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_007.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png deleted file mode 100644 index 2c35176..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png deleted file mode 100644 index dc58146..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png deleted file mode 100644 index 1824cba..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png deleted file mode 100644 index 46c9bb5..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png deleted file mode 100644 index aed496a..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png deleted file mode 100644 index 91cf3e4..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_007.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_007.png deleted file mode 100644 index 52638e3..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_007.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_009.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_009.png deleted file mode 100644 index c5078cf..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_009.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_010.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_010.png deleted file mode 100644 index 58e87b6..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_010.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png deleted file mode 100644 index b7d6c32..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png deleted file mode 100644 index dbd52b1..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png deleted file mode 100644 index 31fb585..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png deleted file mode 100644 index 5a50fc4..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png deleted file mode 100644 index dfb32cc..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png deleted file mode 100644 index 9a6db51..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png deleted file mode 100644 index 8e8c275..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png deleted file mode 100644 index 3fadb99..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_009.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_009.png deleted file mode 100644 index 56d18ef..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_009.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_010.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_010.png deleted file mode 100644 index 5aef7d2..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_010.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_013.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_013.png deleted file mode 100644 index bb8bd7c..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_013.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_014.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_014.png deleted file mode 100644 index 30cec7b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_014.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_001.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_001.png deleted file mode 100644 index b8d1b71..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_002.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_002.png deleted file mode 100644 index f066922..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png deleted file mode 100644 index 2d0be7d..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png deleted file mode 100644 index 5fc1700..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.png deleted file mode 100644 index 05f7c93..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png deleted file mode 100644 index e95653e..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_007.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_007.png deleted file mode 100644 index 6e6f3b9..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_007.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_008.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_008.png deleted file mode 100644 index 007d246..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_008.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_009.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_009.png deleted file mode 100644 index e1e9ba8..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_009.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_011.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_011.png deleted file mode 100644 index 75ef929..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_011.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png deleted file mode 100644 index 1569ea7..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png deleted file mode 100644 index dc58146..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_003.png deleted file mode 100644 index 1e9af5a..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_006.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_006.png deleted file mode 100644 index f58d383..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png deleted file mode 100644 index 7b651ca..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png deleted file mode 100644 index 08cda47..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png deleted file mode 100644 index aef4700..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png deleted file mode 100644 index a785125..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_005.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_005.png deleted file mode 100644 index c6c49cb..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_006.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_006.png deleted file mode 100644 index 8870b10..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png b/docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png deleted file mode 100644 index 3524e19..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_WDA_003.png b/docs/source/auto_examples/images/sphx_glr_plot_WDA_003.png deleted file mode 100644 index 819b974..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_WDA_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_001.png deleted file mode 100644 index 7165659..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_002.png deleted file mode 100644 index 82e7364..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_003.png deleted file mode 100644 index f2a8fd3..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_004.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_004.png deleted file mode 100644 index 5d52b39..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_005.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_005.png deleted file mode 100644 index 81cee52..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_006.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_006.png deleted file mode 100644 index bfa0873..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png deleted file mode 100644 index 8e2892d..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png deleted file mode 100644 index 16304ef..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png deleted file mode 100644 index 7165659..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png deleted file mode 100644 index c244118..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png deleted file mode 100644 index 542ed69..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png deleted file mode 100644 index e44f5e7..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png deleted file mode 100644 index beb300b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png deleted file mode 100644 index 7463619..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png deleted file mode 100644 index 388a0d6..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_001.png b/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_001.png deleted file mode 100644 index 819177c..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_002.png b/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_002.png deleted file mode 100644 index b518db1..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_003.png b/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_003.png deleted file mode 100644 index 7412ef2..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_004.png b/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_004.png deleted file mode 100644 index 9ef7182..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png b/docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png deleted file mode 100644 index a59b773..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_001.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_001.png deleted file mode 100644 index 300d04a..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_fgw_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_002.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_002.png deleted file mode 100644 index 5f95d4a..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_fgw_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_003.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_003.png deleted file mode 100644 index 378e4f7..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_fgw_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_004.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_004.png deleted file mode 100644 index 4e0df9f..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_fgw_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_010.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_010.png deleted file mode 100644 index d0e36e8..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_fgw_010.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_011.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_011.png deleted file mode 100644 index 6d7e630..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_fgw_011.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png b/docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png deleted file mode 100644 index f6b72b5..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png deleted file mode 100644 index 4923bca..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png deleted file mode 100644 index 1bd0a87..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png deleted file mode 100644 index e898b0b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png deleted file mode 100644 index d54a124..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_001.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_001.png deleted file mode 100644 index 1824cba..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_002.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_002.png deleted file mode 100644 index 2d9e678..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png deleted file mode 100644 index 385fca9..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png deleted file mode 100644 index e98de9b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_006.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_006.png deleted file mode 100644 index afca192..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_008.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_008.png deleted file mode 100644 index daa2a8d..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_008.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_001.png deleted file mode 100644 index 64695a2..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_002.png deleted file mode 100644 index 63f3b59..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_003.png deleted file mode 100644 index 3c33d5b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png deleted file mode 100644 index 51c07f9..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_002.png deleted file mode 100644 index 8f579ac..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png deleted file mode 100644 index 51350f5..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png deleted file mode 100644 index 5b8101b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_001.png deleted file mode 100644 index e57780b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_002.png deleted file mode 100644 index 77cbd69..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_003.png deleted file mode 100644 index e33595c..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_006.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_006.png deleted file mode 100644 index 7385dcc..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_001.png deleted file mode 100644 index af64f21..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_002.png deleted file mode 100644 index 5334792..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_003.png deleted file mode 100644 index ba8ad9d..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_004.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_004.png deleted file mode 100644 index ea921e2..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_004.png and /dev/null 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 deleted file mode 100644 index 66ef851..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png and /dev/null 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 deleted file mode 100644 index f9a4959..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.png deleted file mode 100644 index d889c54..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.png deleted file mode 100644 index 4b2328d..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png deleted file mode 100644 index fd662b3..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_004.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_004.png deleted file mode 100644 index ff10b72..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_001.png deleted file mode 100644 index 61c4a7e..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_002.png deleted file mode 100644 index a329e4f..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_003.png deleted file mode 100644 index 02fe3d6..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png deleted file mode 100644 index 9999531..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png deleted file mode 100644 index 057b586..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png deleted file mode 100644 index f82fddf..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png deleted file mode 100644 index 1c73e43..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_001.png deleted file mode 100644 index fd16c39..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png deleted file mode 100644 index 36518f7..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.png deleted file mode 100644 index 6679ace..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_006.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_006.png deleted file mode 100644 index 2b3bf0e..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_006.png and /dev/null 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 deleted file mode 100644 index f944550..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png and /dev/null 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 deleted file mode 100644 index 45542c1..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png and /dev/null 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 deleted file mode 100644 index 83e0d41..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png and /dev/null 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 deleted file mode 100644 index a1ba204..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png deleted file mode 100644 index 2c35176..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png deleted file mode 100644 index dc58146..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png deleted file mode 100644 index 21be620..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_001.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_001.png deleted file mode 100644 index 0fc47ab..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_001.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_002.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_002.png deleted file mode 100644 index 7909f19..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_002.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_003.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_003.png deleted file mode 100644 index 23a0674..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_003.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png deleted file mode 100644 index 1db9eda..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png deleted file mode 100644 index 23a0674..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_006.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_006.png deleted file mode 100644 index 335ea95..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_006.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png deleted file mode 100644 index cda643b..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png and /dev/null differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_008.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_008.png deleted file mode 100644 index 335ea95..0000000 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_008.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png deleted file mode 100644 index c73b639..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.png deleted file mode 100644 index c73b639..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png deleted file mode 100644 index 1986d18..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png deleted file mode 100644 index cf31a53..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png deleted file mode 100644 index ee3710f..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png deleted file mode 100644 index 7a4e6b4..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png deleted file mode 100644 index 2316fcc..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png deleted file mode 100644 index 9568037..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png deleted file mode 100644 index 1b6eeaf..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_lp_vs_entropic_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_lp_vs_entropic_thumb.png deleted file mode 100644 index 9568037..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_lp_vs_entropic_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png deleted file mode 100644 index 7501527..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png deleted file mode 100644 index 219d52a..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png deleted file mode 100644 index b64a0fe..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png deleted file mode 100644 index b0d9597..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png deleted file mode 100644 index 2f3e81a..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png deleted file mode 100644 index 7881fae..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png deleted file mode 100644 index f6079d6..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.png deleted file mode 100644 index 9e9c272..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png deleted file mode 100644 index 51d64b7..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.png deleted file mode 100644 index 748d62c..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png deleted file mode 100644 index 1e05241..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png and /dev/null 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 deleted file mode 100644 index db37d2b..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png deleted file mode 100644 index 1a92904..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png deleted file mode 100644 index 81a8066..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png deleted file mode 100644 index 2c0ddb1..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.png deleted file mode 100644 index e1e2f7c..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.png and /dev/null 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 deleted file mode 100644 index 0f630f1..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png deleted file mode 100644 index c73b639..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png deleted file mode 100644 index 9e308d2..0000000 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png and /dev/null differ diff --git a/docs/source/auto_examples/index.rst b/docs/source/auto_examples/index.rst deleted file mode 100644 index 9f05263..0000000 --- a/docs/source/auto_examples/index.rst +++ /dev/null @@ -1,620 +0,0 @@ -:orphan: - - - -.. _sphx_glr_auto_examples: - -POT Examples -============ - -This is a gallery of all the POT example files. - - - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.png - - :ref:`sphx_glr_auto_examples_plot_OT_1D.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_OT_1D - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png - - :ref:`sphx_glr_auto_examples_plot_UOT_1D.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_UOT_1D - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png - - :ref:`sphx_glr_auto_examples_plot_screenkhorn_1D.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_screenkhorn_1D - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png - - :ref:`sphx_glr_auto_examples_plot_optim_OTreg.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_optim_OTreg - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png - - :ref:`sphx_glr_auto_examples_plot_OT_1D_smooth.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_OT_1D_smooth - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png - - :ref:`sphx_glr_auto_examples_plot_free_support_barycenter.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_free_support_barycenter - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png - - :ref:`sphx_glr_auto_examples_plot_compute_emd.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_compute_emd - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png - - :ref:`sphx_glr_auto_examples_plot_gromov.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_gromov - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png - - :ref:`sphx_glr_auto_examples_plot_convolutional_barycenter.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_convolutional_barycenter - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_linear_mapping.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_linear_mapping - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png - - :ref:`sphx_glr_auto_examples_plot_OT_2D_samples.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_OT_2D_samples - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png - - :ref:`sphx_glr_auto_examples_plot_WDA.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_WDA - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png - - :ref:`sphx_glr_auto_examples_plot_stochastic.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_stochastic - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_color_images.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_color_images - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png - - :ref:`sphx_glr_auto_examples_plot_barycenter_1D.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_barycenter_1D - -.. raw:: html - -
- -.. 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 - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_laplacian - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_mapping_colors_images.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_mapping_colors_images - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png - - :ref:`sphx_glr_auto_examples_plot_UOT_barycenter_1D.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_UOT_barycenter_1D - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_mapping.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_mapping - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png - - :ref:`sphx_glr_auto_examples_plot_fgw.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_fgw - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_semi_supervised.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_semi_supervised - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_classes.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_classes - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png - - :ref:`sphx_glr_auto_examples_plot_partial_wass_and_gromov.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_partial_wass_and_gromov - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_d2.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_d2 - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png - - :ref:`sphx_glr_auto_examples_plot_OT_L1_vs_L2.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_OT_L1_vs_L2 - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png - - :ref:`sphx_glr_auto_examples_plot_otda_jcpot.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_otda_jcpot - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_lp_vs_entropic_thumb.png - - :ref:`sphx_glr_auto_examples_plot_barycenter_lp_vs_entropic.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_barycenter_lp_vs_entropic - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png - - :ref:`sphx_glr_auto_examples_plot_barycenter_fgw.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_barycenter_fgw - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png - - :ref:`sphx_glr_auto_examples_plot_gromov_barycenter.py` - -.. raw:: html - -
- - -.. toctree:: - :hidden: - - /auto_examples/plot_gromov_barycenter -.. raw:: html - -
- - - -.. only :: html - - .. container:: sphx-glr-footer - :class: sphx-glr-footer-gallery - - - .. container:: sphx-glr-download sphx-glr-download-python - - :download:`Download all examples in Python source code: auto_examples_python.zip ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download all examples in Jupyter notebooks: auto_examples_jupyter.zip ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_OT_1D.ipynb b/docs/source/auto_examples/plot_OT_1D.ipynb deleted file mode 100644 index f679a30..0000000 --- a/docs/source/auto_examples/plot_OT_1D.ipynb +++ /dev/null @@ -1,137 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 1D optimal transport\n\n\nThis example illustrates the computation of EMD and Sinkhorn transport plans\nand their visualization.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot\nfrom ot.datasets import make_1D_gauss as gauss" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot distributions and loss matrix\n----------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve EMD\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "G0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve Sinkhorn\n--------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "lambd = 1e-3\nGs = ot.sinkhorn(a, b, M, lambd, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn')\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_OT_1D.py b/docs/source/auto_examples/plot_OT_1D.py deleted file mode 100644 index f33e2a4..0000000 --- a/docs/source/auto_examples/plot_OT_1D.py +++ /dev/null @@ -1,84 +0,0 @@ -# -*- coding: utf-8 -*- -""" -==================== -1D optimal transport -==================== - -This example illustrates the computation of EMD and Sinkhorn transport plans -and their visualization. - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -import ot.plot -from ot.datasets import make_1D_gauss as gauss - -############################################################################## -# Generate data -# ------------- - - -#%% parameters - -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() - - -############################################################################## -# Plot distributions and loss matrix -# ---------------------------------- - -#%% plot the distributions - -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') - -############################################################################## -# Solve EMD -# --------- - - -#%% EMD - -G0 = ot.emd(a, b, M) - -pl.figure(3, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') - -############################################################################## -# Solve Sinkhorn -# -------------- - - -#%% Sinkhorn - -lambd = 1e-3 -Gs = ot.sinkhorn(a, b, M, lambd, verbose=True) - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn') - -pl.show() diff --git a/docs/source/auto_examples/plot_OT_1D.rst b/docs/source/auto_examples/plot_OT_1D.rst deleted file mode 100644 index ec21845..0000000 --- a/docs/source/auto_examples/plot_OT_1D.rst +++ /dev/null @@ -1,228 +0,0 @@ -.. 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_OT_1D.py: - - -==================== -1D optimal transport -==================== - -This example illustrates the computation of EMD and Sinkhorn transport plans -and their visualization. - - - -.. code-block:: default - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - import ot.plot - from ot.datasets import make_1D_gauss as gauss - - - - - - - - -Generate data -------------- - - -.. 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() - - - - - - - - - -Plot distributions and loss matrix ----------------------------------- - - -.. 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() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - - - - - -.. code-block:: default - - - pl.figure(2, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_002.png - :class: sphx-glr-single-img - - - - - -Solve EMD ---------- - - -.. code-block:: default - - - G0 = ot.emd(a, b, M) - - pl.figure(3, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_003.png - :class: sphx-glr-single-img - - - - - -Solve Sinkhorn --------------- - - -.. code-block:: default - - - lambd = 1e-3 - Gs = ot.sinkhorn(a, b, M, lambd, verbose=True) - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn') - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_004.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Err - ------------------- - 0|2.861463e-01| - 10|1.860154e-01| - 20|8.144529e-02| - 30|3.130143e-02| - 40|1.178815e-02| - 50|4.426078e-03| - 60|1.661047e-03| - 70|6.233110e-04| - 80|2.338932e-04| - 90|8.776627e-05| - 100|3.293340e-05| - 110|1.235791e-05| - 120|4.637176e-06| - 130|1.740051e-06| - 140|6.529356e-07| - 150|2.450071e-07| - 160|9.193632e-08| - 170|3.449812e-08| - 180|1.294505e-08| - 190|4.857493e-09| - It. |Err - ------------------- - 200|1.822723e-09| - 210|6.839572e-10| - /home/rflamary/PYTHON/POT/examples/plot_OT_1D.py:84: 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 0.665 seconds) - - -.. _sphx_glr_download_auto_examples_plot_OT_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_OT_1D.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_OT_1D.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_OT_1D_smooth.ipynb b/docs/source/auto_examples/plot_OT_1D_smooth.ipynb deleted file mode 100644 index 493e6bb..0000000 --- a/docs/source/auto_examples/plot_OT_1D_smooth.ipynb +++ /dev/null @@ -1,166 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 1D smooth optimal transport\n\n\nThis example illustrates the computation of EMD, Sinkhorn and smooth OT plans\nand their visualization.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot\nfrom ot.datasets import make_1D_gauss as gauss" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot distributions and loss matrix\n----------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve EMD\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "G0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve Sinkhorn\n--------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "lambd = 2e-3\nGs = ot.sinkhorn(a, b, M, lambd, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn')\n\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve Smooth OT\n--------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "lambd = 2e-3\nGsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='kl')\n\npl.figure(5, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT KL reg.')\n\npl.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "lambd = 1e-1\nGsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='l2')\n\npl.figure(6, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT l2 reg.')\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_OT_1D_smooth.py b/docs/source/auto_examples/plot_OT_1D_smooth.py deleted file mode 100644 index b690751..0000000 --- a/docs/source/auto_examples/plot_OT_1D_smooth.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: utf-8 -*- -""" -=========================== -1D smooth optimal transport -=========================== - -This example illustrates the computation of EMD, Sinkhorn and smooth OT plans -and their visualization. - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -import ot.plot -from ot.datasets import make_1D_gauss as gauss - -############################################################################## -# Generate data -# ------------- - - -#%% parameters - -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() - - -############################################################################## -# Plot distributions and loss matrix -# ---------------------------------- - -#%% plot the distributions - -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') - -############################################################################## -# Solve EMD -# --------- - - -#%% EMD - -G0 = ot.emd(a, b, M) - -pl.figure(3, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') - -############################################################################## -# Solve Sinkhorn -# -------------- - - -#%% Sinkhorn - -lambd = 2e-3 -Gs = ot.sinkhorn(a, b, M, lambd, verbose=True) - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn') - -pl.show() - -############################################################################## -# Solve Smooth OT -# -------------- - - -#%% Smooth OT with KL regularization - -lambd = 2e-3 -Gsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='kl') - -pl.figure(5, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT KL reg.') - -pl.show() - - -#%% Smooth OT with KL regularization - -lambd = 1e-1 -Gsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='l2') - -pl.figure(6, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT l2 reg.') - -pl.show() diff --git a/docs/source/auto_examples/plot_OT_1D_smooth.rst b/docs/source/auto_examples/plot_OT_1D_smooth.rst deleted file mode 100644 index de42689..0000000 --- a/docs/source/auto_examples/plot_OT_1D_smooth.rst +++ /dev/null @@ -1,282 +0,0 @@ -.. 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_OT_1D_smooth.py: - - -=========================== -1D smooth optimal transport -=========================== - -This example illustrates the computation of EMD, Sinkhorn and smooth OT plans -and their visualization. - - - -.. code-block:: default - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - import ot.plot - from ot.datasets import make_1D_gauss as gauss - - - - - - - - -Generate data -------------- - - -.. 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() - - - - - - - - - -Plot distributions and loss matrix ----------------------------------- - - -.. 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() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - - - - - -.. code-block:: default - - - pl.figure(2, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png - :class: sphx-glr-single-img - - - - - -Solve EMD ---------- - - -.. code-block:: default - - - G0 = ot.emd(a, b, M) - - pl.figure(3, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png - :class: sphx-glr-single-img - - - - - -Solve Sinkhorn --------------- - - -.. code-block:: default - - - lambd = 2e-3 - Gs = ot.sinkhorn(a, b, M, lambd, verbose=True) - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn') - - pl.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Err - ------------------- - 0|2.821142e-01| - 10|7.695268e-02| - 20|1.112774e-02| - 30|1.571553e-03| - 40|2.218100e-04| - 50|3.130527e-05| - 60|4.418267e-06| - 70|6.235716e-07| - 80|8.800770e-08| - 90|1.242095e-08| - 100|1.753030e-09| - 110|2.474136e-10| - /home/rflamary/PYTHON/POT/examples/plot_OT_1D_smooth.py:84: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Solve Smooth OT --------------- - - -.. code-block:: default - - - lambd = 2e-3 - Gsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='kl') - - pl.figure(5, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT KL reg.') - - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_OT_1D_smooth.py:99: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - - -.. code-block:: default - - - lambd = 1e-1 - Gsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='l2') - - pl.figure(6, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT l2 reg.') - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_OT_1D_smooth.py:110: 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 0.732 seconds) - - -.. _sphx_glr_download_auto_examples_plot_OT_1D_smooth.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_OT_1D_smooth.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_OT_1D_smooth.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_OT_2D_samples.ipynb b/docs/source/auto_examples/plot_OT_2D_samples.ipynb deleted file mode 100644 index ff7abde..0000000 --- a/docs/source/auto_examples/plot_OT_2D_samples.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 2D Optimal transport between empirical distributions\n\n\nIllustration of 2D optimal transport between discributions that are weighted\nsum of diracs. The OT matrix is plotted with the samples.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n# Kilian Fatras \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 50 # nb samples\n\nmu_s = np.array([0, 0])\ncov_s = np.array([[1, 0], [0, 1]])\n\nmu_t = np.array([4, 4])\ncov_t = np.array([[1, -.8], [-.8, 1]])\n\nxs = ot.datasets.make_2D_samples_gauss(n, mu_s, cov_s)\nxt = ot.datasets.make_2D_samples_gauss(n, mu_t, cov_t)\n\na, b = np.ones((n,)) / n, np.ones((n,)) / n # uniform distribution on samples\n\n# loss matrix\nM = ot.dist(xs, xt)\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "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')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute EMD\n-----------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "G0 = ot.emd(a, b, M)\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=[.5, .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')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute Sinkhorn\n----------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# reg term\nlambd = 1e-3\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=[.5, .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()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Emprirical Sinkhorn\n----------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# reg term\nlambd = 1e-3\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=[.5, .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()" - ] - } - ], - "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_OT_2D_samples.py b/docs/source/auto_examples/plot_OT_2D_samples.py deleted file mode 100644 index 63126ba..0000000 --- a/docs/source/auto_examples/plot_OT_2D_samples.py +++ /dev/null @@ -1,128 +0,0 @@ -# -*- coding: utf-8 -*- -""" -==================================================== -2D Optimal transport between empirical distributions -==================================================== - -Illustration of 2D optimal transport between discributions that are weighted -sum of diracs. The OT matrix is plotted with the samples. - -""" - -# Author: Remi Flamary -# Kilian Fatras -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -import ot.plot - -############################################################################## -# Generate data -# ------------- - -#%% parameters and data generation - -n = 50 # nb samples - -mu_s = np.array([0, 0]) -cov_s = np.array([[1, 0], [0, 1]]) - -mu_t = np.array([4, 4]) -cov_t = np.array([[1, -.8], [-.8, 1]]) - -xs = ot.datasets.make_2D_samples_gauss(n, mu_s, cov_s) -xt = ot.datasets.make_2D_samples_gauss(n, mu_t, cov_t) - -a, b = np.ones((n,)) / n, np.ones((n,)) / n # uniform distribution on samples - -# loss matrix -M = ot.dist(xs, xt) -M /= M.max() - -############################################################################## -# Plot data -# --------- - -#%% plot samples - -pl.figure(1) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.legend(loc=0) -pl.title('Source and target distributions') - -pl.figure(2) -pl.imshow(M, interpolation='nearest') -pl.title('Cost matrix M') - -############################################################################## -# Compute EMD -# ----------- - -#%% EMD - -G0 = ot.emd(a, b, M) - -pl.figure(3) -pl.imshow(G0, interpolation='nearest') -pl.title('OT matrix G0') - -pl.figure(4) -ot.plot.plot2D_samples_mat(xs, xt, G0, c=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.legend(loc=0) -pl.title('OT matrix with samples') - - -############################################################################## -# Compute Sinkhorn -# ---------------- - -#%% sinkhorn - -# reg term -lambd = 1e-3 - -Gs = ot.sinkhorn(a, b, M, lambd) - -pl.figure(5) -pl.imshow(Gs, interpolation='nearest') -pl.title('OT matrix sinkhorn') - -pl.figure(6) -ot.plot.plot2D_samples_mat(xs, xt, Gs, color=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.legend(loc=0) -pl.title('OT matrix Sinkhorn with samples') - -pl.show() - - -############################################################################## -# Emprirical Sinkhorn -# ---------------- - -#%% sinkhorn - -# reg term -lambd = 1e-3 - -Ges = ot.bregman.empirical_sinkhorn(xs, xt, lambd) - -pl.figure(7) -pl.imshow(Ges, interpolation='nearest') -pl.title('OT matrix empirical sinkhorn') - -pl.figure(8) -ot.plot.plot2D_samples_mat(xs, xt, Ges, color=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.legend(loc=0) -pl.title('OT matrix Sinkhorn from samples') - -pl.show() diff --git a/docs/source/auto_examples/plot_OT_2D_samples.rst b/docs/source/auto_examples/plot_OT_2D_samples.rst deleted file mode 100644 index 460bb95..0000000 --- a/docs/source/auto_examples/plot_OT_2D_samples.rst +++ /dev/null @@ -1,310 +0,0 @@ -.. 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_OT_2D_samples.py: - - -==================================================== -2D Optimal transport between empirical distributions -==================================================== - -Illustration of 2D optimal transport between discributions that are weighted -sum of diracs. The OT matrix is plotted with the samples. - - - -.. code-block:: default - - - # Author: Remi Flamary - # Kilian Fatras - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - import ot.plot - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - n = 50 # nb samples - - mu_s = np.array([0, 0]) - cov_s = np.array([[1, 0], [0, 1]]) - - mu_t = np.array([4, 4]) - cov_t = np.array([[1, -.8], [-.8, 1]]) - - xs = ot.datasets.make_2D_samples_gauss(n, mu_s, cov_s) - xt = ot.datasets.make_2D_samples_gauss(n, mu_t, cov_t) - - a, b = np.ones((n,)) / n, np.ones((n,)) / n # uniform distribution on samples - - # loss matrix - M = ot.dist(xs, xt) - M /= M.max() - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - pl.figure(1) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.legend(loc=0) - pl.title('Source and target distributions') - - pl.figure(2) - pl.imshow(M, interpolation='nearest') - pl.title('Cost matrix M') - - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png - :class: sphx-glr-multi-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - Text(0.5, 1.0, 'Cost matrix M') - - - -Compute EMD ------------ - - -.. code-block:: default - - - G0 = ot.emd(a, b, M) - - pl.figure(3) - pl.imshow(G0, interpolation='nearest') - pl.title('OT matrix G0') - - pl.figure(4) - ot.plot.plot2D_samples_mat(xs, xt, G0, c=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.legend(loc=0) - pl.title('OT matrix with samples') - - - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png - :class: sphx-glr-multi-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - Text(0.5, 1.0, 'OT matrix with samples') - - - -Compute Sinkhorn ----------------- - - -.. code-block:: default - - - # reg term - lambd = 1e-3 - - Gs = ot.sinkhorn(a, b, M, lambd) - - pl.figure(5) - pl.imshow(Gs, interpolation='nearest') - pl.title('OT matrix sinkhorn') - - pl.figure(6) - ot.plot.plot2D_samples_mat(xs, xt, Gs, color=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.legend(loc=0) - pl.title('OT matrix Sinkhorn with samples') - - pl.show() - - - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png - :class: sphx-glr-multi-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_OT_2D_samples.py:103: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Emprirical Sinkhorn ----------------- - - -.. code-block:: default - - - # reg term - lambd = 1e-3 - - Ges = ot.bregman.empirical_sinkhorn(xs, xt, lambd) - - pl.figure(7) - pl.imshow(Ges, interpolation='nearest') - pl.title('OT matrix empirical sinkhorn') - - pl.figure(8) - ot.plot.plot2D_samples_mat(xs, xt, Ges, color=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.legend(loc=0) - pl.title('OT matrix Sinkhorn from samples') - - pl.show() - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png - :class: sphx-glr-multi-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/ot/bregman.py:363: RuntimeWarning: divide by zero encountered in true_divide - v = np.divide(b, KtransposeU) - Warning: numerical errors at iteration 0 - /home/rflamary/PYTHON/POT/ot/plot.py:90: RuntimeWarning: invalid value encountered in double_scalars - if G[i, j] / mx > thr: - /home/rflamary/PYTHON/POT/examples/plot_OT_2D_samples.py:128: 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 2.154 seconds) - - -.. _sphx_glr_download_auto_examples_plot_OT_2D_samples.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_OT_2D_samples.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_OT_2D_samples.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb b/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb deleted file mode 100644 index 12a09f0..0000000 --- a/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 2D Optimal transport for different metrics\n\n\n2D OT on empirical distributio with different gound metric.\n\nStole the figure idea from Fig. 1 and 2 in\nhttps://arxiv.org/pdf/1706.07650.pdf\n\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Dataset 1 : uniform sampling\n----------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 20 # nb samples\nxs = np.zeros((n, 2))\nxs[:, 0] = np.arange(n) + 1\nxs[:, 1] = (np.arange(n) + 1) * -0.001 # to make it strictly convex...\n\nxt = np.zeros((n, 2))\nxt[:, 1] = np.arange(n) + 1\n\na, b = ot.unif(n), ot.unif(n) # uniform distribution on samples\n\n# loss matrix\nM1 = ot.dist(xs, xt, metric='euclidean')\nM1 /= M1.max()\n\n# loss matrix\nM2 = ot.dist(xs, xt, metric='sqeuclidean')\nM2 /= M2.max()\n\n# loss matrix\nMp = np.sqrt(ot.dist(xs, xt, metric='euclidean'))\nMp /= Mp.max()\n\n# Data\npl.figure(1, figsize=(7, 3))\npl.clf()\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\npl.title('Source and target distributions')\n\n\n# Cost matrices\npl.figure(2, figsize=(7, 3))\n\npl.subplot(1, 3, 1)\npl.imshow(M1, interpolation='nearest')\npl.title('Euclidean cost')\n\npl.subplot(1, 3, 2)\npl.imshow(M2, interpolation='nearest')\npl.title('Squared Euclidean cost')\n\npl.subplot(1, 3, 3)\npl.imshow(Mp, interpolation='nearest')\npl.title('Sqrt Euclidean cost')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Dataset 1 : Plot OT Matrices\n----------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "G1 = ot.emd(a, b, M1)\nG2 = ot.emd(a, b, M2)\nGp = ot.emd(a, b, Mp)\n\n# OT matrices\npl.figure(3, figsize=(7, 3))\n\npl.subplot(1, 3, 1)\not.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT Euclidean')\n\npl.subplot(1, 3, 2)\not.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT squared Euclidean')\n\npl.subplot(1, 3, 3)\not.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT sqrt Euclidean')\npl.tight_layout()\n\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Dataset 2 : Partial circle\n--------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 50 # nb samples\nxtot = np.zeros((n + 1, 2))\nxtot[:, 0] = np.cos(\n (np.arange(n + 1) + 1.0) * 0.9 / (n + 2) * 2 * np.pi)\nxtot[:, 1] = np.sin(\n (np.arange(n + 1) + 1.0) * 0.9 / (n + 2) * 2 * np.pi)\n\nxs = xtot[:n, :]\nxt = xtot[1:, :]\n\na, b = ot.unif(n), ot.unif(n) # uniform distribution on samples\n\n# loss matrix\nM1 = ot.dist(xs, xt, metric='euclidean')\nM1 /= M1.max()\n\n# loss matrix\nM2 = ot.dist(xs, xt, metric='sqeuclidean')\nM2 /= M2.max()\n\n# loss matrix\nMp = np.sqrt(ot.dist(xs, xt, metric='euclidean'))\nMp /= Mp.max()\n\n\n# Data\npl.figure(4, figsize=(7, 3))\npl.clf()\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\npl.title('Source and traget distributions')\n\n\n# Cost matrices\npl.figure(5, figsize=(7, 3))\n\npl.subplot(1, 3, 1)\npl.imshow(M1, interpolation='nearest')\npl.title('Euclidean cost')\n\npl.subplot(1, 3, 2)\npl.imshow(M2, interpolation='nearest')\npl.title('Squared Euclidean cost')\n\npl.subplot(1, 3, 3)\npl.imshow(Mp, interpolation='nearest')\npl.title('Sqrt Euclidean cost')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Dataset 2 : Plot OT Matrices\n-----------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "G1 = ot.emd(a, b, M1)\nG2 = ot.emd(a, b, M2)\nGp = ot.emd(a, b, Mp)\n\n# OT matrices\npl.figure(6, figsize=(7, 3))\n\npl.subplot(1, 3, 1)\not.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT Euclidean')\n\npl.subplot(1, 3, 2)\not.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT squared Euclidean')\n\npl.subplot(1, 3, 3)\not.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT sqrt Euclidean')\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_OT_L1_vs_L2.py b/docs/source/auto_examples/plot_OT_L1_vs_L2.py deleted file mode 100644 index 37b429f..0000000 --- a/docs/source/auto_examples/plot_OT_L1_vs_L2.py +++ /dev/null @@ -1,208 +0,0 @@ -# -*- coding: utf-8 -*- -""" -========================================== -2D Optimal transport for different metrics -========================================== - -2D OT on empirical distributio with different gound metric. - -Stole the figure idea from Fig. 1 and 2 in -https://arxiv.org/pdf/1706.07650.pdf - - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -import ot.plot - -############################################################################## -# Dataset 1 : uniform sampling -# ---------------------------- - -n = 20 # nb samples -xs = np.zeros((n, 2)) -xs[:, 0] = np.arange(n) + 1 -xs[:, 1] = (np.arange(n) + 1) * -0.001 # to make it strictly convex... - -xt = np.zeros((n, 2)) -xt[:, 1] = np.arange(n) + 1 - -a, b = ot.unif(n), ot.unif(n) # uniform distribution on samples - -# loss matrix -M1 = ot.dist(xs, xt, metric='euclidean') -M1 /= M1.max() - -# loss matrix -M2 = ot.dist(xs, xt, metric='sqeuclidean') -M2 /= M2.max() - -# loss matrix -Mp = np.sqrt(ot.dist(xs, xt, metric='euclidean')) -Mp /= Mp.max() - -# Data -pl.figure(1, figsize=(7, 3)) -pl.clf() -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -pl.title('Source and target distributions') - - -# Cost matrices -pl.figure(2, figsize=(7, 3)) - -pl.subplot(1, 3, 1) -pl.imshow(M1, interpolation='nearest') -pl.title('Euclidean cost') - -pl.subplot(1, 3, 2) -pl.imshow(M2, interpolation='nearest') -pl.title('Squared Euclidean cost') - -pl.subplot(1, 3, 3) -pl.imshow(Mp, interpolation='nearest') -pl.title('Sqrt Euclidean cost') -pl.tight_layout() - -############################################################################## -# Dataset 1 : Plot OT Matrices -# ---------------------------- - - -#%% EMD -G1 = ot.emd(a, b, M1) -G2 = ot.emd(a, b, M2) -Gp = ot.emd(a, b, Mp) - -# OT matrices -pl.figure(3, figsize=(7, 3)) - -pl.subplot(1, 3, 1) -ot.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -# pl.legend(loc=0) -pl.title('OT Euclidean') - -pl.subplot(1, 3, 2) -ot.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -# pl.legend(loc=0) -pl.title('OT squared Euclidean') - -pl.subplot(1, 3, 3) -ot.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -# pl.legend(loc=0) -pl.title('OT sqrt Euclidean') -pl.tight_layout() - -pl.show() - - -############################################################################## -# Dataset 2 : Partial circle -# -------------------------- - -n = 50 # nb samples -xtot = np.zeros((n + 1, 2)) -xtot[:, 0] = np.cos( - (np.arange(n + 1) + 1.0) * 0.9 / (n + 2) * 2 * np.pi) -xtot[:, 1] = np.sin( - (np.arange(n + 1) + 1.0) * 0.9 / (n + 2) * 2 * np.pi) - -xs = xtot[:n, :] -xt = xtot[1:, :] - -a, b = ot.unif(n), ot.unif(n) # uniform distribution on samples - -# loss matrix -M1 = ot.dist(xs, xt, metric='euclidean') -M1 /= M1.max() - -# loss matrix -M2 = ot.dist(xs, xt, metric='sqeuclidean') -M2 /= M2.max() - -# loss matrix -Mp = np.sqrt(ot.dist(xs, xt, metric='euclidean')) -Mp /= Mp.max() - - -# Data -pl.figure(4, figsize=(7, 3)) -pl.clf() -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -pl.title('Source and traget distributions') - - -# Cost matrices -pl.figure(5, figsize=(7, 3)) - -pl.subplot(1, 3, 1) -pl.imshow(M1, interpolation='nearest') -pl.title('Euclidean cost') - -pl.subplot(1, 3, 2) -pl.imshow(M2, interpolation='nearest') -pl.title('Squared Euclidean cost') - -pl.subplot(1, 3, 3) -pl.imshow(Mp, interpolation='nearest') -pl.title('Sqrt Euclidean cost') -pl.tight_layout() - -############################################################################## -# Dataset 2 : Plot OT Matrices -# ----------------------------- - - -#%% EMD -G1 = ot.emd(a, b, M1) -G2 = ot.emd(a, b, M2) -Gp = ot.emd(a, b, Mp) - -# OT matrices -pl.figure(6, figsize=(7, 3)) - -pl.subplot(1, 3, 1) -ot.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -# pl.legend(loc=0) -pl.title('OT Euclidean') - -pl.subplot(1, 3, 2) -ot.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -# pl.legend(loc=0) -pl.title('OT squared Euclidean') - -pl.subplot(1, 3, 3) -ot.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1]) -pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') -pl.axis('equal') -# pl.legend(loc=0) -pl.title('OT sqrt Euclidean') -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_OT_L1_vs_L2.rst b/docs/source/auto_examples/plot_OT_L1_vs_L2.rst deleted file mode 100644 index 16b20f9..0000000 --- a/docs/source/auto_examples/plot_OT_L1_vs_L2.rst +++ /dev/null @@ -1,343 +0,0 @@ -.. 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_OT_L1_vs_L2.py: - - -========================================== -2D Optimal transport for different metrics -========================================== - -2D OT on empirical distributio with different gound metric. - -Stole the figure idea from Fig. 1 and 2 in -https://arxiv.org/pdf/1706.07650.pdf - - - - -.. code-block:: default - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - import ot.plot - - - - - - - - -Dataset 1 : uniform sampling ----------------------------- - - -.. code-block:: default - - - n = 20 # nb samples - xs = np.zeros((n, 2)) - xs[:, 0] = np.arange(n) + 1 - xs[:, 1] = (np.arange(n) + 1) * -0.001 # to make it strictly convex... - - xt = np.zeros((n, 2)) - xt[:, 1] = np.arange(n) + 1 - - a, b = ot.unif(n), ot.unif(n) # uniform distribution on samples - - # loss matrix - M1 = ot.dist(xs, xt, metric='euclidean') - M1 /= M1.max() - - # loss matrix - M2 = ot.dist(xs, xt, metric='sqeuclidean') - M2 /= M2.max() - - # loss matrix - Mp = np.sqrt(ot.dist(xs, xt, metric='euclidean')) - Mp /= Mp.max() - - # Data - pl.figure(1, figsize=(7, 3)) - pl.clf() - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - pl.title('Source and target distributions') - - - # Cost matrices - pl.figure(2, figsize=(7, 3)) - - pl.subplot(1, 3, 1) - pl.imshow(M1, interpolation='nearest') - pl.title('Euclidean cost') - - pl.subplot(1, 3, 2) - pl.imshow(M2, interpolation='nearest') - pl.title('Squared Euclidean cost') - - pl.subplot(1, 3, 3) - pl.imshow(Mp, interpolation='nearest') - pl.title('Sqrt Euclidean cost') - pl.tight_layout() - - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_001.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_002.png - :class: sphx-glr-multi-img - - - - - -Dataset 1 : Plot OT Matrices ----------------------------- - - -.. code-block:: default - - G1 = ot.emd(a, b, M1) - G2 = ot.emd(a, b, M2) - Gp = ot.emd(a, b, Mp) - - # OT matrices - pl.figure(3, figsize=(7, 3)) - - pl.subplot(1, 3, 1) - ot.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - # pl.legend(loc=0) - pl.title('OT Euclidean') - - pl.subplot(1, 3, 2) - ot.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - # pl.legend(loc=0) - pl.title('OT squared Euclidean') - - pl.subplot(1, 3, 3) - ot.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - # pl.legend(loc=0) - pl.title('OT sqrt Euclidean') - pl.tight_layout() - - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_OT_L1_vs_L2.py:113: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Dataset 2 : Partial circle --------------------------- - - -.. code-block:: default - - - n = 50 # nb samples - xtot = np.zeros((n + 1, 2)) - xtot[:, 0] = np.cos( - (np.arange(n + 1) + 1.0) * 0.9 / (n + 2) * 2 * np.pi) - xtot[:, 1] = np.sin( - (np.arange(n + 1) + 1.0) * 0.9 / (n + 2) * 2 * np.pi) - - xs = xtot[:n, :] - xt = xtot[1:, :] - - a, b = ot.unif(n), ot.unif(n) # uniform distribution on samples - - # loss matrix - M1 = ot.dist(xs, xt, metric='euclidean') - M1 /= M1.max() - - # loss matrix - M2 = ot.dist(xs, xt, metric='sqeuclidean') - M2 /= M2.max() - - # loss matrix - Mp = np.sqrt(ot.dist(xs, xt, metric='euclidean')) - Mp /= Mp.max() - - - # Data - pl.figure(4, figsize=(7, 3)) - pl.clf() - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - pl.title('Source and traget distributions') - - - # Cost matrices - pl.figure(5, figsize=(7, 3)) - - pl.subplot(1, 3, 1) - pl.imshow(M1, interpolation='nearest') - pl.title('Euclidean cost') - - pl.subplot(1, 3, 2) - pl.imshow(M2, interpolation='nearest') - pl.title('Squared Euclidean cost') - - pl.subplot(1, 3, 3) - pl.imshow(Mp, interpolation='nearest') - pl.title('Sqrt Euclidean cost') - pl.tight_layout() - - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.png - :class: sphx-glr-multi-img - - - - - -Dataset 2 : Plot OT Matrices ------------------------------ - - -.. code-block:: default - - G1 = ot.emd(a, b, M1) - G2 = ot.emd(a, b, M2) - Gp = ot.emd(a, b, Mp) - - # OT matrices - pl.figure(6, figsize=(7, 3)) - - pl.subplot(1, 3, 1) - ot.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - # pl.legend(loc=0) - pl.title('OT Euclidean') - - pl.subplot(1, 3, 2) - ot.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - # pl.legend(loc=0) - pl.title('OT squared Euclidean') - - pl.subplot(1, 3, 3) - ot.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1]) - pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - pl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples') - pl.axis('equal') - # pl.legend(loc=0) - pl.title('OT sqrt Euclidean') - pl.tight_layout() - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_OT_L1_vs_L2.py:208: 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.002 seconds) - - -.. _sphx_glr_download_auto_examples_plot_OT_L1_vs_L2.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_OT_L1_vs_L2.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_OT_L1_vs_L2.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_UOT_1D.ipynb b/docs/source/auto_examples/plot_UOT_1D.ipynb deleted file mode 100644 index 640e398..0000000 --- a/docs/source/auto_examples/plot_UOT_1D.ipynb +++ /dev/null @@ -1,108 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 1D Unbalanced optimal transport\n\n\nThis example illustrates the computation of Unbalanced Optimal transport\nusing a Kullback-Leibler relaxation.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Hicham Janati \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot\nfrom ot.datasets import make_1D_gauss as gauss" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# make distributions unbalanced\nb *= 5.\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot distributions and loss matrix\n----------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()\n\n# plot distributions and loss matrix\n\npl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve Unbalanced Sinkhorn\n--------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Sinkhorn\n\nepsilon = 0.1 # entropy parameter\nalpha = 1. # Unbalanced KL relaxation parameter\nGs = ot.unbalanced.sinkhorn_unbalanced(a, b, M, epsilon, alpha, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'UOT matrix Sinkhorn')\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_UOT_1D.py b/docs/source/auto_examples/plot_UOT_1D.py deleted file mode 100644 index 2ea8b05..0000000 --- a/docs/source/auto_examples/plot_UOT_1D.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding: utf-8 -*- -""" -=============================== -1D Unbalanced optimal transport -=============================== - -This example illustrates the computation of Unbalanced Optimal transport -using a Kullback-Leibler relaxation. -""" - -# Author: Hicham Janati -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -import ot.plot -from ot.datasets import make_1D_gauss as gauss - -############################################################################## -# Generate data -# ------------- - - -#%% parameters - -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) - -# make distributions unbalanced -b *= 5. - -# loss matrix -M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) -M /= M.max() - - -############################################################################## -# Plot distributions and loss matrix -# ---------------------------------- - -#%% plot the distributions - -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') - - -############################################################################## -# Solve Unbalanced Sinkhorn -# -------------- - - -# Sinkhorn - -epsilon = 0.1 # entropy parameter -alpha = 1. # Unbalanced KL relaxation parameter -Gs = ot.unbalanced.sinkhorn_unbalanced(a, b, M, epsilon, alpha, verbose=True) - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, Gs, 'UOT matrix Sinkhorn') - -pl.show() diff --git a/docs/source/auto_examples/plot_UOT_1D.rst b/docs/source/auto_examples/plot_UOT_1D.rst deleted file mode 100644 index f43b0c1..0000000 --- a/docs/source/auto_examples/plot_UOT_1D.rst +++ /dev/null @@ -1,177 +0,0 @@ -.. 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_UOT_1D.py: - - -=============================== -1D Unbalanced optimal transport -=============================== - -This example illustrates the computation of Unbalanced Optimal transport -using a Kullback-Leibler relaxation. - - -.. code-block:: default - - - # Author: Hicham Janati - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - import ot.plot - from ot.datasets import make_1D_gauss as gauss - - - - - - - - -Generate data -------------- - - -.. 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) - - # make distributions unbalanced - b *= 5. - - # loss matrix - M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) - M /= M.max() - - - - - - - - - -Plot distributions and loss matrix ----------------------------------- - - -.. 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:: /auto_examples/images/sphx_glr_plot_UOT_1D_001.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_UOT_1D_002.png - :class: sphx-glr-multi-img - - - - - -Solve Unbalanced Sinkhorn --------------- - - -.. code-block:: default - - - - # Sinkhorn - - epsilon = 0.1 # entropy parameter - alpha = 1. # Unbalanced KL relaxation parameter - Gs = ot.unbalanced.sinkhorn_unbalanced(a, b, M, epsilon, alpha, verbose=True) - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Gs, 'UOT matrix Sinkhorn') - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_UOT_1D_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_UOT_1D.py:76: 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 0.274 seconds) - - -.. _sphx_glr_download_auto_examples_plot_UOT_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_UOT_1D.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_UOT_1D.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb b/docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb deleted file mode 100644 index 549a78b..0000000 --- a/docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 1D Wasserstein barycenter demo for Unbalanced distributions\n\n\nThis example illustrates the computation of regularized Wassersyein Barycenter\nas proposed in [10] for Unbalanced inputs.\n\n\n[10] Chizat, L., Peyr\u00e9, G., Schmitzer, B., & Vialard, F. X. (2016). Scaling algorithms for unbalanced transport problems. arXiv preprint arXiv:1607.05816.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Hicham Janati \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\n# necessary for 3d plot even if not used\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nfrom matplotlib.collections import PolyCollection" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.make_1D_gauss(n, m=60, s=8)\n\n# make unbalanced dists\na2 *= 3.\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# plot the distributions\n\npl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Barycenter computation\n----------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# non weighted barycenter computation\n\nweight = 0.5 # 0<=weight<=1\nweights = np.array([1 - weight, weight])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\nalpha = 1.\n\nbary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights)\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Barycentric interpolation\n-------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# barycenter interpolation\n\nn_weight = 11\nweight_list = np.linspace(0, 1, n_weight)\n\n\nB_l2 = np.zeros((n, n_weight))\n\nB_wass = np.copy(B_l2)\n\nfor i in range(0, n_weight):\n weight = weight_list[i]\n weights = np.array([1 - weight, weight])\n B_l2[:, i] = A.dot(weights)\n B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights)\n\n\n# plot interpolation\n\npl.figure(3)\n\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = weight_list\nfor i, z in enumerate(zs):\n ys = B_l2[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel(r'$\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with l2')\npl.tight_layout()\n\npl.figure(4)\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = weight_list\nfor i, z in enumerate(zs):\n ys = B_wass[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel(r'$\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with Wasserstein')\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_UOT_barycenter_1D.py b/docs/source/auto_examples/plot_UOT_barycenter_1D.py deleted file mode 100644 index acb5892..0000000 --- a/docs/source/auto_examples/plot_UOT_barycenter_1D.py +++ /dev/null @@ -1,164 +0,0 @@ -# -*- coding: utf-8 -*- -""" -=========================================================== -1D Wasserstein barycenter demo for Unbalanced distributions -=========================================================== - -This example illustrates the computation of regularized Wassersyein Barycenter -as proposed in [10] for Unbalanced inputs. - - -[10] Chizat, L., Peyré, G., Schmitzer, B., & Vialard, F. X. (2016). Scaling algorithms for unbalanced transport problems. arXiv preprint arXiv:1607.05816. - -""" - -# Author: Hicham Janati -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -# necessary for 3d plot even if not used -from mpl_toolkits.mplot3d import Axes3D # noqa -from matplotlib.collections import PolyCollection - -############################################################################## -# Generate data -# ------------- - -# parameters - -n = 100 # nb bins - -# bin positions -x = np.arange(n, dtype=np.float64) - -# Gaussian distributions -a1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std -a2 = ot.datasets.make_1D_gauss(n, m=60, s=8) - -# make unbalanced dists -a2 *= 3. - -# creating matrix A containing all distributions -A = np.vstack((a1, a2)).T -n_distributions = A.shape[1] - -# loss matrix + normalization -M = ot.utils.dist0(n) -M /= M.max() - -############################################################################## -# Plot data -# --------- - -# plot the distributions - -pl.figure(1, figsize=(6.4, 3)) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') -pl.tight_layout() - -############################################################################## -# Barycenter computation -# ---------------------- - -# non weighted barycenter computation - -weight = 0.5 # 0<=weight<=1 -weights = np.array([1 - weight, weight]) - -# l2bary -bary_l2 = A.dot(weights) - -# wasserstein -reg = 1e-3 -alpha = 1. - -bary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) - -pl.figure(2) -pl.clf() -pl.subplot(2, 1, 1) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') - -pl.subplot(2, 1, 2) -pl.plot(x, bary_l2, 'r', label='l2') -pl.plot(x, bary_wass, 'g', label='Wasserstein') -pl.legend() -pl.title('Barycenters') -pl.tight_layout() - -############################################################################## -# Barycentric interpolation -# ------------------------- - -# barycenter interpolation - -n_weight = 11 -weight_list = np.linspace(0, 1, n_weight) - - -B_l2 = np.zeros((n, n_weight)) - -B_wass = np.copy(B_l2) - -for i in range(0, n_weight): - weight = weight_list[i] - weights = np.array([1 - weight, weight]) - B_l2[:, i] = A.dot(weights) - B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) - - -# plot interpolation - -pl.figure(3) - -cmap = pl.cm.get_cmap('viridis') -verts = [] -zs = weight_list -for i, z in enumerate(zs): - ys = B_l2[:, i] - verts.append(list(zip(x, ys))) - -ax = pl.gcf().gca(projection='3d') - -poly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list]) -poly.set_alpha(0.7) -ax.add_collection3d(poly, zs=zs, zdir='y') -ax.set_xlabel('x') -ax.set_xlim3d(0, n) -ax.set_ylabel(r'$\alpha$') -ax.set_ylim3d(0, 1) -ax.set_zlabel('') -ax.set_zlim3d(0, B_l2.max() * 1.01) -pl.title('Barycenter interpolation with l2') -pl.tight_layout() - -pl.figure(4) -cmap = pl.cm.get_cmap('viridis') -verts = [] -zs = weight_list -for i, z in enumerate(zs): - ys = B_wass[:, i] - verts.append(list(zip(x, ys))) - -ax = pl.gcf().gca(projection='3d') - -poly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list]) -poly.set_alpha(0.7) -ax.add_collection3d(poly, zs=zs, zdir='y') -ax.set_xlabel('x') -ax.set_xlim3d(0, n) -ax.set_ylabel(r'$\alpha$') -ax.set_ylim3d(0, 1) -ax.set_zlabel('') -ax.set_zlim3d(0, B_l2.max() * 1.01) -pl.title('Barycenter interpolation with Wasserstein') -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_UOT_barycenter_1D.rst b/docs/source/auto_examples/plot_UOT_barycenter_1D.rst deleted file mode 100644 index 2688d2e..0000000 --- a/docs/source/auto_examples/plot_UOT_barycenter_1D.rst +++ /dev/null @@ -1,299 +0,0 @@ -.. 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_UOT_barycenter_1D.py: - - -=========================================================== -1D Wasserstein barycenter demo for Unbalanced distributions -=========================================================== - -This example illustrates the computation of regularized Wassersyein Barycenter -as proposed in [10] for Unbalanced inputs. - - -[10] Chizat, L., Peyré, G., Schmitzer, B., & Vialard, F. X. (2016). Scaling algorithms for unbalanced transport problems. arXiv preprint arXiv:1607.05816. - - - -.. code-block:: default - - - # Author: Hicham Janati - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - # necessary for 3d plot even if not used - from mpl_toolkits.mplot3d import Axes3D # noqa - from matplotlib.collections import PolyCollection - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - # parameters - - n = 100 # nb bins - - # bin positions - x = np.arange(n, dtype=np.float64) - - # Gaussian distributions - a1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std - a2 = ot.datasets.make_1D_gauss(n, m=60, s=8) - - # make unbalanced dists - a2 *= 3. - - # creating matrix A containing all distributions - A = np.vstack((a1, a2)).T - n_distributions = A.shape[1] - - # loss matrix + normalization - M = ot.utils.dist0(n) - M /= M.max() - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - # plot the distributions - - pl.figure(1, figsize=(6.4, 3)) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - pl.tight_layout() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png - :class: sphx-glr-single-img - - - - - -Barycenter computation ----------------------- - - -.. code-block:: default - - - # non weighted barycenter computation - - weight = 0.5 # 0<=weight<=1 - weights = np.array([1 - weight, weight]) - - # l2bary - bary_l2 = A.dot(weights) - - # wasserstein - reg = 1e-3 - alpha = 1. - - bary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) - - pl.figure(2) - pl.clf() - pl.subplot(2, 1, 1) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - - pl.subplot(2, 1, 2) - pl.plot(x, bary_l2, 'r', label='l2') - pl.plot(x, bary_wass, 'g', label='Wasserstein') - pl.legend() - pl.title('Barycenters') - pl.tight_layout() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png - :class: sphx-glr-single-img - - - - - -Barycentric interpolation -------------------------- - - -.. code-block:: default - - - # barycenter interpolation - - n_weight = 11 - weight_list = np.linspace(0, 1, n_weight) - - - B_l2 = np.zeros((n, n_weight)) - - B_wass = np.copy(B_l2) - - for i in range(0, n_weight): - weight = weight_list[i] - weights = np.array([1 - weight, weight]) - B_l2[:, i] = A.dot(weights) - B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) - - - # plot interpolation - - pl.figure(3) - - cmap = pl.cm.get_cmap('viridis') - verts = [] - zs = weight_list - for i, z in enumerate(zs): - ys = B_l2[:, i] - verts.append(list(zip(x, ys))) - - ax = pl.gcf().gca(projection='3d') - - poly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list]) - poly.set_alpha(0.7) - ax.add_collection3d(poly, zs=zs, zdir='y') - ax.set_xlabel('x') - ax.set_xlim3d(0, n) - ax.set_ylabel(r'$\alpha$') - ax.set_ylim3d(0, 1) - ax.set_zlabel('') - ax.set_zlim3d(0, B_l2.max() * 1.01) - pl.title('Barycenter interpolation with l2') - pl.tight_layout() - - pl.figure(4) - cmap = pl.cm.get_cmap('viridis') - verts = [] - zs = weight_list - for i, z in enumerate(zs): - ys = B_wass[:, i] - verts.append(list(zip(x, ys))) - - ax = pl.gcf().gca(projection='3d') - - poly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list]) - poly.set_alpha(0.7) - ax.add_collection3d(poly, zs=zs, zdir='y') - ax.set_xlabel('x') - ax.set_xlim3d(0, n) - ax.set_ylabel(r'$\alpha$') - ax.set_ylim3d(0, 1) - ax.set_zlabel('') - ax.set_zlim3d(0, B_l2.max() * 1.01) - pl.title('Barycenter interpolation with Wasserstein') - pl.tight_layout() - - pl.show() - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png - :class: sphx-glr-multi-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/ot/unbalanced.py:895: RuntimeWarning: overflow encountered in true_divide - u = (A / Kv) ** fi - /home/rflamary/PYTHON/POT/ot/unbalanced.py:900: RuntimeWarning: invalid value encountered in true_divide - v = (Q / Ktu) ** fi - /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 595 - warnings.warn('Numerical errors at iteration %s' % i) - /home/rflamary/PYTHON/POT/ot/unbalanced.py:900: RuntimeWarning: overflow encountered in true_divide - v = (Q / Ktu) ** fi - /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 974 - warnings.warn('Numerical errors at iteration %s' % i) - /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 615 - warnings.warn('Numerical errors at iteration %s' % i) - /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 455 - warnings.warn('Numerical errors at iteration %s' % i) - /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 361 - warnings.warn('Numerical errors at iteration %s' % i) - /home/rflamary/PYTHON/POT/examples/plot_UOT_barycenter_1D.py:164: 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.567 seconds) - - -.. _sphx_glr_download_auto_examples_plot_UOT_barycenter_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_UOT_barycenter_1D.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_UOT_barycenter_1D.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_WDA.ipynb b/docs/source/auto_examples/plot_WDA.ipynb deleted file mode 100644 index 1661c53..0000000 --- a/docs/source/auto_examples/plot_WDA.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "nbformat_minor": 0, - "nbformat": 4, - "cells": [ - { - "execution_count": null, - "cell_type": "code", - "source": [ - "%matplotlib inline" - ], - "outputs": [], - "metadata": { - "collapsed": false - } - }, - { - "source": [ - "\n# Wasserstein Discriminant Analysis\n\n\nThis example illustrate the use of WDA as proposed in [11].\n\n\n[11] Flamary, R., Cuturi, M., Courty, N., & Rakotomamonjy, A. (2016).\nWasserstein Discriminant Analysis.\n\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, - { - "execution_count": null, - "cell_type": "code", - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\n\nfrom ot.dr import wda, fda" - ], - "outputs": [], - "metadata": { - "collapsed": false - } - }, - { - "source": [ - "Generate data\n-------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, - { - "execution_count": null, - "cell_type": "code", - "source": [ - "#%% parameters\n\nn = 1000 # nb samples in source and target datasets\nnz = 0.2\n\n# generate circle dataset\nt = np.random.rand(n) * 2 * np.pi\nys = np.floor((np.arange(n) * 1.0 / n * 3)) + 1\nxs = np.concatenate(\n (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1)\nxs = xs * ys.reshape(-1, 1) + nz * np.random.randn(n, 2)\n\nt = np.random.rand(n) * 2 * np.pi\nyt = np.floor((np.arange(n) * 1.0 / n * 3)) + 1\nxt = np.concatenate(\n (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1)\nxt = xt * yt.reshape(-1, 1) + nz * np.random.randn(n, 2)\n\nnbnoise = 8\n\nxs = np.hstack((xs, np.random.randn(n, nbnoise)))\nxt = np.hstack((xt, np.random.randn(n, nbnoise)))" - ], - "outputs": [], - "metadata": { - "collapsed": false - } - }, - { - "source": [ - "Plot data\n---------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, - { - "execution_count": null, - "cell_type": "code", - "source": [ - "#%% plot samples\npl.figure(1, figsize=(6.4, 3.5))\n\npl.subplot(1, 2, 1)\npl.scatter(xt[:, 0], xt[:, 1], c=ys, marker='+', label='Source samples')\npl.legend(loc=0)\npl.title('Discriminant dimensions')\n\npl.subplot(1, 2, 2)\npl.scatter(xt[:, 2], xt[:, 3], c=ys, marker='+', label='Source samples')\npl.legend(loc=0)\npl.title('Other dimensions')\npl.tight_layout()" - ], - "outputs": [], - "metadata": { - "collapsed": false - } - }, - { - "source": [ - "Compute Fisher Discriminant Analysis\n------------------------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, - { - "execution_count": null, - "cell_type": "code", - "source": [ - "#%% Compute FDA\np = 2\n\nPfda, projfda = fda(xs, ys, p)" - ], - "outputs": [], - "metadata": { - "collapsed": false - } - }, - { - "source": [ - "Compute Wasserstein Discriminant Analysis\n-----------------------------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, - { - "execution_count": null, - "cell_type": "code", - "source": [ - "#%% Compute WDA\np = 2\nreg = 1e0\nk = 10\nmaxiter = 100\n\nPwda, projwda = wda(xs, ys, p, reg, k, maxiter=maxiter)" - ], - "outputs": [], - "metadata": { - "collapsed": false - } - }, - { - "source": [ - "Plot 2D projections\n-------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, - { - "execution_count": null, - "cell_type": "code", - "source": [ - "#%% plot samples\n\nxsp = projfda(xs)\nxtp = projfda(xt)\n\nxspw = projwda(xs)\nxtpw = projwda(xt)\n\npl.figure(2)\n\npl.subplot(2, 2, 1)\npl.scatter(xsp[:, 0], xsp[:, 1], c=ys, marker='+', label='Projected samples')\npl.legend(loc=0)\npl.title('Projected training samples FDA')\n\npl.subplot(2, 2, 2)\npl.scatter(xtp[:, 0], xtp[:, 1], c=ys, marker='+', label='Projected samples')\npl.legend(loc=0)\npl.title('Projected test samples FDA')\n\npl.subplot(2, 2, 3)\npl.scatter(xspw[:, 0], xspw[:, 1], c=ys, marker='+', label='Projected samples')\npl.legend(loc=0)\npl.title('Projected training samples WDA')\n\npl.subplot(2, 2, 4)\npl.scatter(xtpw[:, 0], xtpw[:, 1], c=ys, marker='+', label='Projected samples')\npl.legend(loc=0)\npl.title('Projected test samples WDA')\npl.tight_layout()\n\npl.show()" - ], - "outputs": [], - "metadata": { - "collapsed": false - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "name": "python2", - "language": "python" - }, - "language_info": { - "mimetype": "text/x-python", - "nbconvert_exporter": "python", - "name": "python", - "file_extension": ".py", - "version": "2.7.12", - "pygments_lexer": "ipython2", - "codemirror_mode": { - "version": 2, - "name": "ipython" - } - } - } -} \ No newline at end of file diff --git a/docs/source/auto_examples/plot_WDA.py b/docs/source/auto_examples/plot_WDA.py deleted file mode 100644 index 93cc237..0000000 --- a/docs/source/auto_examples/plot_WDA.py +++ /dev/null @@ -1,127 +0,0 @@ -# -*- coding: utf-8 -*- -""" -================================= -Wasserstein Discriminant Analysis -================================= - -This example illustrate the use of WDA as proposed in [11]. - - -[11] Flamary, R., Cuturi, M., Courty, N., & Rakotomamonjy, A. (2016). -Wasserstein Discriminant Analysis. - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl - -from ot.dr import wda, fda - - -############################################################################## -# Generate data -# ------------- - -#%% parameters - -n = 1000 # nb samples in source and target datasets -nz = 0.2 - -# generate circle dataset -t = np.random.rand(n) * 2 * np.pi -ys = np.floor((np.arange(n) * 1.0 / n * 3)) + 1 -xs = np.concatenate( - (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1) -xs = xs * ys.reshape(-1, 1) + nz * np.random.randn(n, 2) - -t = np.random.rand(n) * 2 * np.pi -yt = np.floor((np.arange(n) * 1.0 / n * 3)) + 1 -xt = np.concatenate( - (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1) -xt = xt * yt.reshape(-1, 1) + nz * np.random.randn(n, 2) - -nbnoise = 8 - -xs = np.hstack((xs, np.random.randn(n, nbnoise))) -xt = np.hstack((xt, np.random.randn(n, nbnoise))) - -############################################################################## -# Plot data -# --------- - -#%% plot samples -pl.figure(1, figsize=(6.4, 3.5)) - -pl.subplot(1, 2, 1) -pl.scatter(xt[:, 0], xt[:, 1], c=ys, marker='+', label='Source samples') -pl.legend(loc=0) -pl.title('Discriminant dimensions') - -pl.subplot(1, 2, 2) -pl.scatter(xt[:, 2], xt[:, 3], c=ys, marker='+', label='Source samples') -pl.legend(loc=0) -pl.title('Other dimensions') -pl.tight_layout() - -############################################################################## -# Compute Fisher Discriminant Analysis -# ------------------------------------ - -#%% Compute FDA -p = 2 - -Pfda, projfda = fda(xs, ys, p) - -############################################################################## -# Compute Wasserstein Discriminant Analysis -# ----------------------------------------- - -#%% Compute WDA -p = 2 -reg = 1e0 -k = 10 -maxiter = 100 - -Pwda, projwda = wda(xs, ys, p, reg, k, maxiter=maxiter) - - -############################################################################## -# Plot 2D projections -# ------------------- - -#%% plot samples - -xsp = projfda(xs) -xtp = projfda(xt) - -xspw = projwda(xs) -xtpw = projwda(xt) - -pl.figure(2) - -pl.subplot(2, 2, 1) -pl.scatter(xsp[:, 0], xsp[:, 1], c=ys, marker='+', label='Projected samples') -pl.legend(loc=0) -pl.title('Projected training samples FDA') - -pl.subplot(2, 2, 2) -pl.scatter(xtp[:, 0], xtp[:, 1], c=ys, marker='+', label='Projected samples') -pl.legend(loc=0) -pl.title('Projected test samples FDA') - -pl.subplot(2, 2, 3) -pl.scatter(xspw[:, 0], xspw[:, 1], c=ys, marker='+', label='Projected samples') -pl.legend(loc=0) -pl.title('Projected training samples WDA') - -pl.subplot(2, 2, 4) -pl.scatter(xtpw[:, 0], xtpw[:, 1], c=ys, marker='+', label='Projected samples') -pl.legend(loc=0) -pl.title('Projected test samples WDA') -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_WDA.rst b/docs/source/auto_examples/plot_WDA.rst deleted file mode 100644 index 2d83123..0000000 --- a/docs/source/auto_examples/plot_WDA.rst +++ /dev/null @@ -1,244 +0,0 @@ - - -.. _sphx_glr_auto_examples_plot_WDA.py: - - -================================= -Wasserstein Discriminant Analysis -================================= - -This example illustrate the use of WDA as proposed in [11]. - - -[11] Flamary, R., Cuturi, M., Courty, N., & Rakotomamonjy, A. (2016). -Wasserstein Discriminant Analysis. - - - - -.. code-block:: python - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - - from ot.dr import wda, fda - - - - - - - - -Generate data -------------- - - - -.. code-block:: python - - - #%% parameters - - n = 1000 # nb samples in source and target datasets - nz = 0.2 - - # generate circle dataset - t = np.random.rand(n) * 2 * np.pi - ys = np.floor((np.arange(n) * 1.0 / n * 3)) + 1 - xs = np.concatenate( - (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1) - xs = xs * ys.reshape(-1, 1) + nz * np.random.randn(n, 2) - - t = np.random.rand(n) * 2 * np.pi - yt = np.floor((np.arange(n) * 1.0 / n * 3)) + 1 - xt = np.concatenate( - (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1) - xt = xt * yt.reshape(-1, 1) + nz * np.random.randn(n, 2) - - nbnoise = 8 - - xs = np.hstack((xs, np.random.randn(n, nbnoise))) - xt = np.hstack((xt, np.random.randn(n, nbnoise))) - - - - - - - -Plot data ---------- - - - -.. code-block:: python - - - #%% plot samples - pl.figure(1, figsize=(6.4, 3.5)) - - pl.subplot(1, 2, 1) - pl.scatter(xt[:, 0], xt[:, 1], c=ys, marker='+', label='Source samples') - pl.legend(loc=0) - pl.title('Discriminant dimensions') - - pl.subplot(1, 2, 2) - pl.scatter(xt[:, 2], xt[:, 3], c=ys, marker='+', label='Source samples') - pl.legend(loc=0) - pl.title('Other dimensions') - pl.tight_layout() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_WDA_001.png - :align: center - - - - -Compute Fisher Discriminant Analysis ------------------------------------- - - - -.. code-block:: python - - - #%% Compute FDA - p = 2 - - Pfda, projfda = fda(xs, ys, p) - - - - - - - -Compute Wasserstein Discriminant Analysis ------------------------------------------ - - - -.. code-block:: python - - - #%% Compute WDA - p = 2 - reg = 1e0 - k = 10 - maxiter = 100 - - Pwda, projwda = wda(xs, ys, p, reg, k, maxiter=maxiter) - - - - - - -.. rst-class:: sphx-glr-script-out - - Out:: - - Compiling cost function... - Computing gradient of cost function... - iter cost val grad. norm - 1 +9.0167295050534191e-01 2.28422652e-01 - 2 +4.8324990550878105e-01 4.89362707e-01 - 3 +3.4613154515357075e-01 2.84117562e-01 - 4 +2.5277108387195002e-01 1.24888750e-01 - 5 +2.4113858393736629e-01 8.07491482e-02 - 6 +2.3642108593032782e-01 1.67612140e-02 - 7 +2.3625721372202199e-01 7.68640008e-03 - 8 +2.3625461994913738e-01 7.42200784e-03 - 9 +2.3624493441436939e-01 6.43534105e-03 - 10 +2.3621901383686217e-01 2.17960585e-03 - 11 +2.3621854258326572e-01 2.03306749e-03 - 12 +2.3621696458678049e-01 1.37118721e-03 - 13 +2.3621569489873540e-01 2.76368907e-04 - 14 +2.3621565599232983e-01 1.41898134e-04 - 15 +2.3621564465487518e-01 5.96602069e-05 - 16 +2.3621564232556647e-01 1.08709521e-05 - 17 +2.3621564230277003e-01 9.17855656e-06 - 18 +2.3621564224857586e-01 1.73728345e-06 - 19 +2.3621564224748123e-01 1.17770019e-06 - 20 +2.3621564224658587e-01 2.16179383e-07 - Terminated - min grad norm reached after 20 iterations, 9.20 seconds. - - -Plot 2D projections -------------------- - - - -.. code-block:: python - - - #%% plot samples - - xsp = projfda(xs) - xtp = projfda(xt) - - xspw = projwda(xs) - xtpw = projwda(xt) - - pl.figure(2) - - pl.subplot(2, 2, 1) - pl.scatter(xsp[:, 0], xsp[:, 1], c=ys, marker='+', label='Projected samples') - pl.legend(loc=0) - pl.title('Projected training samples FDA') - - pl.subplot(2, 2, 2) - pl.scatter(xtp[:, 0], xtp[:, 1], c=ys, marker='+', label='Projected samples') - pl.legend(loc=0) - pl.title('Projected test samples FDA') - - pl.subplot(2, 2, 3) - pl.scatter(xspw[:, 0], xspw[:, 1], c=ys, marker='+', label='Projected samples') - pl.legend(loc=0) - pl.title('Projected training samples WDA') - - pl.subplot(2, 2, 4) - pl.scatter(xtpw[:, 0], xtpw[:, 1], c=ys, marker='+', label='Projected samples') - pl.legend(loc=0) - pl.title('Projected test samples WDA') - pl.tight_layout() - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_WDA_003.png - :align: center - - - - -**Total running time of the script:** ( 0 minutes 16.182 seconds) - - - -.. container:: sphx-glr-footer - - - .. container:: sphx-glr-download - - :download:`Download Python source code: plot_WDA.py ` - - - - .. container:: sphx-glr-download - - :download:`Download Jupyter notebook: plot_WDA.ipynb ` - -.. rst-class:: sphx-glr-signature - - `Generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_barycenter_1D.ipynb b/docs/source/auto_examples/plot_barycenter_1D.ipynb deleted file mode 100644 index 387c41a..0000000 --- a/docs/source/auto_examples/plot_barycenter_1D.ipynb +++ /dev/null @@ -1,137 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 1D Wasserstein barycenter demo\n\n\nThis example illustrates the computation of regularized Wassersyein Barycenter\nas proposed in [3].\n\n\n[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyr\u00e9, G. (2015).\nIterative Bregman projections for regularized transportation problems\nSIAM Journal on Scientific Computing, 37(2), A1111-A1138.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\n# necessary for 3d plot even if not used\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nfrom matplotlib.collections import PolyCollection" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.make_1D_gauss(n, m=60, s=8)\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Barycenter computation\n----------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "alpha = 0.2 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Barycentric interpolation\n-------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_alpha = 11\nalpha_list = np.linspace(0, 1, n_alpha)\n\n\nB_l2 = np.zeros((n, n_alpha))\n\nB_wass = np.copy(B_l2)\n\nfor i in range(0, n_alpha):\n alpha = alpha_list[i]\n weights = np.array([1 - alpha, alpha])\n B_l2[:, i] = A.dot(weights)\n B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(3)\n\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_l2[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with l2')\npl.tight_layout()\n\npl.figure(4)\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_wass[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with Wasserstein')\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_barycenter_1D.py b/docs/source/auto_examples/plot_barycenter_1D.py deleted file mode 100644 index 6864301..0000000 --- a/docs/source/auto_examples/plot_barycenter_1D.py +++ /dev/null @@ -1,160 +0,0 @@ -# -*- coding: utf-8 -*- -""" -============================== -1D Wasserstein barycenter demo -============================== - -This example illustrates the computation of regularized Wassersyein Barycenter -as proposed in [3]. - - -[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyré, G. (2015). -Iterative Bregman projections for regularized transportation problems -SIAM Journal on Scientific Computing, 37(2), A1111-A1138. - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -# necessary for 3d plot even if not used -from mpl_toolkits.mplot3d import Axes3D # noqa -from matplotlib.collections import PolyCollection - -############################################################################## -# Generate data -# ------------- - -#%% parameters - -n = 100 # nb bins - -# bin positions -x = np.arange(n, dtype=np.float64) - -# Gaussian distributions -a1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std -a2 = ot.datasets.make_1D_gauss(n, m=60, s=8) - -# creating matrix A containing all distributions -A = np.vstack((a1, a2)).T -n_distributions = A.shape[1] - -# loss matrix + normalization -M = ot.utils.dist0(n) -M /= M.max() - -############################################################################## -# Plot data -# --------- - -#%% plot the distributions - -pl.figure(1, figsize=(6.4, 3)) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') -pl.tight_layout() - -############################################################################## -# Barycenter computation -# ---------------------- - -#%% barycenter computation - -alpha = 0.2 # 0<=alpha<=1 -weights = np.array([1 - alpha, alpha]) - -# l2bary -bary_l2 = A.dot(weights) - -# wasserstein -reg = 1e-3 -bary_wass = ot.bregman.barycenter(A, M, reg, weights) - -pl.figure(2) -pl.clf() -pl.subplot(2, 1, 1) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') - -pl.subplot(2, 1, 2) -pl.plot(x, bary_l2, 'r', label='l2') -pl.plot(x, bary_wass, 'g', label='Wasserstein') -pl.legend() -pl.title('Barycenters') -pl.tight_layout() - -############################################################################## -# Barycentric interpolation -# ------------------------- - -#%% barycenter interpolation - -n_alpha = 11 -alpha_list = np.linspace(0, 1, n_alpha) - - -B_l2 = np.zeros((n, n_alpha)) - -B_wass = np.copy(B_l2) - -for i in range(0, n_alpha): - alpha = alpha_list[i] - weights = np.array([1 - alpha, alpha]) - B_l2[:, i] = A.dot(weights) - B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights) - -#%% plot interpolation - -pl.figure(3) - -cmap = pl.cm.get_cmap('viridis') -verts = [] -zs = alpha_list -for i, z in enumerate(zs): - ys = B_l2[:, i] - verts.append(list(zip(x, ys))) - -ax = pl.gcf().gca(projection='3d') - -poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list]) -poly.set_alpha(0.7) -ax.add_collection3d(poly, zs=zs, zdir='y') -ax.set_xlabel('x') -ax.set_xlim3d(0, n) -ax.set_ylabel('$\\alpha$') -ax.set_ylim3d(0, 1) -ax.set_zlabel('') -ax.set_zlim3d(0, B_l2.max() * 1.01) -pl.title('Barycenter interpolation with l2') -pl.tight_layout() - -pl.figure(4) -cmap = pl.cm.get_cmap('viridis') -verts = [] -zs = alpha_list -for i, z in enumerate(zs): - ys = B_wass[:, i] - verts.append(list(zip(x, ys))) - -ax = pl.gcf().gca(projection='3d') - -poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list]) -poly.set_alpha(0.7) -ax.add_collection3d(poly, zs=zs, zdir='y') -ax.set_xlabel('x') -ax.set_xlim3d(0, n) -ax.set_ylabel('$\\alpha$') -ax.set_ylim3d(0, 1) -ax.set_zlabel('') -ax.set_zlim3d(0, B_l2.max() * 1.01) -pl.title('Barycenter interpolation with Wasserstein') -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_barycenter_1D.rst b/docs/source/auto_examples/plot_barycenter_1D.rst deleted file mode 100644 index a65ac3d..0000000 --- a/docs/source/auto_examples/plot_barycenter_1D.rst +++ /dev/null @@ -1,280 +0,0 @@ -.. 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_barycenter_1D.py: - - -============================== -1D Wasserstein barycenter demo -============================== - -This example illustrates the computation of regularized Wassersyein Barycenter -as proposed in [3]. - - -[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyré, G. (2015). -Iterative Bregman projections for regularized transportation problems -SIAM Journal on Scientific Computing, 37(2), A1111-A1138. - - - -.. code-block:: default - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - # necessary for 3d plot even if not used - from mpl_toolkits.mplot3d import Axes3D # noqa - from matplotlib.collections import PolyCollection - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - n = 100 # nb bins - - # bin positions - x = np.arange(n, dtype=np.float64) - - # Gaussian distributions - a1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std - a2 = ot.datasets.make_1D_gauss(n, m=60, s=8) - - # creating matrix A containing all distributions - A = np.vstack((a1, a2)).T - n_distributions = A.shape[1] - - # loss matrix + normalization - M = ot.utils.dist0(n) - M /= M.max() - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - pl.figure(1, figsize=(6.4, 3)) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - pl.tight_layout() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_001.png - :class: sphx-glr-single-img - - - - - -Barycenter computation ----------------------- - - -.. code-block:: default - - - alpha = 0.2 # 0<=alpha<=1 - weights = np.array([1 - alpha, alpha]) - - # l2bary - bary_l2 = A.dot(weights) - - # wasserstein - reg = 1e-3 - bary_wass = ot.bregman.barycenter(A, M, reg, weights) - - pl.figure(2) - pl.clf() - pl.subplot(2, 1, 1) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - - pl.subplot(2, 1, 2) - pl.plot(x, bary_l2, 'r', label='l2') - pl.plot(x, bary_wass, 'g', label='Wasserstein') - pl.legend() - pl.title('Barycenters') - pl.tight_layout() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_002.png - :class: sphx-glr-single-img - - - - - -Barycentric interpolation -------------------------- - - -.. code-block:: default - - - n_alpha = 11 - alpha_list = np.linspace(0, 1, n_alpha) - - - B_l2 = np.zeros((n, n_alpha)) - - B_wass = np.copy(B_l2) - - for i in range(0, n_alpha): - alpha = alpha_list[i] - weights = np.array([1 - alpha, alpha]) - B_l2[:, i] = A.dot(weights) - B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights) - - - - - - - - - -.. code-block:: default - - - pl.figure(3) - - cmap = pl.cm.get_cmap('viridis') - verts = [] - zs = alpha_list - for i, z in enumerate(zs): - ys = B_l2[:, i] - verts.append(list(zip(x, ys))) - - ax = pl.gcf().gca(projection='3d') - - poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list]) - poly.set_alpha(0.7) - ax.add_collection3d(poly, zs=zs, zdir='y') - ax.set_xlabel('x') - ax.set_xlim3d(0, n) - ax.set_ylabel('$\\alpha$') - ax.set_ylim3d(0, 1) - ax.set_zlabel('') - ax.set_zlim3d(0, B_l2.max() * 1.01) - pl.title('Barycenter interpolation with l2') - pl.tight_layout() - - pl.figure(4) - cmap = pl.cm.get_cmap('viridis') - verts = [] - zs = alpha_list - for i, z in enumerate(zs): - ys = B_wass[:, i] - verts.append(list(zip(x, ys))) - - ax = pl.gcf().gca(projection='3d') - - poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list]) - poly.set_alpha(0.7) - ax.add_collection3d(poly, zs=zs, zdir='y') - ax.set_xlabel('x') - ax.set_xlim3d(0, n) - ax.set_ylabel('$\\alpha$') - ax.set_ylim3d(0, 1) - ax.set_zlabel('') - ax.set_zlim3d(0, B_l2.max() * 1.01) - pl.title('Barycenter interpolation with Wasserstein') - pl.tight_layout() - - pl.show() - - - -.. rst-class:: sphx-glr-horizontal - - - * - - .. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_003.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_004.png - :class: sphx-glr-multi-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_barycenter_1D.py:160: 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 0.769 seconds) - - -.. _sphx_glr_download_auto_examples_plot_barycenter_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_barycenter_1D.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_barycenter_1D.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_barycenter_fgw.ipynb b/docs/source/auto_examples/plot_barycenter_fgw.ipynb deleted file mode 100644 index 4e4704c..0000000 --- a/docs/source/auto_examples/plot_barycenter_fgw.ipynb +++ /dev/null @@ -1,173 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n=================================\nPlot graphs' barycenter using FGW\n=================================\n\nThis example illustrates the computation barycenter of labeled graphs using FGW\n\nRequires networkx >=2\n\n.. [18] Vayer Titouan, Chapel Laetitia, Flamary R{'e}mi, Tavenard Romain\n and Courty Nicolas\n \"Optimal Transport for structured data with application on graphs\"\n International Conference on Machine Learning (ICML). 2019.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Titouan Vayer \n#\n# License: MIT License" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import numpy as np\nimport matplotlib.pyplot as plt\nimport networkx as nx\nimport math\nfrom scipy.sparse.csgraph import shortest_path\nimport matplotlib.colors as mcol\nfrom matplotlib import cm\nfrom ot.gromov import fgw_barycenters" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def find_thresh(C, inf=0.5, sup=3, step=10):\n \"\"\" Trick to find the adequate thresholds from where value of the C matrix are considered close enough to say that nodes are connected\n Tthe threshold is found by a linesearch between values \"inf\" and \"sup\" with \"step\" thresholds tested.\n The optimal threshold is the one which minimizes the reconstruction error between the shortest_path matrix coming from the thresholded adjency matrix\n and the original matrix.\n Parameters\n ----------\n C : ndarray, shape (n_nodes,n_nodes)\n The structure matrix to threshold\n inf : float\n The beginning of the linesearch\n sup : float\n The end of the linesearch\n step : integer\n Number of thresholds tested\n \"\"\"\n dist = []\n search = np.linspace(inf, sup, step)\n for thresh in search:\n Cprime = sp_to_adjency(C, 0, thresh)\n SC = shortest_path(Cprime, method='D')\n SC[SC == float('inf')] = 100\n dist.append(np.linalg.norm(SC - C))\n return search[np.argmin(dist)], dist\n\n\ndef sp_to_adjency(C, threshinf=0.2, threshsup=1.8):\n \"\"\" Thresholds the structure matrix in order to compute an adjency matrix.\n All values between threshinf and threshsup are considered representing connected nodes and set to 1. Else are set to 0\n Parameters\n ----------\n C : ndarray, shape (n_nodes,n_nodes)\n The structure matrix to threshold\n threshinf : float\n The minimum value of distance from which the new value is set to 1\n threshsup : float\n The maximum value of distance from which the new value is set to 1\n Returns\n -------\n C : ndarray, shape (n_nodes,n_nodes)\n The threshold matrix. Each element is in {0,1}\n \"\"\"\n H = np.zeros_like(C)\n np.fill_diagonal(H, np.diagonal(C))\n C = C - H\n C = np.minimum(np.maximum(C, threshinf), threshsup)\n C[C == threshsup] = 0\n C[C != 0] = 1\n\n return C\n\n\ndef build_noisy_circular_graph(N=20, mu=0, sigma=0.3, with_noise=False, structure_noise=False, p=None):\n \"\"\" Create a noisy circular graph\n \"\"\"\n g = nx.Graph()\n g.add_nodes_from(list(range(N)))\n for i in range(N):\n noise = float(np.random.normal(mu, sigma, 1))\n if with_noise:\n g.add_node(i, attr_name=math.sin((2 * i * math.pi / N)) + noise)\n else:\n g.add_node(i, attr_name=math.sin(2 * i * math.pi / N))\n g.add_edge(i, i + 1)\n if structure_noise:\n randomint = np.random.randint(0, p)\n if randomint == 0:\n if i <= N - 3:\n g.add_edge(i, i + 2)\n if i == N - 2:\n g.add_edge(i, 0)\n if i == N - 1:\n g.add_edge(i, 1)\n g.add_edge(N, 0)\n noise = float(np.random.normal(mu, sigma, 1))\n if with_noise:\n g.add_node(N, attr_name=math.sin((2 * N * math.pi / N)) + noise)\n else:\n g.add_node(N, attr_name=math.sin(2 * N * math.pi / N))\n return g\n\n\ndef graph_colors(nx_graph, vmin=0, vmax=7):\n cnorm = mcol.Normalize(vmin=vmin, vmax=vmax)\n cpick = cm.ScalarMappable(norm=cnorm, cmap='viridis')\n cpick.set_array([])\n val_map = {}\n for k, v in nx.get_node_attributes(nx_graph, 'attr_name').items():\n val_map[k] = cpick.to_rgba(v)\n colors = []\n for node in nx_graph.nodes():\n colors.append(val_map[node])\n return colors" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We build a dataset of noisy circular graphs.\nNoise is added on the structures by random connections and on the features by gaussian noise.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "np.random.seed(30)\nX0 = []\nfor k in range(9):\n X0.append(build_noisy_circular_graph(np.random.randint(15, 25), with_noise=True, structure_noise=True, p=3))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "plt.figure(figsize=(8, 10))\nfor i in range(len(X0)):\n plt.subplot(3, 3, i + 1)\n g = X0[i]\n pos = nx.kamada_kawai_layout(g)\n nx.draw(g, pos=pos, node_color=graph_colors(g, vmin=-1, vmax=1), with_labels=False, node_size=100)\nplt.suptitle('Dataset of noisy graphs. Color indicates the label', fontsize=20)\nplt.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Barycenter computation\n----------------------\n\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Features distances are the euclidean distances\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "Cs = [shortest_path(nx.adjacency_matrix(x)) for x in X0]\nps = [np.ones(len(x.nodes())) / len(x.nodes()) for x in X0]\nYs = [np.array([v for (k, v) in nx.get_node_attributes(x, 'attr_name').items()]).reshape(-1, 1) for x in X0]\nlambdas = np.array([np.ones(len(Ys)) / len(Ys)]).ravel()\nsizebary = 15 # we choose a barycenter with 15 nodes\n\nA, C, log = fgw_barycenters(sizebary, Ys, Cs, ps, lambdas, alpha=0.95, log=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot Barycenter\n-------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "bary = nx.from_numpy_matrix(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0]))\nfor i, v in enumerate(A.ravel()):\n bary.add_node(i, attr_name=v)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pos = nx.kamada_kawai_layout(bary)\nnx.draw(bary, pos=pos, node_color=graph_colors(bary, vmin=-1, vmax=1), with_labels=False)\nplt.suptitle('Barycenter', fontsize=20)\nplt.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_barycenter_fgw.py b/docs/source/auto_examples/plot_barycenter_fgw.py deleted file mode 100644 index 77b0370..0000000 --- a/docs/source/auto_examples/plot_barycenter_fgw.py +++ /dev/null @@ -1,184 +0,0 @@ -# -*- coding: utf-8 -*- -""" -================================= -Plot graphs' barycenter using FGW -================================= - -This example illustrates the computation barycenter of labeled graphs using FGW - -Requires networkx >=2 - -.. [18] Vayer Titouan, Chapel Laetitia, Flamary R{\'e}mi, Tavenard Romain - and Courty Nicolas - "Optimal Transport for structured data with application on graphs" - International Conference on Machine Learning (ICML). 2019. - -""" - -# Author: Titouan Vayer -# -# License: MIT License - -#%% load libraries -import numpy as np -import matplotlib.pyplot as plt -import networkx as nx -import math -from scipy.sparse.csgraph import shortest_path -import matplotlib.colors as mcol -from matplotlib import cm -from ot.gromov import fgw_barycenters -#%% Graph functions - - -def find_thresh(C, inf=0.5, sup=3, step=10): - """ Trick to find the adequate thresholds from where value of the C matrix are considered close enough to say that nodes are connected - Tthe threshold is found by a linesearch between values "inf" and "sup" with "step" thresholds tested. - The optimal threshold is the one which minimizes the reconstruction error between the shortest_path matrix coming from the thresholded adjency matrix - and the original matrix. - Parameters - ---------- - C : ndarray, shape (n_nodes,n_nodes) - The structure matrix to threshold - inf : float - The beginning of the linesearch - sup : float - The end of the linesearch - step : integer - Number of thresholds tested - """ - dist = [] - search = np.linspace(inf, sup, step) - for thresh in search: - Cprime = sp_to_adjency(C, 0, thresh) - SC = shortest_path(Cprime, method='D') - SC[SC == float('inf')] = 100 - dist.append(np.linalg.norm(SC - C)) - return search[np.argmin(dist)], dist - - -def sp_to_adjency(C, threshinf=0.2, threshsup=1.8): - """ Thresholds the structure matrix in order to compute an adjency matrix. - All values between threshinf and threshsup are considered representing connected nodes and set to 1. Else are set to 0 - Parameters - ---------- - C : ndarray, shape (n_nodes,n_nodes) - The structure matrix to threshold - threshinf : float - The minimum value of distance from which the new value is set to 1 - threshsup : float - The maximum value of distance from which the new value is set to 1 - Returns - ------- - C : ndarray, shape (n_nodes,n_nodes) - The threshold matrix. Each element is in {0,1} - """ - H = np.zeros_like(C) - np.fill_diagonal(H, np.diagonal(C)) - C = C - H - C = np.minimum(np.maximum(C, threshinf), threshsup) - C[C == threshsup] = 0 - C[C != 0] = 1 - - return C - - -def build_noisy_circular_graph(N=20, mu=0, sigma=0.3, with_noise=False, structure_noise=False, p=None): - """ Create a noisy circular graph - """ - g = nx.Graph() - g.add_nodes_from(list(range(N))) - for i in range(N): - noise = float(np.random.normal(mu, sigma, 1)) - if with_noise: - g.add_node(i, attr_name=math.sin((2 * i * math.pi / N)) + noise) - else: - g.add_node(i, attr_name=math.sin(2 * i * math.pi / N)) - g.add_edge(i, i + 1) - if structure_noise: - randomint = np.random.randint(0, p) - if randomint == 0: - if i <= N - 3: - g.add_edge(i, i + 2) - if i == N - 2: - g.add_edge(i, 0) - if i == N - 1: - g.add_edge(i, 1) - g.add_edge(N, 0) - noise = float(np.random.normal(mu, sigma, 1)) - if with_noise: - g.add_node(N, attr_name=math.sin((2 * N * math.pi / N)) + noise) - else: - g.add_node(N, attr_name=math.sin(2 * N * math.pi / N)) - return g - - -def graph_colors(nx_graph, vmin=0, vmax=7): - cnorm = mcol.Normalize(vmin=vmin, vmax=vmax) - cpick = cm.ScalarMappable(norm=cnorm, cmap='viridis') - cpick.set_array([]) - val_map = {} - for k, v in nx.get_node_attributes(nx_graph, 'attr_name').items(): - val_map[k] = cpick.to_rgba(v) - colors = [] - for node in nx_graph.nodes(): - colors.append(val_map[node]) - return colors - -############################################################################## -# Generate data -# ------------- - -#%% circular dataset -# We build a dataset of noisy circular graphs. -# Noise is added on the structures by random connections and on the features by gaussian noise. - - -np.random.seed(30) -X0 = [] -for k in range(9): - X0.append(build_noisy_circular_graph(np.random.randint(15, 25), with_noise=True, structure_noise=True, p=3)) - -############################################################################## -# Plot data -# --------- - -#%% Plot graphs - -plt.figure(figsize=(8, 10)) -for i in range(len(X0)): - plt.subplot(3, 3, i + 1) - g = X0[i] - pos = nx.kamada_kawai_layout(g) - nx.draw(g, pos=pos, node_color=graph_colors(g, vmin=-1, vmax=1), with_labels=False, node_size=100) -plt.suptitle('Dataset of noisy graphs. Color indicates the label', fontsize=20) -plt.show() - -############################################################################## -# Barycenter computation -# ---------------------- - -#%% We compute the barycenter using FGW. Structure matrices are computed using the shortest_path distance in the graph -# Features distances are the euclidean distances -Cs = [shortest_path(nx.adjacency_matrix(x)) for x in X0] -ps = [np.ones(len(x.nodes())) / len(x.nodes()) for x in X0] -Ys = [np.array([v for (k, v) in nx.get_node_attributes(x, 'attr_name').items()]).reshape(-1, 1) for x in X0] -lambdas = np.array([np.ones(len(Ys)) / len(Ys)]).ravel() -sizebary = 15 # we choose a barycenter with 15 nodes - -A, C, log = fgw_barycenters(sizebary, Ys, Cs, ps, lambdas, alpha=0.95, log=True) - -############################################################################## -# Plot Barycenter -# ------------------------- - -#%% Create the barycenter -bary = nx.from_numpy_matrix(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0])) -for i, v in enumerate(A.ravel()): - bary.add_node(i, attr_name=v) - -#%% -pos = nx.kamada_kawai_layout(bary) -nx.draw(bary, pos=pos, node_color=graph_colors(bary, vmin=-1, vmax=1), with_labels=False) -plt.suptitle('Barycenter', fontsize=20) -plt.show() diff --git a/docs/source/auto_examples/plot_barycenter_fgw.rst b/docs/source/auto_examples/plot_barycenter_fgw.rst deleted file mode 100644 index ad4c275..0000000 --- a/docs/source/auto_examples/plot_barycenter_fgw.rst +++ /dev/null @@ -1,320 +0,0 @@ -.. 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_barycenter_fgw.py: - - -================================= -Plot graphs' barycenter using FGW -================================= - -This example illustrates the computation barycenter of labeled graphs using FGW - -Requires networkx >=2 - -.. [18] Vayer Titouan, Chapel Laetitia, Flamary R{'e}mi, Tavenard Romain - and Courty Nicolas - "Optimal Transport for structured data with application on graphs" - International Conference on Machine Learning (ICML). 2019. - - - -.. code-block:: default - - - # Author: Titouan Vayer - # - # License: MIT License - - - - - - - - - -.. code-block:: default - - import numpy as np - import matplotlib.pyplot as plt - import networkx as nx - import math - from scipy.sparse.csgraph import shortest_path - import matplotlib.colors as mcol - from matplotlib import cm - from ot.gromov import fgw_barycenters - - - - - - - - -.. code-block:: default - - - - def find_thresh(C, inf=0.5, sup=3, step=10): - """ Trick to find the adequate thresholds from where value of the C matrix are considered close enough to say that nodes are connected - Tthe threshold is found by a linesearch between values "inf" and "sup" with "step" thresholds tested. - The optimal threshold is the one which minimizes the reconstruction error between the shortest_path matrix coming from the thresholded adjency matrix - and the original matrix. - Parameters - ---------- - C : ndarray, shape (n_nodes,n_nodes) - The structure matrix to threshold - inf : float - The beginning of the linesearch - sup : float - The end of the linesearch - step : integer - Number of thresholds tested - """ - dist = [] - search = np.linspace(inf, sup, step) - for thresh in search: - Cprime = sp_to_adjency(C, 0, thresh) - SC = shortest_path(Cprime, method='D') - SC[SC == float('inf')] = 100 - dist.append(np.linalg.norm(SC - C)) - return search[np.argmin(dist)], dist - - - def sp_to_adjency(C, threshinf=0.2, threshsup=1.8): - """ Thresholds the structure matrix in order to compute an adjency matrix. - All values between threshinf and threshsup are considered representing connected nodes and set to 1. Else are set to 0 - Parameters - ---------- - C : ndarray, shape (n_nodes,n_nodes) - The structure matrix to threshold - threshinf : float - The minimum value of distance from which the new value is set to 1 - threshsup : float - The maximum value of distance from which the new value is set to 1 - Returns - ------- - C : ndarray, shape (n_nodes,n_nodes) - The threshold matrix. Each element is in {0,1} - """ - H = np.zeros_like(C) - np.fill_diagonal(H, np.diagonal(C)) - C = C - H - C = np.minimum(np.maximum(C, threshinf), threshsup) - C[C == threshsup] = 0 - C[C != 0] = 1 - - return C - - - def build_noisy_circular_graph(N=20, mu=0, sigma=0.3, with_noise=False, structure_noise=False, p=None): - """ Create a noisy circular graph - """ - g = nx.Graph() - g.add_nodes_from(list(range(N))) - for i in range(N): - noise = float(np.random.normal(mu, sigma, 1)) - if with_noise: - g.add_node(i, attr_name=math.sin((2 * i * math.pi / N)) + noise) - else: - g.add_node(i, attr_name=math.sin(2 * i * math.pi / N)) - g.add_edge(i, i + 1) - if structure_noise: - randomint = np.random.randint(0, p) - if randomint == 0: - if i <= N - 3: - g.add_edge(i, i + 2) - if i == N - 2: - g.add_edge(i, 0) - if i == N - 1: - g.add_edge(i, 1) - g.add_edge(N, 0) - noise = float(np.random.normal(mu, sigma, 1)) - if with_noise: - g.add_node(N, attr_name=math.sin((2 * N * math.pi / N)) + noise) - else: - g.add_node(N, attr_name=math.sin(2 * N * math.pi / N)) - return g - - - def graph_colors(nx_graph, vmin=0, vmax=7): - cnorm = mcol.Normalize(vmin=vmin, vmax=vmax) - cpick = cm.ScalarMappable(norm=cnorm, cmap='viridis') - cpick.set_array([]) - val_map = {} - for k, v in nx.get_node_attributes(nx_graph, 'attr_name').items(): - val_map[k] = cpick.to_rgba(v) - colors = [] - for node in nx_graph.nodes(): - colors.append(val_map[node]) - return colors - - - - - - - - -Generate data -------------- - -We build a dataset of noisy circular graphs. -Noise is added on the structures by random connections and on the features by gaussian noise. - - -.. code-block:: default - - - - np.random.seed(30) - X0 = [] - for k in range(9): - X0.append(build_noisy_circular_graph(np.random.randint(15, 25), with_noise=True, structure_noise=True, p=3)) - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - plt.figure(figsize=(8, 10)) - for i in range(len(X0)): - plt.subplot(3, 3, i + 1) - g = X0[i] - pos = nx.kamada_kawai_layout(g) - nx.draw(g, pos=pos, node_color=graph_colors(g, vmin=-1, vmax=1), with_labels=False, node_size=100) - plt.suptitle('Dataset of noisy graphs. Color indicates the label', fontsize=20) - plt.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_barycenter_fgw.py:155: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - plt.show() - - - - -Barycenter computation ----------------------- - -Features distances are the euclidean distances - - -.. code-block:: default - - Cs = [shortest_path(nx.adjacency_matrix(x)) for x in X0] - ps = [np.ones(len(x.nodes())) / len(x.nodes()) for x in X0] - Ys = [np.array([v for (k, v) in nx.get_node_attributes(x, 'attr_name').items()]).reshape(-1, 1) for x in X0] - lambdas = np.array([np.ones(len(Ys)) / len(Ys)]).ravel() - sizebary = 15 # we choose a barycenter with 15 nodes - - A, C, log = fgw_barycenters(sizebary, Ys, Cs, ps, lambdas, alpha=0.95, log=True) - - - - - - - - -Plot Barycenter -------------------------- - - -.. code-block:: default - - bary = nx.from_numpy_matrix(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0])) - for i, v in enumerate(A.ravel()): - bary.add_node(i, attr_name=v) - - - - - - - - - -.. code-block:: default - - pos = nx.kamada_kawai_layout(bary) - nx.draw(bary, pos=pos, node_color=graph_colors(bary, vmin=-1, vmax=1), with_labels=False) - plt.suptitle('Barycenter', fontsize=20) - plt.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_barycenter_fgw.py:184: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - plt.show() - - - - - -.. rst-class:: sphx-glr-timing - - **Total running time of the script:** ( 0 minutes 1.949 seconds) - - -.. _sphx_glr_download_auto_examples_plot_barycenter_fgw.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_barycenter_fgw.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_barycenter_fgw.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb deleted file mode 100644 index b976aae..0000000 --- a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb +++ /dev/null @@ -1,192 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 1D Wasserstein barycenter comparison between exact LP and entropic regularization\n\n\nThis example illustrates the computation of regularized Wasserstein Barycenter\nas proposed in [3] and exact LP barycenters using standard LP solver.\n\nIt reproduces approximately Figure 3.1 and 3.2 from the following paper:\nCuturi, M., & Peyr\u00e9, G. (2016). A smoothed dual approach for variational\nWasserstein problems. SIAM Journal on Imaging Sciences, 9(1), 320-343.\n\n[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyr\u00e9, G. (2015).\nIterative Bregman projections for regularized transportation problems\nSIAM Journal on Scientific Computing, 37(2), A1111-A1138.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\n# necessary for 3d plot even if not used\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nfrom matplotlib.collections import PolyCollection # noqa\n\n#import ot.lp.cvx as cvx" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Gaussian Data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "problems = []\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\n# Gaussian distributions\na1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.make_1D_gauss(n, m=60, s=8)\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "alpha = 0.5 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\not.tic()\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\not.toc()\n\n\not.tic()\nbary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True)\not.toc()\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\npl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()\n\nproblems.append([A, [bary_l2, bary_wass, bary_wass2]])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Stair Data\n----------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "a1 = 1.0 * (x > 10) * (x < 50)\na2 = 1.0 * (x > 60) * (x < 80)\n\na1 /= a1.sum()\na2 /= a2.sum()\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "alpha = 0.5 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\not.tic()\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\not.toc()\n\n\not.tic()\nbary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True)\not.toc()\n\n\nproblems.append([A, [bary_l2, bary_wass, bary_wass2]])\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\npl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Dirac Data\n----------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "a1 = np.zeros(n)\na2 = np.zeros(n)\n\na1[10] = .25\na1[20] = .5\na1[30] = .25\na2[80] = 1\n\n\na1 /= a1.sum()\na2 /= a2.sum()\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "alpha = 0.5 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\not.tic()\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\not.toc()\n\n\not.tic()\nbary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True)\not.toc()\n\n\nproblems.append([A, [bary_l2, bary_wass, bary_wass2]])\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\npl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Final figure\n------------\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "nbm = len(problems)\nnbm2 = (nbm // 2)\n\n\npl.figure(2, (20, 6))\npl.clf()\n\nfor i in range(nbm):\n\n A = problems[i][0]\n bary_l2 = problems[i][1][0]\n bary_wass = problems[i][1][1]\n bary_wass2 = problems[i][1][2]\n\n pl.subplot(2, nbm, 1 + i)\n for j in range(n_distributions):\n pl.plot(x, A[:, j])\n if i == nbm2:\n pl.title('Distributions')\n pl.xticks(())\n pl.yticks(())\n\n pl.subplot(2, nbm, 1 + i + nbm)\n\n pl.plot(x, bary_l2, 'r', label='L2 (Euclidean)')\n pl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\n pl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\n if i == nbm - 1:\n pl.legend()\n if i == nbm2:\n pl.title('Barycenters')\n\n pl.xticks(())\n pl.yticks(())" - ] - } - ], - "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_barycenter_lp_vs_entropic.py b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py deleted file mode 100644 index d7c72d0..0000000 --- a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py +++ /dev/null @@ -1,286 +0,0 @@ -# -*- coding: utf-8 -*- -""" -================================================================================= -1D Wasserstein barycenter comparison between exact LP and entropic regularization -================================================================================= - -This example illustrates the computation of regularized Wasserstein Barycenter -as proposed in [3] and exact LP barycenters using standard LP solver. - -It reproduces approximately Figure 3.1 and 3.2 from the following paper: -Cuturi, M., & Peyré, G. (2016). A smoothed dual approach for variational -Wasserstein problems. SIAM Journal on Imaging Sciences, 9(1), 320-343. - -[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyré, G. (2015). -Iterative Bregman projections for regularized transportation problems -SIAM Journal on Scientific Computing, 37(2), A1111-A1138. - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -# necessary for 3d plot even if not used -from mpl_toolkits.mplot3d import Axes3D # noqa -from matplotlib.collections import PolyCollection # noqa - -#import ot.lp.cvx as cvx - -############################################################################## -# Gaussian Data -# ------------- - -#%% parameters - -problems = [] - -n = 100 # nb bins - -# bin positions -x = np.arange(n, dtype=np.float64) - -# Gaussian distributions -# Gaussian distributions -a1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std -a2 = ot.datasets.make_1D_gauss(n, m=60, s=8) - -# creating matrix A containing all distributions -A = np.vstack((a1, a2)).T -n_distributions = A.shape[1] - -# loss matrix + normalization -M = ot.utils.dist0(n) -M /= M.max() - - -#%% plot the distributions - -pl.figure(1, figsize=(6.4, 3)) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') -pl.tight_layout() - -#%% barycenter computation - -alpha = 0.5 # 0<=alpha<=1 -weights = np.array([1 - alpha, alpha]) - -# l2bary -bary_l2 = A.dot(weights) - -# wasserstein -reg = 1e-3 -ot.tic() -bary_wass = ot.bregman.barycenter(A, M, reg, weights) -ot.toc() - - -ot.tic() -bary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True) -ot.toc() - -pl.figure(2) -pl.clf() -pl.subplot(2, 1, 1) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') - -pl.subplot(2, 1, 2) -pl.plot(x, bary_l2, 'r', label='l2') -pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') -pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') -pl.legend() -pl.title('Barycenters') -pl.tight_layout() - -problems.append([A, [bary_l2, bary_wass, bary_wass2]]) - -############################################################################## -# Stair Data -# ---------- - -#%% parameters - -a1 = 1.0 * (x > 10) * (x < 50) -a2 = 1.0 * (x > 60) * (x < 80) - -a1 /= a1.sum() -a2 /= a2.sum() - -# creating matrix A containing all distributions -A = np.vstack((a1, a2)).T -n_distributions = A.shape[1] - -# loss matrix + normalization -M = ot.utils.dist0(n) -M /= M.max() - - -#%% plot the distributions - -pl.figure(1, figsize=(6.4, 3)) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') -pl.tight_layout() - - -#%% barycenter computation - -alpha = 0.5 # 0<=alpha<=1 -weights = np.array([1 - alpha, alpha]) - -# l2bary -bary_l2 = A.dot(weights) - -# wasserstein -reg = 1e-3 -ot.tic() -bary_wass = ot.bregman.barycenter(A, M, reg, weights) -ot.toc() - - -ot.tic() -bary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True) -ot.toc() - - -problems.append([A, [bary_l2, bary_wass, bary_wass2]]) - -pl.figure(2) -pl.clf() -pl.subplot(2, 1, 1) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') - -pl.subplot(2, 1, 2) -pl.plot(x, bary_l2, 'r', label='l2') -pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') -pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') -pl.legend() -pl.title('Barycenters') -pl.tight_layout() - - -############################################################################## -# Dirac Data -# ---------- - -#%% parameters - -a1 = np.zeros(n) -a2 = np.zeros(n) - -a1[10] = .25 -a1[20] = .5 -a1[30] = .25 -a2[80] = 1 - - -a1 /= a1.sum() -a2 /= a2.sum() - -# creating matrix A containing all distributions -A = np.vstack((a1, a2)).T -n_distributions = A.shape[1] - -# loss matrix + normalization -M = ot.utils.dist0(n) -M /= M.max() - - -#%% plot the distributions - -pl.figure(1, figsize=(6.4, 3)) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') -pl.tight_layout() - - -#%% barycenter computation - -alpha = 0.5 # 0<=alpha<=1 -weights = np.array([1 - alpha, alpha]) - -# l2bary -bary_l2 = A.dot(weights) - -# wasserstein -reg = 1e-3 -ot.tic() -bary_wass = ot.bregman.barycenter(A, M, reg, weights) -ot.toc() - - -ot.tic() -bary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True) -ot.toc() - - -problems.append([A, [bary_l2, bary_wass, bary_wass2]]) - -pl.figure(2) -pl.clf() -pl.subplot(2, 1, 1) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') - -pl.subplot(2, 1, 2) -pl.plot(x, bary_l2, 'r', label='l2') -pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') -pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') -pl.legend() -pl.title('Barycenters') -pl.tight_layout() - - -############################################################################## -# Final figure -# ------------ -# - -#%% plot - -nbm = len(problems) -nbm2 = (nbm // 2) - - -pl.figure(2, (20, 6)) -pl.clf() - -for i in range(nbm): - - A = problems[i][0] - bary_l2 = problems[i][1][0] - bary_wass = problems[i][1][1] - bary_wass2 = problems[i][1][2] - - pl.subplot(2, nbm, 1 + i) - for j in range(n_distributions): - pl.plot(x, A[:, j]) - if i == nbm2: - pl.title('Distributions') - pl.xticks(()) - pl.yticks(()) - - pl.subplot(2, nbm, 1 + i + nbm) - - pl.plot(x, bary_l2, 'r', label='L2 (Euclidean)') - pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') - pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') - if i == nbm - 1: - pl.legend() - if i == nbm2: - pl.title('Barycenters') - - pl.xticks(()) - pl.yticks(()) diff --git a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst deleted file mode 100644 index 5e83fbf..0000000 --- a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst +++ /dev/null @@ -1,532 +0,0 @@ -.. 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_barycenter_lp_vs_entropic.py: - - -================================================================================= -1D Wasserstein barycenter comparison between exact LP and entropic regularization -================================================================================= - -This example illustrates the computation of regularized Wasserstein Barycenter -as proposed in [3] and exact LP barycenters using standard LP solver. - -It reproduces approximately Figure 3.1 and 3.2 from the following paper: -Cuturi, M., & Peyré, G. (2016). A smoothed dual approach for variational -Wasserstein problems. SIAM Journal on Imaging Sciences, 9(1), 320-343. - -[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyré, G. (2015). -Iterative Bregman projections for regularized transportation problems -SIAM Journal on Scientific Computing, 37(2), A1111-A1138. - - - -.. code-block:: default - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - # necessary for 3d plot even if not used - from mpl_toolkits.mplot3d import Axes3D # noqa - from matplotlib.collections import PolyCollection # noqa - - #import ot.lp.cvx as cvx - - - - - - - - -Gaussian Data -------------- - - -.. code-block:: default - - - problems = [] - - n = 100 # nb bins - - # bin positions - x = np.arange(n, dtype=np.float64) - - # Gaussian distributions - # Gaussian distributions - a1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std - a2 = ot.datasets.make_1D_gauss(n, m=60, s=8) - - # creating matrix A containing all distributions - A = np.vstack((a1, a2)).T - n_distributions = A.shape[1] - - # loss matrix + normalization - M = ot.utils.dist0(n) - M /= M.max() - - - - - - - - - - -.. code-block:: default - - - pl.figure(1, figsize=(6.4, 3)) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - pl.tight_layout() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png - :class: sphx-glr-single-img - - - - - - -.. code-block:: default - - - alpha = 0.5 # 0<=alpha<=1 - weights = np.array([1 - alpha, alpha]) - - # l2bary - bary_l2 = A.dot(weights) - - # wasserstein - reg = 1e-3 - ot.tic() - bary_wass = ot.bregman.barycenter(A, M, reg, weights) - ot.toc() - - - ot.tic() - bary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True) - ot.toc() - - pl.figure(2) - pl.clf() - pl.subplot(2, 1, 1) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - - pl.subplot(2, 1, 2) - pl.plot(x, bary_l2, 'r', label='l2') - pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') - pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') - pl.legend() - pl.title('Barycenters') - pl.tight_layout() - - problems.append([A, [bary_l2, bary_wass, bary_wass2]]) - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - Elapsed time : 0.0049059391021728516 s - Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective - 1.0 1.0 1.0 - 1.0 1700.336700337 - 0.006776453137632 0.006776453137632 0.006776453137632 0.9932238647293 0.006776453137632 125.6700527543 - 0.004018712867873 0.004018712867873 0.004018712867873 0.4301142633001 0.004018712867873 12.26594150092 - 0.001172775061627 0.001172775061627 0.001172775061627 0.7599932455027 0.001172775061627 0.3378536968898 - 0.0004375137005386 0.0004375137005386 0.0004375137005386 0.6422331807989 0.0004375137005386 0.1468420566359 - 0.0002326690467339 0.0002326690467339 0.0002326690467339 0.5016999460898 0.0002326690467339 0.09381703231428 - 7.430121674299e-05 7.4301216743e-05 7.430121674299e-05 0.7035962305811 7.430121674299e-05 0.05777870257169 - 5.321227838943e-05 5.321227838945e-05 5.321227838944e-05 0.3087841864307 5.321227838944e-05 0.05266249477219 - 1.990900379216e-05 1.99090037922e-05 1.990900379216e-05 0.6520472013271 1.990900379216e-05 0.04526054405523 - 6.305442046834e-06 6.305442046856e-06 6.305442046837e-06 0.7073953304085 6.305442046837e-06 0.04237597591384 - 2.290148391591e-06 2.290148391631e-06 2.290148391602e-06 0.6941812711476 2.29014839161e-06 0.04152284932101 - 1.182864875578e-06 1.182864875548e-06 1.182864875555e-06 0.5084552046229 1.182864875567e-06 0.04129461872829 - 3.626786386894e-07 3.626786386985e-07 3.626786386845e-07 0.7101651569095 3.626786385995e-07 0.0411303244893 - 1.539754244475e-07 1.539754247164e-07 1.539754247197e-07 0.6279322077522 1.539754251915e-07 0.04108867636377 - 5.193221608537e-08 5.19322169648e-08 5.193221696942e-08 0.6843453280956 5.193221892276e-08 0.04106859618454 - 1.888205219929e-08 1.88820500654e-08 1.888205006369e-08 0.6673443828803 1.888205852187e-08 0.04106214175236 - 5.676837529301e-09 5.676842740457e-09 5.676842761502e-09 0.7281712198286 5.676877044229e-09 0.04105958648535 - 3.501170987746e-09 3.501167688027e-09 3.501167721804e-09 0.4140142115019 3.501183058995e-09 0.04105916265728 - 1.110582426269e-09 1.110580273241e-09 1.110580239523e-09 0.6999003212726 1.110624310022e-09 0.04105870073273 - 5.768753963318e-10 5.769422203363e-10 5.769421938248e-10 0.5002521235315 5.767522037401e-10 0.04105859764872 - 1.534102102874e-10 1.535920569433e-10 1.535921107494e-10 0.7516900610544 1.535251083958e-10 0.04105851678411 - 6.717475002202e-11 6.735435784522e-11 6.735430717133e-11 0.5944268235824 6.732253215483e-11 0.04105850033323 - 1.751321118837e-11 1.74043080851e-11 1.740429001123e-11 0.7566075167358 1.736956306927e-11 0.0410584908946 - Optimization terminated successfully. - Current function value: 0.041058 - Iterations: 22 - Elapsed time : 2.149055242538452 s - - - - -Stair Data ----------- - - -.. code-block:: default - - - a1 = 1.0 * (x > 10) * (x < 50) - a2 = 1.0 * (x > 60) * (x < 80) - - a1 /= a1.sum() - a2 /= a2.sum() - - # creating matrix A containing all distributions - A = np.vstack((a1, a2)).T - n_distributions = A.shape[1] - - # loss matrix + normalization - M = ot.utils.dist0(n) - M /= M.max() - - - - - - - - - - -.. code-block:: default - - - pl.figure(1, figsize=(6.4, 3)) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png - :class: sphx-glr-single-img - - - - - - -.. code-block:: default - - - alpha = 0.5 # 0<=alpha<=1 - weights = np.array([1 - alpha, alpha]) - - # l2bary - bary_l2 = A.dot(weights) - - # wasserstein - reg = 1e-3 - ot.tic() - bary_wass = ot.bregman.barycenter(A, M, reg, weights) - ot.toc() - - - ot.tic() - bary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True) - ot.toc() - - - problems.append([A, [bary_l2, bary_wass, bary_wass2]]) - - pl.figure(2) - pl.clf() - pl.subplot(2, 1, 1) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - - pl.subplot(2, 1, 2) - pl.plot(x, bary_l2, 'r', label='l2') - pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') - pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') - pl.legend() - pl.title('Barycenters') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - Elapsed time : 0.008316993713378906 s - Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective - 1.0 1.0 1.0 - 1.0 1700.336700337 - 0.006776466288938 0.006776466288938 0.006776466288938 0.9932238515788 0.006776466288938 125.66492558 - 0.004036918865472 0.004036918865472 0.004036918865472 0.4272973099325 0.004036918865472 12.347161701 - 0.001219232687076 0.001219232687076 0.001219232687076 0.7496986855957 0.001219232687076 0.3243835647418 - 0.0003837422984467 0.0003837422984467 0.0003837422984467 0.6926882608271 0.0003837422984467 0.1361719397498 - 0.0001070128410194 0.0001070128410194 0.0001070128410194 0.7643889137854 0.0001070128410194 0.07581952832542 - 0.0001001275033713 0.0001001275033714 0.0001001275033713 0.07058704838615 0.0001001275033713 0.07347394936346 - 4.550897507807e-05 4.550897507807e-05 4.550897507807e-05 0.576117248486 4.550897507807e-05 0.05555077655034 - 8.557124125834e-06 8.557124125853e-06 8.557124125835e-06 0.853592544106 8.557124125835e-06 0.0443981466023 - 3.611995628666e-06 3.611995628643e-06 3.611995628672e-06 0.6002277331398 3.611995628673e-06 0.0428300776216 - 7.590393750111e-07 7.590393750273e-07 7.590393750129e-07 0.8221486533655 7.590393750133e-07 0.04192322976247 - 8.299929287077e-08 8.299929283415e-08 8.299929287126e-08 0.901746793884 8.299929287181e-08 0.04170825633295 - 3.117560207452e-10 3.117560192413e-10 3.117560199213e-10 0.9970399692253 3.117560200234e-10 0.04168179329766 - 1.559774508975e-14 1.559825507727e-14 1.559755309294e-14 0.9999499686993 1.559748033629e-14 0.04168169240444 - Optimization terminated successfully. - Current function value: 0.041682 - Iterations: 13 - Elapsed time : 2.0333712100982666 s - - - - -Dirac Data ----------- - - -.. code-block:: default - - - a1 = np.zeros(n) - a2 = np.zeros(n) - - a1[10] = .25 - a1[20] = .5 - a1[30] = .25 - a2[80] = 1 - - - a1 /= a1.sum() - a2 /= a2.sum() - - # creating matrix A containing all distributions - A = np.vstack((a1, a2)).T - n_distributions = A.shape[1] - - # loss matrix + normalization - M = ot.utils.dist0(n) - M /= M.max() - - - - - - - - - - -.. code-block:: default - - - pl.figure(1, figsize=(6.4, 3)) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png - :class: sphx-glr-single-img - - - - - - -.. code-block:: default - - - alpha = 0.5 # 0<=alpha<=1 - weights = np.array([1 - alpha, alpha]) - - # l2bary - bary_l2 = A.dot(weights) - - # wasserstein - reg = 1e-3 - ot.tic() - bary_wass = ot.bregman.barycenter(A, M, reg, weights) - ot.toc() - - - ot.tic() - bary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True) - ot.toc() - - - problems.append([A, [bary_l2, bary_wass, bary_wass2]]) - - pl.figure(2) - pl.clf() - pl.subplot(2, 1, 1) - for i in range(n_distributions): - pl.plot(x, A[:, i]) - pl.title('Distributions') - - pl.subplot(2, 1, 2) - pl.plot(x, bary_l2, 'r', label='l2') - pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') - pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') - pl.legend() - pl.title('Barycenters') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - Elapsed time : 0.001787424087524414 s - Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective - 1.0 1.0 1.0 - 1.0 1700.336700337 - 0.00677467552072 0.006774675520719 0.006774675520719 0.9932256422636 0.006774675520719 125.6956034741 - 0.002048208707556 0.002048208707555 0.002048208707555 0.734309536815 0.002048208707555 5.213991622102 - 0.0002697365474791 0.0002697365474791 0.0002697365474791 0.8839403501183 0.0002697365474791 0.5059383903908 - 6.832109993919e-05 6.832109993918e-05 6.832109993918e-05 0.7601171075982 6.832109993918e-05 0.2339657807271 - 2.437682932221e-05 2.437682932221e-05 2.437682932221e-05 0.6663448297463 2.437682932221e-05 0.1471256246325 - 1.134983216308e-05 1.134983216308e-05 1.134983216308e-05 0.5553643816417 1.134983216308e-05 0.1181584941171 - 3.342312725863e-06 3.34231272585e-06 3.342312725863e-06 0.7238133571629 3.342312725863e-06 0.1006387519746 - 7.078561231536e-07 7.078561231537e-07 7.078561231535e-07 0.803314255252 7.078561231535e-07 0.09474734646268 - 1.966870949422e-07 1.966870952674e-07 1.966870952717e-07 0.7525479180433 1.966870953014e-07 0.09354342735758 - 4.199895266495e-10 4.199895367352e-10 4.19989526535e-10 0.9984019849265 4.199895265747e-10 0.09310367785861 - 2.101053559204e-14 2.100331212975e-14 2.101054034304e-14 0.9999499736903 2.101053604307e-14 0.09310274466458 - Optimization terminated successfully. - Current function value: 0.093103 - Iterations: 11 - Elapsed time : 2.1853578090667725 s - - - - -Final figure ------------- - - - -.. code-block:: default - - - nbm = len(problems) - nbm2 = (nbm // 2) - - - pl.figure(2, (20, 6)) - pl.clf() - - for i in range(nbm): - - A = problems[i][0] - bary_l2 = problems[i][1][0] - bary_wass = problems[i][1][1] - bary_wass2 = problems[i][1][2] - - pl.subplot(2, nbm, 1 + i) - for j in range(n_distributions): - pl.plot(x, A[:, j]) - if i == nbm2: - pl.title('Distributions') - pl.xticks(()) - pl.yticks(()) - - pl.subplot(2, nbm, 1 + i + nbm) - - pl.plot(x, bary_l2, 'r', label='L2 (Euclidean)') - pl.plot(x, bary_wass, 'g', label='Reg Wasserstein') - pl.plot(x, bary_wass2, 'b', label='LP Wasserstein') - if i == nbm - 1: - pl.legend() - if i == nbm2: - pl.title('Barycenters') - - pl.xticks(()) - pl.yticks(()) - - - -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png - :class: sphx-glr-single-img - - - - - - -.. rst-class:: sphx-glr-timing - - **Total running time of the script:** ( 0 minutes 7.697 seconds) - - -.. _sphx_glr_download_auto_examples_plot_barycenter_lp_vs_entropic.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_barycenter_lp_vs_entropic.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_barycenter_lp_vs_entropic.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_compute_emd.ipynb b/docs/source/auto_examples/plot_compute_emd.ipynb deleted file mode 100644 index 24a2fff..0000000 --- a/docs/source/auto_examples/plot_compute_emd.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Plot multiple EMD\n\n\nShows how to compute multiple EMD and Sinkhorn with two differnt\nground metrics and plot their values for diffeent distributions.\n\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nfrom ot.datasets import make_1D_gauss as gauss" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 100 # nb bins\nn_target = 50 # nb target distributions\n\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\nlst_m = np.linspace(20, 90, n_target)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\n\nB = np.zeros((n, n_target))\n\nfor i, m in enumerate(lst_m):\n B[:, i] = gauss(n, m=m, s=5)\n\n# loss matrix and normalization\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'euclidean')\nM /= M.max()\nM2 = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'sqeuclidean')\nM2 /= M2.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1)\npl.subplot(2, 1, 1)\npl.plot(x, a, 'b', label='Source distribution')\npl.title('Source distribution')\npl.subplot(2, 1, 2)\npl.plot(x, B, label='Target distributions')\npl.title('Target distributions')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute EMD for the different losses\n------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "d_emd = ot.emd2(a, B, M) # direct computation of EMD\nd_emd2 = ot.emd2(a, B, M2) # direct computation of EMD with loss M2\n\n\npl.figure(2)\npl.plot(d_emd, label='Euclidean EMD')\npl.plot(d_emd2, label='Squared Euclidean EMD')\npl.title('EMD distances')\npl.legend()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute Sinkhorn for the different losses\n-----------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "reg = 1e-2\nd_sinkhorn = ot.sinkhorn2(a, B, M, reg)\nd_sinkhorn2 = ot.sinkhorn2(a, B, M2, reg)\n\npl.figure(2)\npl.clf()\npl.plot(d_emd, label='Euclidean EMD')\npl.plot(d_emd2, label='Squared Euclidean EMD')\npl.plot(d_sinkhorn, '+', label='Euclidean Sinkhorn')\npl.plot(d_sinkhorn2, '+', label='Squared Euclidean Sinkhorn')\npl.title('EMD distances')\npl.legend()\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_compute_emd.py b/docs/source/auto_examples/plot_compute_emd.py deleted file mode 100644 index 7ed2b01..0000000 --- a/docs/source/auto_examples/plot_compute_emd.py +++ /dev/null @@ -1,102 +0,0 @@ -# -*- coding: utf-8 -*- -""" -================= -Plot multiple EMD -================= - -Shows how to compute multiple EMD and Sinkhorn with two differnt -ground metrics and plot their values for diffeent distributions. - - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -from ot.datasets import make_1D_gauss as gauss - - -############################################################################## -# Generate data -# ------------- - -#%% parameters - -n = 100 # nb bins -n_target = 50 # nb target distributions - - -# bin positions -x = np.arange(n, dtype=np.float64) - -lst_m = np.linspace(20, 90, n_target) - -# Gaussian distributions -a = gauss(n, m=20, s=5) # m= mean, s= std - -B = np.zeros((n, n_target)) - -for i, m in enumerate(lst_m): - B[:, i] = gauss(n, m=m, s=5) - -# loss matrix and normalization -M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'euclidean') -M /= M.max() -M2 = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'sqeuclidean') -M2 /= M2.max() - -############################################################################## -# Plot data -# --------- - -#%% plot the distributions - -pl.figure(1) -pl.subplot(2, 1, 1) -pl.plot(x, a, 'b', label='Source distribution') -pl.title('Source distribution') -pl.subplot(2, 1, 2) -pl.plot(x, B, label='Target distributions') -pl.title('Target distributions') -pl.tight_layout() - - -############################################################################## -# Compute EMD for the different losses -# ------------------------------------ - -#%% Compute and plot distributions and loss matrix - -d_emd = ot.emd2(a, B, M) # direct computation of EMD -d_emd2 = ot.emd2(a, B, M2) # direct computation of EMD with loss M2 - - -pl.figure(2) -pl.plot(d_emd, label='Euclidean EMD') -pl.plot(d_emd2, label='Squared Euclidean EMD') -pl.title('EMD distances') -pl.legend() - -############################################################################## -# Compute Sinkhorn for the different losses -# ----------------------------------------- - -#%% -reg = 1e-2 -d_sinkhorn = ot.sinkhorn2(a, B, M, reg) -d_sinkhorn2 = ot.sinkhorn2(a, B, M2, reg) - -pl.figure(2) -pl.clf() -pl.plot(d_emd, label='Euclidean EMD') -pl.plot(d_emd2, label='Squared Euclidean EMD') -pl.plot(d_sinkhorn, '+', label='Euclidean Sinkhorn') -pl.plot(d_sinkhorn2, '+', label='Squared Euclidean Sinkhorn') -pl.title('EMD distances') -pl.legend() - -pl.show() diff --git a/docs/source/auto_examples/plot_compute_emd.rst b/docs/source/auto_examples/plot_compute_emd.rst deleted file mode 100644 index e4cc143..0000000 --- a/docs/source/auto_examples/plot_compute_emd.rst +++ /dev/null @@ -1,211 +0,0 @@ -.. 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_compute_emd.py: - - -================= -Plot multiple EMD -================= - -Shows how to compute multiple EMD and Sinkhorn with two differnt -ground metrics and plot their values for diffeent distributions. - - - - -.. code-block:: default - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - from ot.datasets import make_1D_gauss as gauss - - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - n = 100 # nb bins - n_target = 50 # nb target distributions - - - # bin positions - x = np.arange(n, dtype=np.float64) - - lst_m = np.linspace(20, 90, n_target) - - # Gaussian distributions - a = gauss(n, m=20, s=5) # m= mean, s= std - - B = np.zeros((n, n_target)) - - for i, m in enumerate(lst_m): - B[:, i] = gauss(n, m=m, s=5) - - # loss matrix and normalization - M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'euclidean') - M /= M.max() - M2 = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'sqeuclidean') - M2 /= M2.max() - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - pl.figure(1) - pl.subplot(2, 1, 1) - pl.plot(x, a, 'b', label='Source distribution') - pl.title('Source distribution') - pl.subplot(2, 1, 2) - pl.plot(x, B, label='Target distributions') - pl.title('Target distributions') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_compute_emd_001.png - :class: sphx-glr-single-img - - - - - -Compute EMD for the different losses ------------------------------------- - - -.. code-block:: default - - - d_emd = ot.emd2(a, B, M) # direct computation of EMD - d_emd2 = ot.emd2(a, B, M2) # direct computation of EMD with loss M2 - - - pl.figure(2) - pl.plot(d_emd, label='Euclidean EMD') - pl.plot(d_emd2, label='Squared Euclidean EMD') - pl.title('EMD distances') - pl.legend() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_compute_emd_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - - - - -Compute Sinkhorn for the different losses ------------------------------------------ - - -.. code-block:: default - - reg = 1e-2 - d_sinkhorn = ot.sinkhorn2(a, B, M, reg) - d_sinkhorn2 = ot.sinkhorn2(a, B, M2, reg) - - pl.figure(2) - pl.clf() - pl.plot(d_emd, label='Euclidean EMD') - pl.plot(d_emd2, label='Squared Euclidean EMD') - pl.plot(d_sinkhorn, '+', label='Euclidean Sinkhorn') - pl.plot(d_sinkhorn2, '+', label='Squared Euclidean Sinkhorn') - pl.title('EMD distances') - pl.legend() - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_compute_emd_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_compute_emd.py:102: 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 0.436 seconds) - - -.. _sphx_glr_download_auto_examples_plot_compute_emd.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_compute_emd.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_compute_emd.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_convolutional_barycenter.ipynb b/docs/source/auto_examples/plot_convolutional_barycenter.ipynb deleted file mode 100644 index f94a32e..0000000 --- a/docs/source/auto_examples/plot_convolutional_barycenter.ipynb +++ /dev/null @@ -1,90 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Convolutional Wasserstein Barycenter example\n\n\nThis example is designed to illustrate how the Convolutional Wasserstein Barycenter\nfunction of POT works.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Nicolas Courty \n#\n# License: MIT License\n\n\nimport numpy as np\nimport pylab as pl\nimport ot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Data preparation\n----------------\n\nThe four distributions are constructed from 4 simple images\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f1 = 1 - pl.imread('../data/redcross.png')[:, :, 2]\nf2 = 1 - pl.imread('../data/duck.png')[:, :, 2]\nf3 = 1 - pl.imread('../data/heart.png')[:, :, 2]\nf4 = 1 - pl.imread('../data/tooth.png')[:, :, 2]\n\nA = []\nf1 = f1 / np.sum(f1)\nf2 = f2 / np.sum(f2)\nf3 = f3 / np.sum(f3)\nf4 = f4 / np.sum(f4)\nA.append(f1)\nA.append(f2)\nA.append(f3)\nA.append(f4)\nA = np.array(A)\n\nnb_images = 5\n\n# those are the four corners coordinates that will be interpolated by bilinear\n# interpolation\nv1 = np.array((1, 0, 0, 0))\nv2 = np.array((0, 1, 0, 0))\nv3 = np.array((0, 0, 1, 0))\nv4 = np.array((0, 0, 0, 1))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Barycenter computation and visualization\n----------------------------------------\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(figsize=(10, 10))\npl.title('Convolutional Wasserstein Barycenters in POT')\ncm = 'Blues'\n# regularization parameter\nreg = 0.004\nfor i in range(nb_images):\n for j in range(nb_images):\n pl.subplot(nb_images, nb_images, i * nb_images + j + 1)\n tx = float(i) / (nb_images - 1)\n ty = float(j) / (nb_images - 1)\n\n # weights are constructed by bilinear interpolation\n tmp1 = (1 - tx) * v1 + tx * v2\n tmp2 = (1 - tx) * v3 + tx * v4\n weights = (1 - ty) * tmp1 + ty * tmp2\n\n if i == 0 and j == 0:\n pl.imshow(f1, cmap=cm)\n pl.axis('off')\n elif i == 0 and j == (nb_images - 1):\n pl.imshow(f3, cmap=cm)\n pl.axis('off')\n elif i == (nb_images - 1) and j == 0:\n pl.imshow(f2, cmap=cm)\n pl.axis('off')\n elif i == (nb_images - 1) and j == (nb_images - 1):\n pl.imshow(f4, cmap=cm)\n pl.axis('off')\n else:\n # call to barycenter computation\n pl.imshow(ot.bregman.convolutional_barycenter2d(A, reg, weights), cmap=cm)\n pl.axis('off')\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_convolutional_barycenter.py b/docs/source/auto_examples/plot_convolutional_barycenter.py deleted file mode 100644 index e74db04..0000000 --- a/docs/source/auto_examples/plot_convolutional_barycenter.py +++ /dev/null @@ -1,92 +0,0 @@ - -#%% -# -*- coding: utf-8 -*- -""" -============================================ -Convolutional Wasserstein Barycenter example -============================================ - -This example is designed to illustrate how the Convolutional Wasserstein Barycenter -function of POT works. -""" - -# Author: Nicolas Courty -# -# License: MIT License - - -import numpy as np -import pylab as pl -import ot - -############################################################################## -# Data preparation -# ---------------- -# -# The four distributions are constructed from 4 simple images - - -f1 = 1 - pl.imread('../data/redcross.png')[:, :, 2] -f2 = 1 - pl.imread('../data/duck.png')[:, :, 2] -f3 = 1 - pl.imread('../data/heart.png')[:, :, 2] -f4 = 1 - pl.imread('../data/tooth.png')[:, :, 2] - -A = [] -f1 = f1 / np.sum(f1) -f2 = f2 / np.sum(f2) -f3 = f3 / np.sum(f3) -f4 = f4 / np.sum(f4) -A.append(f1) -A.append(f2) -A.append(f3) -A.append(f4) -A = np.array(A) - -nb_images = 5 - -# those are the four corners coordinates that will be interpolated by bilinear -# interpolation -v1 = np.array((1, 0, 0, 0)) -v2 = np.array((0, 1, 0, 0)) -v3 = np.array((0, 0, 1, 0)) -v4 = np.array((0, 0, 0, 1)) - - -############################################################################## -# Barycenter computation and visualization -# ---------------------------------------- -# - -pl.figure(figsize=(10, 10)) -pl.title('Convolutional Wasserstein Barycenters in POT') -cm = 'Blues' -# regularization parameter -reg = 0.004 -for i in range(nb_images): - for j in range(nb_images): - pl.subplot(nb_images, nb_images, i * nb_images + j + 1) - tx = float(i) / (nb_images - 1) - ty = float(j) / (nb_images - 1) - - # weights are constructed by bilinear interpolation - tmp1 = (1 - tx) * v1 + tx * v2 - tmp2 = (1 - tx) * v3 + tx * v4 - weights = (1 - ty) * tmp1 + ty * tmp2 - - if i == 0 and j == 0: - pl.imshow(f1, cmap=cm) - pl.axis('off') - elif i == 0 and j == (nb_images - 1): - pl.imshow(f3, cmap=cm) - pl.axis('off') - elif i == (nb_images - 1) and j == 0: - pl.imshow(f2, cmap=cm) - pl.axis('off') - elif i == (nb_images - 1) and j == (nb_images - 1): - pl.imshow(f4, cmap=cm) - pl.axis('off') - else: - # call to barycenter computation - pl.imshow(ot.bregman.convolutional_barycenter2d(A, reg, weights), cmap=cm) - pl.axis('off') -pl.show() diff --git a/docs/source/auto_examples/plot_convolutional_barycenter.rst b/docs/source/auto_examples/plot_convolutional_barycenter.rst deleted file mode 100644 index 9c9a596..0000000 --- a/docs/source/auto_examples/plot_convolutional_barycenter.rst +++ /dev/null @@ -1,173 +0,0 @@ -.. 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_convolutional_barycenter.py: - - -============================================ -Convolutional Wasserstein Barycenter example -============================================ - -This example is designed to illustrate how the Convolutional Wasserstein Barycenter -function of POT works. - - -.. code-block:: default - - - # Author: Nicolas Courty - # - # License: MIT License - - - import numpy as np - import pylab as pl - import ot - - - - - - - - -Data preparation ----------------- - -The four distributions are constructed from 4 simple images - - -.. code-block:: default - - - - f1 = 1 - pl.imread('../data/redcross.png')[:, :, 2] - f2 = 1 - pl.imread('../data/duck.png')[:, :, 2] - f3 = 1 - pl.imread('../data/heart.png')[:, :, 2] - f4 = 1 - pl.imread('../data/tooth.png')[:, :, 2] - - A = [] - f1 = f1 / np.sum(f1) - f2 = f2 / np.sum(f2) - f3 = f3 / np.sum(f3) - f4 = f4 / np.sum(f4) - A.append(f1) - A.append(f2) - A.append(f3) - A.append(f4) - A = np.array(A) - - nb_images = 5 - - # those are the four corners coordinates that will be interpolated by bilinear - # interpolation - v1 = np.array((1, 0, 0, 0)) - v2 = np.array((0, 1, 0, 0)) - v3 = np.array((0, 0, 1, 0)) - v4 = np.array((0, 0, 0, 1)) - - - - - - - - - -Barycenter computation and visualization ----------------------------------------- - - - -.. code-block:: default - - - pl.figure(figsize=(10, 10)) - pl.title('Convolutional Wasserstein Barycenters in POT') - cm = 'Blues' - # regularization parameter - reg = 0.004 - for i in range(nb_images): - for j in range(nb_images): - pl.subplot(nb_images, nb_images, i * nb_images + j + 1) - tx = float(i) / (nb_images - 1) - ty = float(j) / (nb_images - 1) - - # weights are constructed by bilinear interpolation - tmp1 = (1 - tx) * v1 + tx * v2 - tmp2 = (1 - tx) * v3 + tx * v4 - weights = (1 - ty) * tmp1 + ty * tmp2 - - if i == 0 and j == 0: - pl.imshow(f1, cmap=cm) - pl.axis('off') - elif i == 0 and j == (nb_images - 1): - pl.imshow(f3, cmap=cm) - pl.axis('off') - elif i == (nb_images - 1) and j == 0: - pl.imshow(f2, cmap=cm) - pl.axis('off') - elif i == (nb_images - 1) and j == (nb_images - 1): - pl.imshow(f4, cmap=cm) - pl.axis('off') - else: - # call to barycenter computation - pl.imshow(ot.bregman.convolutional_barycenter2d(A, reg, weights), cmap=cm) - pl.axis('off') - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_convolutional_barycenter.py:92: 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 34.615 seconds) - - -.. _sphx_glr_download_auto_examples_plot_convolutional_barycenter.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_convolutional_barycenter.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_convolutional_barycenter.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_fgw.ipynb b/docs/source/auto_examples/plot_fgw.ipynb deleted file mode 100644 index 20c0a3f..0000000 --- a/docs/source/auto_examples/plot_fgw.ipynb +++ /dev/null @@ -1,169 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Plot Fused-gromov-Wasserstein\n\n\nThis example illustrates the computation of FGW for 1D measures[18].\n\n.. [18] Vayer Titouan, Chapel Laetitia, Flamary R{'e}mi, Tavenard Romain\n and Courty Nicolas\n \"Optimal Transport for structured data with application on graphs\"\n International Conference on Machine Learning (ICML). 2019.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Titouan Vayer \n#\n# License: MIT License\n\nimport matplotlib.pyplot as pl\nimport numpy as np\nimport ot\nfrom ot.gromov import gromov_wasserstein, fused_gromov_wasserstein" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n---------\n\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We create two 1D random measures\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 20 # number of points in the first distribution\nn2 = 30 # number of points in the second distribution\nsig = 1 # std of first distribution\nsig2 = 0.1 # std of second distribution\n\nnp.random.seed(0)\n\nphi = np.arange(n)[:, None]\nxs = phi + sig * np.random.randn(n, 1)\nys = np.vstack((np.ones((n // 2, 1)), 0 * np.ones((n // 2, 1)))) + sig2 * np.random.randn(n, 1)\n\nphi2 = np.arange(n2)[:, None]\nxt = phi2 + sig * np.random.randn(n2, 1)\nyt = np.vstack((np.ones((n2 // 2, 1)), 0 * np.ones((n2 // 2, 1)))) + sig2 * np.random.randn(n2, 1)\nyt = yt[::-1, :]\n\np = ot.unif(n)\nq = ot.unif(n2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.close(10)\npl.figure(10, (7, 7))\n\npl.subplot(2, 1, 1)\n\npl.scatter(ys, xs, c=phi, s=70)\npl.ylabel('Feature value a', fontsize=20)\npl.title('$\\mu=\\sum_i \\delta_{x_i,a_i}$', fontsize=25, usetex=True, y=1)\npl.xticks(())\npl.yticks(())\npl.subplot(2, 1, 2)\npl.scatter(yt, xt, c=phi2, s=70)\npl.xlabel('coordinates x/y', fontsize=25)\npl.ylabel('Feature value b', fontsize=20)\npl.title('$\\\\nu=\\sum_j \\delta_{y_j,b_j}$', fontsize=25, usetex=True, y=1)\npl.yticks(())\npl.tight_layout()\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create structure matrices and across-feature distance matrix\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "C1 = ot.dist(xs)\nC2 = ot.dist(xt)\nM = ot.dist(ys, yt)\nw1 = ot.unif(C1.shape[0])\nw2 = ot.unif(C2.shape[0])\nGot = ot.emd([], [], M)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot matrices\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cmap = 'Reds'\npl.close(10)\npl.figure(10, (5, 5))\nfs = 15\nl_x = [0, 5, 10, 15]\nl_y = [0, 5, 10, 15, 20, 25]\ngs = pl.GridSpec(5, 5)\n\nax1 = pl.subplot(gs[3:, :2])\n\npl.imshow(C1, cmap=cmap, interpolation='nearest')\npl.title(\"$C_1$\", fontsize=fs)\npl.xlabel(\"$k$\", fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\npl.xticks(l_x)\npl.yticks(l_x)\n\nax2 = pl.subplot(gs[:3, 2:])\n\npl.imshow(C2, cmap=cmap, interpolation='nearest')\npl.title(\"$C_2$\", fontsize=fs)\npl.ylabel(\"$l$\", fontsize=fs)\n#pl.ylabel(\"$l$\",fontsize=fs)\npl.xticks(())\npl.yticks(l_y)\nax2.set_aspect('auto')\n\nax3 = pl.subplot(gs[3:, 2:], sharex=ax2, sharey=ax1)\npl.imshow(M, cmap=cmap, interpolation='nearest')\npl.yticks(l_x)\npl.xticks(l_y)\npl.ylabel(\"$i$\", fontsize=fs)\npl.title(\"$M_{AB}$\", fontsize=fs)\npl.xlabel(\"$j$\", fontsize=fs)\npl.tight_layout()\nax3.set_aspect('auto')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute FGW/GW\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "alpha = 1e-3\n\not.tic()\nGwg, logw = fused_gromov_wasserstein(M, C1, C2, p, q, loss_fun='square_loss', alpha=alpha, verbose=True, log=True)\not.toc()\n\n#%reload_ext WGW\nGg, log = gromov_wasserstein(C1, C2, p, q, loss_fun='square_loss', verbose=True, log=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Visualize transport matrices\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cmap = 'Blues'\nfs = 15\npl.figure(2, (13, 5))\npl.clf()\npl.subplot(1, 3, 1)\npl.imshow(Got, cmap=cmap, interpolation='nearest')\n#pl.xlabel(\"$y$\",fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\npl.xticks(())\n\npl.title('Wasserstein ($M$ only)')\n\npl.subplot(1, 3, 2)\npl.imshow(Gg, cmap=cmap, interpolation='nearest')\npl.title('Gromov ($C_1,C_2$ only)')\npl.xticks(())\npl.subplot(1, 3, 3)\npl.imshow(Gwg, cmap=cmap, interpolation='nearest')\npl.title('FGW ($M+C_1,C_2$)')\n\npl.xlabel(\"$j$\", fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\n\npl.tight_layout()\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_fgw.py b/docs/source/auto_examples/plot_fgw.py deleted file mode 100644 index 43efc94..0000000 --- a/docs/source/auto_examples/plot_fgw.py +++ /dev/null @@ -1,173 +0,0 @@ -# -*- coding: utf-8 -*- -""" -============================== -Plot Fused-gromov-Wasserstein -============================== - -This example illustrates the computation of FGW for 1D measures[18]. - -.. [18] Vayer Titouan, Chapel Laetitia, Flamary R{\'e}mi, Tavenard Romain - and Courty Nicolas - "Optimal Transport for structured data with application on graphs" - International Conference on Machine Learning (ICML). 2019. - -""" - -# Author: Titouan Vayer -# -# License: MIT License - -import matplotlib.pyplot as pl -import numpy as np -import ot -from ot.gromov import gromov_wasserstein, fused_gromov_wasserstein - -############################################################################## -# Generate data -# --------- - -#%% parameters -# We create two 1D random measures -n = 20 # number of points in the first distribution -n2 = 30 # number of points in the second distribution -sig = 1 # std of first distribution -sig2 = 0.1 # std of second distribution - -np.random.seed(0) - -phi = np.arange(n)[:, None] -xs = phi + sig * np.random.randn(n, 1) -ys = np.vstack((np.ones((n // 2, 1)), 0 * np.ones((n // 2, 1)))) + sig2 * np.random.randn(n, 1) - -phi2 = np.arange(n2)[:, None] -xt = phi2 + sig * np.random.randn(n2, 1) -yt = np.vstack((np.ones((n2 // 2, 1)), 0 * np.ones((n2 // 2, 1)))) + sig2 * np.random.randn(n2, 1) -yt = yt[::-1, :] - -p = ot.unif(n) -q = ot.unif(n2) - -############################################################################## -# Plot data -# --------- - -#%% plot the distributions - -pl.close(10) -pl.figure(10, (7, 7)) - -pl.subplot(2, 1, 1) - -pl.scatter(ys, xs, c=phi, s=70) -pl.ylabel('Feature value a', fontsize=20) -pl.title('$\mu=\sum_i \delta_{x_i,a_i}$', fontsize=25, usetex=True, y=1) -pl.xticks(()) -pl.yticks(()) -pl.subplot(2, 1, 2) -pl.scatter(yt, xt, c=phi2, s=70) -pl.xlabel('coordinates x/y', fontsize=25) -pl.ylabel('Feature value b', fontsize=20) -pl.title('$\\nu=\sum_j \delta_{y_j,b_j}$', fontsize=25, usetex=True, y=1) -pl.yticks(()) -pl.tight_layout() -pl.show() - -############################################################################## -# Create structure matrices and across-feature distance matrix -# --------- - -#%% Structure matrices and across-features distance matrix -C1 = ot.dist(xs) -C2 = ot.dist(xt) -M = ot.dist(ys, yt) -w1 = ot.unif(C1.shape[0]) -w2 = ot.unif(C2.shape[0]) -Got = ot.emd([], [], M) - -############################################################################## -# Plot matrices -# --------- - -#%% -cmap = 'Reds' -pl.close(10) -pl.figure(10, (5, 5)) -fs = 15 -l_x = [0, 5, 10, 15] -l_y = [0, 5, 10, 15, 20, 25] -gs = pl.GridSpec(5, 5) - -ax1 = pl.subplot(gs[3:, :2]) - -pl.imshow(C1, cmap=cmap, interpolation='nearest') -pl.title("$C_1$", fontsize=fs) -pl.xlabel("$k$", fontsize=fs) -pl.ylabel("$i$", fontsize=fs) -pl.xticks(l_x) -pl.yticks(l_x) - -ax2 = pl.subplot(gs[:3, 2:]) - -pl.imshow(C2, cmap=cmap, interpolation='nearest') -pl.title("$C_2$", fontsize=fs) -pl.ylabel("$l$", fontsize=fs) -#pl.ylabel("$l$",fontsize=fs) -pl.xticks(()) -pl.yticks(l_y) -ax2.set_aspect('auto') - -ax3 = pl.subplot(gs[3:, 2:], sharex=ax2, sharey=ax1) -pl.imshow(M, cmap=cmap, interpolation='nearest') -pl.yticks(l_x) -pl.xticks(l_y) -pl.ylabel("$i$", fontsize=fs) -pl.title("$M_{AB}$", fontsize=fs) -pl.xlabel("$j$", fontsize=fs) -pl.tight_layout() -ax3.set_aspect('auto') -pl.show() - -############################################################################## -# Compute FGW/GW -# --------- - -#%% Computing FGW and GW -alpha = 1e-3 - -ot.tic() -Gwg, logw = fused_gromov_wasserstein(M, C1, C2, p, q, loss_fun='square_loss', alpha=alpha, verbose=True, log=True) -ot.toc() - -#%reload_ext WGW -Gg, log = gromov_wasserstein(C1, C2, p, q, loss_fun='square_loss', verbose=True, log=True) - -############################################################################## -# Visualize transport matrices -# --------- - -#%% visu OT matrix -cmap = 'Blues' -fs = 15 -pl.figure(2, (13, 5)) -pl.clf() -pl.subplot(1, 3, 1) -pl.imshow(Got, cmap=cmap, interpolation='nearest') -#pl.xlabel("$y$",fontsize=fs) -pl.ylabel("$i$", fontsize=fs) -pl.xticks(()) - -pl.title('Wasserstein ($M$ only)') - -pl.subplot(1, 3, 2) -pl.imshow(Gg, cmap=cmap, interpolation='nearest') -pl.title('Gromov ($C_1,C_2$ only)') -pl.xticks(()) -pl.subplot(1, 3, 3) -pl.imshow(Gwg, cmap=cmap, interpolation='nearest') -pl.title('FGW ($M+C_1,C_2$)') - -pl.xlabel("$j$", fontsize=fs) -pl.ylabel("$i$", fontsize=fs) - -pl.tight_layout() -pl.show() diff --git a/docs/source/auto_examples/plot_fgw.rst b/docs/source/auto_examples/plot_fgw.rst deleted file mode 100644 index 1c81d10..0000000 --- a/docs/source/auto_examples/plot_fgw.rst +++ /dev/null @@ -1,329 +0,0 @@ -.. 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_fgw.py: - - -============================== -Plot Fused-gromov-Wasserstein -============================== - -This example illustrates the computation of FGW for 1D measures[18]. - -.. [18] Vayer Titouan, Chapel Laetitia, Flamary R{'e}mi, Tavenard Romain - and Courty Nicolas - "Optimal Transport for structured data with application on graphs" - International Conference on Machine Learning (ICML). 2019. - - - -.. code-block:: default - - - # Author: Titouan Vayer - # - # License: MIT License - - import matplotlib.pyplot as pl - import numpy as np - import ot - from ot.gromov import gromov_wasserstein, fused_gromov_wasserstein - - - - - - - - -Generate data ---------- - -We create two 1D random measures - - -.. code-block:: default - - n = 20 # number of points in the first distribution - n2 = 30 # number of points in the second distribution - sig = 1 # std of first distribution - sig2 = 0.1 # std of second distribution - - np.random.seed(0) - - phi = np.arange(n)[:, None] - xs = phi + sig * np.random.randn(n, 1) - ys = np.vstack((np.ones((n // 2, 1)), 0 * np.ones((n // 2, 1)))) + sig2 * np.random.randn(n, 1) - - phi2 = np.arange(n2)[:, None] - xt = phi2 + sig * np.random.randn(n2, 1) - yt = np.vstack((np.ones((n2 // 2, 1)), 0 * np.ones((n2 // 2, 1)))) + sig2 * np.random.randn(n2, 1) - yt = yt[::-1, :] - - p = ot.unif(n) - q = ot.unif(n2) - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - pl.close(10) - pl.figure(10, (7, 7)) - - pl.subplot(2, 1, 1) - - pl.scatter(ys, xs, c=phi, s=70) - pl.ylabel('Feature value a', fontsize=20) - pl.title('$\mu=\sum_i \delta_{x_i,a_i}$', fontsize=25, usetex=True, y=1) - pl.xticks(()) - pl.yticks(()) - pl.subplot(2, 1, 2) - pl.scatter(yt, xt, c=phi2, s=70) - pl.xlabel('coordinates x/y', fontsize=25) - pl.ylabel('Feature value b', fontsize=20) - pl.title('$\\nu=\sum_j \delta_{y_j,b_j}$', fontsize=25, usetex=True, y=1) - pl.yticks(()) - pl.tight_layout() - pl.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_fgw_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_fgw.py:73: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Create structure matrices and across-feature distance matrix ---------- - - -.. code-block:: default - - C1 = ot.dist(xs) - C2 = ot.dist(xt) - M = ot.dist(ys, yt) - w1 = ot.unif(C1.shape[0]) - w2 = ot.unif(C2.shape[0]) - Got = ot.emd([], [], M) - - - - - - - - -Plot matrices ---------- - - -.. code-block:: default - - cmap = 'Reds' - pl.close(10) - pl.figure(10, (5, 5)) - fs = 15 - l_x = [0, 5, 10, 15] - l_y = [0, 5, 10, 15, 20, 25] - gs = pl.GridSpec(5, 5) - - ax1 = pl.subplot(gs[3:, :2]) - - pl.imshow(C1, cmap=cmap, interpolation='nearest') - pl.title("$C_1$", fontsize=fs) - pl.xlabel("$k$", fontsize=fs) - pl.ylabel("$i$", fontsize=fs) - pl.xticks(l_x) - pl.yticks(l_x) - - ax2 = pl.subplot(gs[:3, 2:]) - - pl.imshow(C2, cmap=cmap, interpolation='nearest') - pl.title("$C_2$", fontsize=fs) - pl.ylabel("$l$", fontsize=fs) - #pl.ylabel("$l$",fontsize=fs) - pl.xticks(()) - pl.yticks(l_y) - ax2.set_aspect('auto') - - ax3 = pl.subplot(gs[3:, 2:], sharex=ax2, sharey=ax1) - pl.imshow(M, cmap=cmap, interpolation='nearest') - pl.yticks(l_x) - pl.xticks(l_y) - pl.ylabel("$i$", fontsize=fs) - pl.title("$M_{AB}$", fontsize=fs) - pl.xlabel("$j$", fontsize=fs) - pl.tight_layout() - ax3.set_aspect('auto') - pl.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_fgw_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_fgw.py:128: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Compute FGW/GW ---------- - - -.. code-block:: default - - alpha = 1e-3 - - ot.tic() - Gwg, logw = fused_gromov_wasserstein(M, C1, C2, p, q, loss_fun='square_loss', alpha=alpha, verbose=True, log=True) - ot.toc() - - #%reload_ext WGW - Gg, log = gromov_wasserstein(C1, C2, p, q, loss_fun='square_loss', verbose=True, log=True) - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 0|4.734412e+01|0.000000e+00|0.000000e+00 - 1|2.508254e+01|8.875326e-01|2.226158e+01 - 2|2.189327e+01|1.456740e-01|3.189279e+00 - 3|2.189327e+01|0.000000e+00|0.000000e+00 - Elapsed time : 0.0023026466369628906 s - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 0|4.683978e+04|0.000000e+00|0.000000e+00 - 1|3.860061e+04|2.134468e-01|8.239175e+03 - 2|2.182948e+04|7.682787e-01|1.677113e+04 - 3|2.182948e+04|0.000000e+00|0.000000e+00 - - - - -Visualize transport matrices ---------- - - -.. code-block:: default - - cmap = 'Blues' - fs = 15 - pl.figure(2, (13, 5)) - pl.clf() - pl.subplot(1, 3, 1) - pl.imshow(Got, cmap=cmap, interpolation='nearest') - #pl.xlabel("$y$",fontsize=fs) - pl.ylabel("$i$", fontsize=fs) - pl.xticks(()) - - pl.title('Wasserstein ($M$ only)') - - pl.subplot(1, 3, 2) - pl.imshow(Gg, cmap=cmap, interpolation='nearest') - pl.title('Gromov ($C_1,C_2$ only)') - pl.xticks(()) - pl.subplot(1, 3, 3) - pl.imshow(Gwg, cmap=cmap, interpolation='nearest') - pl.title('FGW ($M+C_1,C_2$)') - - pl.xlabel("$j$", fontsize=fs) - pl.ylabel("$i$", fontsize=fs) - - pl.tight_layout() - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_fgw_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_fgw.py:173: 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.184 seconds) - - -.. _sphx_glr_download_auto_examples_plot_fgw.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_fgw.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_fgw.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_free_support_barycenter.ipynb b/docs/source/auto_examples/plot_free_support_barycenter.ipynb deleted file mode 100644 index 25ce60f..0000000 --- a/docs/source/auto_examples/plot_free_support_barycenter.ipynb +++ /dev/null @@ -1,108 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 2D free support Wasserstein barycenters of distributions\n\n\nIllustration of 2D Wasserstein barycenters if discributions that are weighted\nsum of diracs.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Vivien Seguy \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n -------------\n%% parameters and data generation\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "N = 3\nd = 2\nmeasures_locations = []\nmeasures_weights = []\n\nfor i in range(N):\n\n n_i = np.random.randint(low=1, high=20) # nb samples\n\n mu_i = np.random.normal(0., 4., (d,)) # Gaussian mean\n\n A_i = np.random.rand(d, d)\n cov_i = np.dot(A_i, A_i.transpose()) # Gaussian covariance matrix\n\n x_i = ot.datasets.make_2D_samples_gauss(n_i, mu_i, cov_i) # Dirac locations\n b_i = np.random.uniform(0., 1., (n_i,))\n b_i = b_i / np.sum(b_i) # Dirac weights\n\n measures_locations.append(x_i)\n measures_weights.append(b_i)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute free support barycenter\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "k = 10 # number of Diracs of the barycenter\nX_init = np.random.normal(0., 1., (k, d)) # initial Dirac locations\nb = np.ones((k,)) / k # weights of the barycenter (it will not be optimized, only the locations are optimized)\n\nX = ot.lp.free_support_barycenter(measures_locations, measures_weights, X_init, b)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1)\nfor (x_i, b_i) in zip(measures_locations, measures_weights):\n color = np.random.randint(low=1, high=10 * N)\n pl.scatter(x_i[:, 0], x_i[:, 1], s=b_i * 1000, label='input measure')\npl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter')\npl.title('Data measures and their barycenter')\npl.legend(loc=0)\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_free_support_barycenter.py b/docs/source/auto_examples/plot_free_support_barycenter.py deleted file mode 100644 index 64b89e4..0000000 --- a/docs/source/auto_examples/plot_free_support_barycenter.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -""" -==================================================== -2D free support Wasserstein barycenters of distributions -==================================================== - -Illustration of 2D Wasserstein barycenters if discributions that are weighted -sum of diracs. - -""" - -# Author: Vivien Seguy -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot - - -############################################################################## -# Generate data -# ------------- -#%% parameters and data generation -N = 3 -d = 2 -measures_locations = [] -measures_weights = [] - -for i in range(N): - - n_i = np.random.randint(low=1, high=20) # nb samples - - mu_i = np.random.normal(0., 4., (d,)) # Gaussian mean - - A_i = np.random.rand(d, d) - cov_i = np.dot(A_i, A_i.transpose()) # Gaussian covariance matrix - - x_i = ot.datasets.make_2D_samples_gauss(n_i, mu_i, cov_i) # Dirac locations - b_i = np.random.uniform(0., 1., (n_i,)) - b_i = b_i / np.sum(b_i) # Dirac weights - - measures_locations.append(x_i) - measures_weights.append(b_i) - - -############################################################################## -# Compute free support barycenter -# ------------- - -k = 10 # number of Diracs of the barycenter -X_init = np.random.normal(0., 1., (k, d)) # initial Dirac locations -b = np.ones((k,)) / k # weights of the barycenter (it will not be optimized, only the locations are optimized) - -X = ot.lp.free_support_barycenter(measures_locations, measures_weights, X_init, b) - - -############################################################################## -# Plot data -# --------- - -pl.figure(1) -for (x_i, b_i) in zip(measures_locations, measures_weights): - color = np.random.randint(low=1, high=10 * N) - pl.scatter(x_i[:, 0], x_i[:, 1], s=b_i * 1000, label='input measure') -pl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter') -pl.title('Data measures and their barycenter') -pl.legend(loc=0) -pl.show() diff --git a/docs/source/auto_examples/plot_free_support_barycenter.rst b/docs/source/auto_examples/plot_free_support_barycenter.rst deleted file mode 100644 index f349604..0000000 --- a/docs/source/auto_examples/plot_free_support_barycenter.rst +++ /dev/null @@ -1,162 +0,0 @@ -.. 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_free_support_barycenter.py: - - -==================================================== -2D free support Wasserstein barycenters of distributions -==================================================== - -Illustration of 2D Wasserstein barycenters if discributions that are weighted -sum of diracs. - - - -.. code-block:: default - - - # Author: Vivien Seguy - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - - - - - - - - - -Generate data - ------------- -%% parameters and data generation - - -.. code-block:: default - - N = 3 - d = 2 - measures_locations = [] - measures_weights = [] - - for i in range(N): - - n_i = np.random.randint(low=1, high=20) # nb samples - - mu_i = np.random.normal(0., 4., (d,)) # Gaussian mean - - A_i = np.random.rand(d, d) - cov_i = np.dot(A_i, A_i.transpose()) # Gaussian covariance matrix - - x_i = ot.datasets.make_2D_samples_gauss(n_i, mu_i, cov_i) # Dirac locations - b_i = np.random.uniform(0., 1., (n_i,)) - b_i = b_i / np.sum(b_i) # Dirac weights - - measures_locations.append(x_i) - measures_weights.append(b_i) - - - - - - - - - -Compute free support barycenter -------------- - - -.. code-block:: default - - - k = 10 # number of Diracs of the barycenter - X_init = np.random.normal(0., 1., (k, d)) # initial Dirac locations - b = np.ones((k,)) / k # weights of the barycenter (it will not be optimized, only the locations are optimized) - - X = ot.lp.free_support_barycenter(measures_locations, measures_weights, X_init, b) - - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - pl.figure(1) - for (x_i, b_i) in zip(measures_locations, measures_weights): - color = np.random.randint(low=1, high=10 * N) - pl.scatter(x_i[:, 0], x_i[:, 1], s=b_i * 1000, label='input measure') - pl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter') - pl.title('Data measures and their barycenter') - pl.legend(loc=0) - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_free_support_barycenter.py:69: 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 0.080 seconds) - - -.. _sphx_glr_download_auto_examples_plot_free_support_barycenter.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_free_support_barycenter.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_free_support_barycenter.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_gromov.ipynb b/docs/source/auto_examples/plot_gromov.ipynb deleted file mode 100644 index e5a88e7..0000000 --- a/docs/source/auto_examples/plot_gromov.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Gromov-Wasserstein example\n\n\nThis example is designed to show how to use the Gromov-Wassertsein distance\ncomputation in POT.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Erwan Vautier \n# Nicolas Courty \n#\n# License: MIT License\n\nimport scipy as sp\nimport numpy as np\nimport matplotlib.pylab as pl\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nimport ot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Sample two Gaussian distributions (2D and 3D)\n---------------------------------------------\n\nThe Gromov-Wasserstein distance allows to compute distances with samples that\ndo not belong to the same metric space. For demonstration purpose, we sample\ntwo Gaussian distributions in 2- and 3-dimensional spaces.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_samples = 30 # nb samples\n\nmu_s = np.array([0, 0])\ncov_s = np.array([[1, 0], [0, 1]])\n\nmu_t = np.array([4, 4, 4])\ncov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])\n\n\nxs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s)\nP = sp.linalg.sqrtm(cov_t)\nxt = np.random.randn(n_samples, 3).dot(P) + mu_t" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plotting the distributions\n--------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "fig = pl.figure()\nax1 = fig.add_subplot(121)\nax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\nax2 = fig.add_subplot(122, projection='3d')\nax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute distance kernels, normalize them and then display\n---------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "C1 = sp.spatial.distance.cdist(xs, xs)\nC2 = sp.spatial.distance.cdist(xt, xt)\n\nC1 /= C1.max()\nC2 /= C2.max()\n\npl.figure()\npl.subplot(121)\npl.imshow(C1)\npl.subplot(122)\npl.imshow(C2)\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute Gromov-Wasserstein plans and distance\n---------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "p = ot.unif(n_samples)\nq = ot.unif(n_samples)\n\ngw0, log0 = ot.gromov.gromov_wasserstein(\n C1, C2, p, q, 'square_loss', verbose=True, log=True)\n\ngw, log = ot.gromov.entropic_gromov_wasserstein(\n C1, C2, p, q, 'square_loss', epsilon=5e-4, log=True, verbose=True)\n\n\nprint('Gromov-Wasserstein distances: ' + str(log0['gw_dist']))\nprint('Entropic Gromov-Wasserstein distances: ' + str(log['gw_dist']))\n\n\npl.figure(1, (10, 5))\n\npl.subplot(1, 2, 1)\npl.imshow(gw0, cmap='jet')\npl.title('Gromov Wasserstein')\n\npl.subplot(1, 2, 2)\npl.imshow(gw, cmap='jet')\npl.title('Entropic Gromov Wasserstein')\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_gromov.py b/docs/source/auto_examples/plot_gromov.py deleted file mode 100644 index deb2f86..0000000 --- a/docs/source/auto_examples/plot_gromov.py +++ /dev/null @@ -1,106 +0,0 @@ -# -*- coding: utf-8 -*- -""" -========================== -Gromov-Wasserstein example -========================== - -This example is designed to show how to use the Gromov-Wassertsein distance -computation in POT. -""" - -# Author: Erwan Vautier -# Nicolas Courty -# -# License: MIT License - -import scipy as sp -import numpy as np -import matplotlib.pylab as pl -from mpl_toolkits.mplot3d import Axes3D # noqa -import ot - -############################################################################# -# -# Sample two Gaussian distributions (2D and 3D) -# --------------------------------------------- -# -# The Gromov-Wasserstein distance allows to compute distances with samples that -# do not belong to the same metric space. For demonstration purpose, we sample -# two Gaussian distributions in 2- and 3-dimensional spaces. - - -n_samples = 30 # nb samples - -mu_s = np.array([0, 0]) -cov_s = np.array([[1, 0], [0, 1]]) - -mu_t = np.array([4, 4, 4]) -cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) - - -xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s) -P = sp.linalg.sqrtm(cov_t) -xt = np.random.randn(n_samples, 3).dot(P) + mu_t - -############################################################################# -# -# Plotting the distributions -# -------------------------- - - -fig = pl.figure() -ax1 = fig.add_subplot(121) -ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -ax2 = fig.add_subplot(122, projection='3d') -ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r') -pl.show() - -############################################################################# -# -# Compute distance kernels, normalize them and then display -# --------------------------------------------------------- - - -C1 = sp.spatial.distance.cdist(xs, xs) -C2 = sp.spatial.distance.cdist(xt, xt) - -C1 /= C1.max() -C2 /= C2.max() - -pl.figure() -pl.subplot(121) -pl.imshow(C1) -pl.subplot(122) -pl.imshow(C2) -pl.show() - -############################################################################# -# -# Compute Gromov-Wasserstein plans and distance -# --------------------------------------------- - -p = ot.unif(n_samples) -q = ot.unif(n_samples) - -gw0, log0 = ot.gromov.gromov_wasserstein( - C1, C2, p, q, 'square_loss', verbose=True, log=True) - -gw, log = ot.gromov.entropic_gromov_wasserstein( - C1, C2, p, q, 'square_loss', epsilon=5e-4, log=True, verbose=True) - - -print('Gromov-Wasserstein distances: ' + str(log0['gw_dist'])) -print('Entropic Gromov-Wasserstein distances: ' + str(log['gw_dist'])) - - -pl.figure(1, (10, 5)) - -pl.subplot(1, 2, 1) -pl.imshow(gw0, cmap='jet') -pl.title('Gromov Wasserstein') - -pl.subplot(1, 2, 2) -pl.imshow(gw, cmap='jet') -pl.title('Entropic Gromov Wasserstein') - -pl.show() diff --git a/docs/source/auto_examples/plot_gromov.rst b/docs/source/auto_examples/plot_gromov.rst deleted file mode 100644 index 13d0d09..0000000 --- a/docs/source/auto_examples/plot_gromov.rst +++ /dev/null @@ -1,245 +0,0 @@ -.. 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_gromov.py: - - -========================== -Gromov-Wasserstein example -========================== - -This example is designed to show how to use the Gromov-Wassertsein distance -computation in POT. - - -.. code-block:: default - - - # Author: Erwan Vautier - # Nicolas Courty - # - # License: MIT License - - import scipy as sp - import numpy as np - import matplotlib.pylab as pl - from mpl_toolkits.mplot3d import Axes3D # noqa - import ot - - - - - - - - -Sample two Gaussian distributions (2D and 3D) ---------------------------------------------- - -The Gromov-Wasserstein distance allows to compute distances with samples that -do not belong to the same metric space. For demonstration purpose, we sample -two Gaussian distributions in 2- and 3-dimensional spaces. - - -.. code-block:: default - - - - n_samples = 30 # nb samples - - mu_s = np.array([0, 0]) - cov_s = np.array([[1, 0], [0, 1]]) - - mu_t = np.array([4, 4, 4]) - cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) - - - xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s) - P = sp.linalg.sqrtm(cov_t) - xt = np.random.randn(n_samples, 3).dot(P) + mu_t - - - - - - - - -Plotting the distributions --------------------------- - - -.. code-block:: default - - - - fig = pl.figure() - ax1 = fig.add_subplot(121) - ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - ax2 = fig.add_subplot(122, projection='3d') - ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r') - pl.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_gromov_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_gromov.py:56: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Compute distance kernels, normalize them and then display ---------------------------------------------------------- - - -.. code-block:: default - - - - C1 = sp.spatial.distance.cdist(xs, xs) - C2 = sp.spatial.distance.cdist(xt, xt) - - C1 /= C1.max() - C2 /= C2.max() - - pl.figure() - pl.subplot(121) - pl.imshow(C1) - pl.subplot(122) - pl.imshow(C2) - pl.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_gromov_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_gromov.py:75: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Compute Gromov-Wasserstein plans and distance ---------------------------------------------- - - -.. code-block:: default - - - p = ot.unif(n_samples) - q = ot.unif(n_samples) - - gw0, log0 = ot.gromov.gromov_wasserstein( - C1, C2, p, q, 'square_loss', verbose=True, log=True) - - gw, log = ot.gromov.entropic_gromov_wasserstein( - C1, C2, p, q, 'square_loss', epsilon=5e-4, log=True, verbose=True) - - - print('Gromov-Wasserstein distances: ' + str(log0['gw_dist'])) - print('Entropic Gromov-Wasserstein distances: ' + str(log['gw_dist'])) - - - pl.figure(1, (10, 5)) - - pl.subplot(1, 2, 1) - pl.imshow(gw0, cmap='jet') - pl.title('Gromov Wasserstein') - - pl.subplot(1, 2, 2) - pl.imshow(gw, cmap='jet') - pl.title('Entropic Gromov Wasserstein') - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_gromov_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 0|8.019265e-02|0.000000e+00|0.000000e+00 - 1|3.734805e-02|1.147171e+00|4.284460e-02 - 2|2.923853e-02|2.773572e-01|8.109516e-03 - 3|2.478957e-02|1.794691e-01|4.448961e-03 - 4|2.444720e-02|1.400444e-02|3.423693e-04 - 5|2.444720e-02|0.000000e+00|0.000000e+00 - It. |Err - ------------------- - 0|8.259147e-02| - 10|6.113732e-04| - 20|1.650651e-08| - 30|5.671192e-12| - Gromov-Wasserstein distances: 0.024447198979060496 - Entropic Gromov-Wasserstein distances: 0.02488439679981518 - /home/rflamary/PYTHON/POT/examples/plot_gromov.py:106: 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 0.999 seconds) - - -.. _sphx_glr_download_auto_examples_plot_gromov.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_gromov.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_gromov.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_gromov_barycenter.ipynb b/docs/source/auto_examples/plot_gromov_barycenter.ipynb deleted file mode 100644 index 17ba374..0000000 --- a/docs/source/auto_examples/plot_gromov_barycenter.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Gromov-Wasserstein Barycenter example\n\n\nThis example is designed to show how to use the Gromov-Wasserstein distance\ncomputation in POT.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Erwan Vautier \n# Nicolas Courty \n#\n# License: MIT License\n\n\nimport numpy as np\nimport scipy as sp\n\nimport matplotlib.pylab as pl\nfrom sklearn import manifold\nfrom sklearn.decomposition import PCA\n\nimport ot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Smacof MDS\n----------\n\nThis function allows to find an embedding of points given a dissimilarity matrix\nthat will be given by the output of the algorithm\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def smacof_mds(C, dim, max_iter=3000, eps=1e-9):\n \"\"\"\n Returns an interpolated point cloud following the dissimilarity matrix C\n using SMACOF multidimensional scaling (MDS) in specific dimensionned\n target space\n\n Parameters\n ----------\n C : ndarray, shape (ns, ns)\n dissimilarity matrix\n dim : int\n dimension of the targeted space\n max_iter : int\n Maximum number of iterations of the SMACOF algorithm for a single run\n eps : float\n relative tolerance w.r.t stress to declare converge\n\n Returns\n -------\n npos : ndarray, shape (R, dim)\n Embedded coordinates of the interpolated point cloud (defined with\n one isometry)\n \"\"\"\n\n rng = np.random.RandomState(seed=3)\n\n mds = manifold.MDS(\n dim,\n max_iter=max_iter,\n eps=1e-9,\n dissimilarity='precomputed',\n n_init=1)\n pos = mds.fit(C).embedding_\n\n nmds = manifold.MDS(\n 2,\n max_iter=max_iter,\n eps=1e-9,\n dissimilarity=\"precomputed\",\n random_state=rng,\n n_init=1)\n npos = nmds.fit_transform(C, init=pos)\n\n return npos" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Data preparation\n----------------\n\nThe four distributions are constructed from 4 simple images\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\nsquare = pl.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256\ncross = pl.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256\ntriangle = pl.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256\nstar = pl.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256\n\nshapes = [square, cross, triangle, star]\n\nS = 4\nxs = [[] for i in range(S)]\n\n\nfor nb in range(4):\n for i in range(8):\n for j in range(8):\n if shapes[nb][i, j] < 0.95:\n xs[nb].append([j, 8 - i])\n\nxs = np.array([np.array(xs[0]), np.array(xs[1]),\n np.array(xs[2]), np.array(xs[3])])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Barycenter computation\n----------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "ns = [len(xs[s]) for s in range(S)]\nn_samples = 30\n\n\"\"\"Compute all distances matrices for the four shapes\"\"\"\nCs = [sp.spatial.distance.cdist(xs[s], xs[s]) for s in range(S)]\nCs = [cs / cs.max() for cs in Cs]\n\nps = [ot.unif(ns[s]) for s in range(S)]\np = ot.unif(n_samples)\n\n\nlambdast = [[float(i) / 3, float(3 - i) / 3] for i in [1, 2]]\n\nCt01 = [0 for i in range(2)]\nfor i in range(2):\n Ct01[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[1]],\n [ps[0], ps[1]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)\n\nCt02 = [0 for i in range(2)]\nfor i in range(2):\n Ct02[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[2]],\n [ps[0], ps[2]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)\n\nCt13 = [0 for i in range(2)]\nfor i in range(2):\n Ct13[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[1], Cs[3]],\n [ps[1], ps[3]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)\n\nCt23 = [0 for i in range(2)]\nfor i in range(2):\n Ct23[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[2], Cs[3]],\n [ps[2], ps[3]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Visualization\n-------------\n\nThe PCA helps in getting consistency between the rotations\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "clf = PCA(n_components=2)\nnpos = [0, 0, 0, 0]\nnpos = [smacof_mds(Cs[s], 2) for s in range(S)]\n\nnpost01 = [0, 0]\nnpost01 = [smacof_mds(Ct01[s], 2) for s in range(2)]\nnpost01 = [clf.fit_transform(npost01[s]) for s in range(2)]\n\nnpost02 = [0, 0]\nnpost02 = [smacof_mds(Ct02[s], 2) for s in range(2)]\nnpost02 = [clf.fit_transform(npost02[s]) for s in range(2)]\n\nnpost13 = [0, 0]\nnpost13 = [smacof_mds(Ct13[s], 2) for s in range(2)]\nnpost13 = [clf.fit_transform(npost13[s]) for s in range(2)]\n\nnpost23 = [0, 0]\nnpost23 = [smacof_mds(Ct23[s], 2) for s in range(2)]\nnpost23 = [clf.fit_transform(npost23[s]) for s in range(2)]\n\n\nfig = pl.figure(figsize=(10, 10))\n\nax1 = pl.subplot2grid((4, 4), (0, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax1.scatter(npos[0][:, 0], npos[0][:, 1], color='r')\n\nax2 = pl.subplot2grid((4, 4), (0, 1))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax2.scatter(npost01[1][:, 0], npost01[1][:, 1], color='b')\n\nax3 = pl.subplot2grid((4, 4), (0, 2))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax3.scatter(npost01[0][:, 0], npost01[0][:, 1], color='b')\n\nax4 = pl.subplot2grid((4, 4), (0, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax4.scatter(npos[1][:, 0], npos[1][:, 1], color='r')\n\nax5 = pl.subplot2grid((4, 4), (1, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax5.scatter(npost02[1][:, 0], npost02[1][:, 1], color='b')\n\nax6 = pl.subplot2grid((4, 4), (1, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax6.scatter(npost13[1][:, 0], npost13[1][:, 1], color='b')\n\nax7 = pl.subplot2grid((4, 4), (2, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax7.scatter(npost02[0][:, 0], npost02[0][:, 1], color='b')\n\nax8 = pl.subplot2grid((4, 4), (2, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax8.scatter(npost13[0][:, 0], npost13[0][:, 1], color='b')\n\nax9 = pl.subplot2grid((4, 4), (3, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax9.scatter(npos[2][:, 0], npos[2][:, 1], color='r')\n\nax10 = pl.subplot2grid((4, 4), (3, 1))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax10.scatter(npost23[1][:, 0], npost23[1][:, 1], color='b')\n\nax11 = pl.subplot2grid((4, 4), (3, 2))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax11.scatter(npost23[0][:, 0], npost23[0][:, 1], color='b')\n\nax12 = pl.subplot2grid((4, 4), (3, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax12.scatter(npos[3][:, 0], npos[3][:, 1], color='r')" - ] - } - ], - "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_gromov_barycenter.py b/docs/source/auto_examples/plot_gromov_barycenter.py deleted file mode 100644 index 101c6c5..0000000 --- a/docs/source/auto_examples/plot_gromov_barycenter.py +++ /dev/null @@ -1,247 +0,0 @@ -# -*- coding: utf-8 -*- -""" -===================================== -Gromov-Wasserstein Barycenter example -===================================== - -This example is designed to show how to use the Gromov-Wasserstein distance -computation in POT. -""" - -# Author: Erwan Vautier -# Nicolas Courty -# -# License: MIT License - - -import numpy as np -import scipy as sp - -import matplotlib.pylab as pl -from sklearn import manifold -from sklearn.decomposition import PCA - -import ot - -############################################################################## -# Smacof MDS -# ---------- -# -# This function allows to find an embedding of points given a dissimilarity matrix -# that will be given by the output of the algorithm - - -def smacof_mds(C, dim, max_iter=3000, eps=1e-9): - """ - Returns an interpolated point cloud following the dissimilarity matrix C - using SMACOF multidimensional scaling (MDS) in specific dimensionned - target space - - Parameters - ---------- - C : ndarray, shape (ns, ns) - dissimilarity matrix - dim : int - dimension of the targeted space - max_iter : int - Maximum number of iterations of the SMACOF algorithm for a single run - eps : float - relative tolerance w.r.t stress to declare converge - - Returns - ------- - npos : ndarray, shape (R, dim) - Embedded coordinates of the interpolated point cloud (defined with - one isometry) - """ - - rng = np.random.RandomState(seed=3) - - mds = manifold.MDS( - dim, - max_iter=max_iter, - eps=1e-9, - dissimilarity='precomputed', - n_init=1) - pos = mds.fit(C).embedding_ - - nmds = manifold.MDS( - 2, - max_iter=max_iter, - eps=1e-9, - dissimilarity="precomputed", - random_state=rng, - n_init=1) - npos = nmds.fit_transform(C, init=pos) - - return npos - - -############################################################################## -# Data preparation -# ---------------- -# -# The four distributions are constructed from 4 simple images - - -def im2mat(I): - """Converts and image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - -square = pl.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256 -cross = pl.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256 -triangle = pl.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256 -star = pl.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256 - -shapes = [square, cross, triangle, star] - -S = 4 -xs = [[] for i in range(S)] - - -for nb in range(4): - for i in range(8): - for j in range(8): - if shapes[nb][i, j] < 0.95: - xs[nb].append([j, 8 - i]) - -xs = np.array([np.array(xs[0]), np.array(xs[1]), - np.array(xs[2]), np.array(xs[3])]) - -############################################################################## -# Barycenter computation -# ---------------------- - - -ns = [len(xs[s]) for s in range(S)] -n_samples = 30 - -"""Compute all distances matrices for the four shapes""" -Cs = [sp.spatial.distance.cdist(xs[s], xs[s]) for s in range(S)] -Cs = [cs / cs.max() for cs in Cs] - -ps = [ot.unif(ns[s]) for s in range(S)] -p = ot.unif(n_samples) - - -lambdast = [[float(i) / 3, float(3 - i) / 3] for i in [1, 2]] - -Ct01 = [0 for i in range(2)] -for i in range(2): - Ct01[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[1]], - [ps[0], ps[1] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - -Ct02 = [0 for i in range(2)] -for i in range(2): - Ct02[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[2]], - [ps[0], ps[2] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - -Ct13 = [0 for i in range(2)] -for i in range(2): - Ct13[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[1], Cs[3]], - [ps[1], ps[3] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - -Ct23 = [0 for i in range(2)] -for i in range(2): - Ct23[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[2], Cs[3]], - [ps[2], ps[3] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - - -############################################################################## -# Visualization -# ------------- -# -# The PCA helps in getting consistency between the rotations - - -clf = PCA(n_components=2) -npos = [0, 0, 0, 0] -npos = [smacof_mds(Cs[s], 2) for s in range(S)] - -npost01 = [0, 0] -npost01 = [smacof_mds(Ct01[s], 2) for s in range(2)] -npost01 = [clf.fit_transform(npost01[s]) for s in range(2)] - -npost02 = [0, 0] -npost02 = [smacof_mds(Ct02[s], 2) for s in range(2)] -npost02 = [clf.fit_transform(npost02[s]) for s in range(2)] - -npost13 = [0, 0] -npost13 = [smacof_mds(Ct13[s], 2) for s in range(2)] -npost13 = [clf.fit_transform(npost13[s]) for s in range(2)] - -npost23 = [0, 0] -npost23 = [smacof_mds(Ct23[s], 2) for s in range(2)] -npost23 = [clf.fit_transform(npost23[s]) for s in range(2)] - - -fig = pl.figure(figsize=(10, 10)) - -ax1 = pl.subplot2grid((4, 4), (0, 0)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax1.scatter(npos[0][:, 0], npos[0][:, 1], color='r') - -ax2 = pl.subplot2grid((4, 4), (0, 1)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax2.scatter(npost01[1][:, 0], npost01[1][:, 1], color='b') - -ax3 = pl.subplot2grid((4, 4), (0, 2)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax3.scatter(npost01[0][:, 0], npost01[0][:, 1], color='b') - -ax4 = pl.subplot2grid((4, 4), (0, 3)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax4.scatter(npos[1][:, 0], npos[1][:, 1], color='r') - -ax5 = pl.subplot2grid((4, 4), (1, 0)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax5.scatter(npost02[1][:, 0], npost02[1][:, 1], color='b') - -ax6 = pl.subplot2grid((4, 4), (1, 3)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax6.scatter(npost13[1][:, 0], npost13[1][:, 1], color='b') - -ax7 = pl.subplot2grid((4, 4), (2, 0)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax7.scatter(npost02[0][:, 0], npost02[0][:, 1], color='b') - -ax8 = pl.subplot2grid((4, 4), (2, 3)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax8.scatter(npost13[0][:, 0], npost13[0][:, 1], color='b') - -ax9 = pl.subplot2grid((4, 4), (3, 0)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax9.scatter(npos[2][:, 0], npos[2][:, 1], color='r') - -ax10 = pl.subplot2grid((4, 4), (3, 1)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax10.scatter(npost23[1][:, 0], npost23[1][:, 1], color='b') - -ax11 = pl.subplot2grid((4, 4), (3, 2)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax11.scatter(npost23[0][:, 0], npost23[0][:, 1], color='b') - -ax12 = pl.subplot2grid((4, 4), (3, 3)) -pl.xlim((-1, 1)) -pl.ylim((-1, 1)) -ax12.scatter(npos[3][:, 0], npos[3][:, 1], color='r') diff --git a/docs/source/auto_examples/plot_gromov_barycenter.rst b/docs/source/auto_examples/plot_gromov_barycenter.rst deleted file mode 100644 index 995cca7..0000000 --- a/docs/source/auto_examples/plot_gromov_barycenter.rst +++ /dev/null @@ -1,349 +0,0 @@ -.. 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_gromov_barycenter.py: - - -===================================== -Gromov-Wasserstein Barycenter example -===================================== - -This example is designed to show how to use the Gromov-Wasserstein distance -computation in POT. - - -.. code-block:: default - - - # Author: Erwan Vautier - # Nicolas Courty - # - # License: MIT License - - - import numpy as np - import scipy as sp - - import matplotlib.pylab as pl - from sklearn import manifold - from sklearn.decomposition import PCA - - import ot - - - - - - - - -Smacof MDS ----------- - -This function allows to find an embedding of points given a dissimilarity matrix -that will be given by the output of the algorithm - - -.. code-block:: default - - - - def smacof_mds(C, dim, max_iter=3000, eps=1e-9): - """ - Returns an interpolated point cloud following the dissimilarity matrix C - using SMACOF multidimensional scaling (MDS) in specific dimensionned - target space - - Parameters - ---------- - C : ndarray, shape (ns, ns) - dissimilarity matrix - dim : int - dimension of the targeted space - max_iter : int - Maximum number of iterations of the SMACOF algorithm for a single run - eps : float - relative tolerance w.r.t stress to declare converge - - Returns - ------- - npos : ndarray, shape (R, dim) - Embedded coordinates of the interpolated point cloud (defined with - one isometry) - """ - - rng = np.random.RandomState(seed=3) - - mds = manifold.MDS( - dim, - max_iter=max_iter, - eps=1e-9, - dissimilarity='precomputed', - n_init=1) - pos = mds.fit(C).embedding_ - - nmds = manifold.MDS( - 2, - max_iter=max_iter, - eps=1e-9, - dissimilarity="precomputed", - random_state=rng, - n_init=1) - npos = nmds.fit_transform(C, init=pos) - - return npos - - - - - - - - - -Data preparation ----------------- - -The four distributions are constructed from 4 simple images - - -.. code-block:: default - - - - def im2mat(I): - """Converts and image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - - square = pl.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256 - cross = pl.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256 - triangle = pl.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256 - star = pl.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256 - - shapes = [square, cross, triangle, star] - - S = 4 - xs = [[] for i in range(S)] - - - for nb in range(4): - for i in range(8): - for j in range(8): - if shapes[nb][i, j] < 0.95: - xs[nb].append([j, 8 - i]) - - xs = np.array([np.array(xs[0]), np.array(xs[1]), - np.array(xs[2]), np.array(xs[3])]) - - - - - - - - -Barycenter computation ----------------------- - - -.. code-block:: default - - - - ns = [len(xs[s]) for s in range(S)] - n_samples = 30 - - """Compute all distances matrices for the four shapes""" - Cs = [sp.spatial.distance.cdist(xs[s], xs[s]) for s in range(S)] - Cs = [cs / cs.max() for cs in Cs] - - ps = [ot.unif(ns[s]) for s in range(S)] - p = ot.unif(n_samples) - - - lambdast = [[float(i) / 3, float(3 - i) / 3] for i in [1, 2]] - - Ct01 = [0 for i in range(2)] - for i in range(2): - Ct01[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[1]], - [ps[0], ps[1] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - - Ct02 = [0 for i in range(2)] - for i in range(2): - Ct02[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[2]], - [ps[0], ps[2] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - - Ct13 = [0 for i in range(2)] - for i in range(2): - Ct13[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[1], Cs[3]], - [ps[1], ps[3] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - - Ct23 = [0 for i in range(2)] - for i in range(2): - Ct23[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[2], Cs[3]], - [ps[2], ps[3] - ], p, lambdast[i], 'square_loss', # 5e-4, - max_iter=100, tol=1e-3) - - - - - - - - - -Visualization -------------- - -The PCA helps in getting consistency between the rotations - - -.. code-block:: default - - - - clf = PCA(n_components=2) - npos = [0, 0, 0, 0] - npos = [smacof_mds(Cs[s], 2) for s in range(S)] - - npost01 = [0, 0] - npost01 = [smacof_mds(Ct01[s], 2) for s in range(2)] - npost01 = [clf.fit_transform(npost01[s]) for s in range(2)] - - npost02 = [0, 0] - npost02 = [smacof_mds(Ct02[s], 2) for s in range(2)] - npost02 = [clf.fit_transform(npost02[s]) for s in range(2)] - - npost13 = [0, 0] - npost13 = [smacof_mds(Ct13[s], 2) for s in range(2)] - npost13 = [clf.fit_transform(npost13[s]) for s in range(2)] - - npost23 = [0, 0] - npost23 = [smacof_mds(Ct23[s], 2) for s in range(2)] - npost23 = [clf.fit_transform(npost23[s]) for s in range(2)] - - - fig = pl.figure(figsize=(10, 10)) - - ax1 = pl.subplot2grid((4, 4), (0, 0)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax1.scatter(npos[0][:, 0], npos[0][:, 1], color='r') - - ax2 = pl.subplot2grid((4, 4), (0, 1)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax2.scatter(npost01[1][:, 0], npost01[1][:, 1], color='b') - - ax3 = pl.subplot2grid((4, 4), (0, 2)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax3.scatter(npost01[0][:, 0], npost01[0][:, 1], color='b') - - ax4 = pl.subplot2grid((4, 4), (0, 3)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax4.scatter(npos[1][:, 0], npos[1][:, 1], color='r') - - ax5 = pl.subplot2grid((4, 4), (1, 0)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax5.scatter(npost02[1][:, 0], npost02[1][:, 1], color='b') - - ax6 = pl.subplot2grid((4, 4), (1, 3)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax6.scatter(npost13[1][:, 0], npost13[1][:, 1], color='b') - - ax7 = pl.subplot2grid((4, 4), (2, 0)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax7.scatter(npost02[0][:, 0], npost02[0][:, 1], color='b') - - ax8 = pl.subplot2grid((4, 4), (2, 3)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax8.scatter(npost13[0][:, 0], npost13[0][:, 1], color='b') - - ax9 = pl.subplot2grid((4, 4), (3, 0)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax9.scatter(npos[2][:, 0], npos[2][:, 1], color='r') - - ax10 = pl.subplot2grid((4, 4), (3, 1)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax10.scatter(npost23[1][:, 0], npost23[1][:, 1], color='b') - - ax11 = pl.subplot2grid((4, 4), (3, 2)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax11.scatter(npost23[0][:, 0], npost23[0][:, 1], color='b') - - ax12 = pl.subplot2grid((4, 4), (3, 3)) - pl.xlim((-1, 1)) - pl.ylim((-1, 1)) - ax12.scatter(npos[3][:, 0], npos[3][:, 1], color='r') - - - -.. image:: /auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - - - - - -.. rst-class:: sphx-glr-timing - - **Total running time of the script:** ( 0 minutes 1.747 seconds) - - -.. _sphx_glr_download_auto_examples_plot_gromov_barycenter.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_gromov_barycenter.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_gromov_barycenter.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_optim_OTreg.ipynb b/docs/source/auto_examples/plot_optim_OTreg.ipynb deleted file mode 100644 index 01e0689..0000000 --- a/docs/source/auto_examples/plot_optim_OTreg.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Regularized OT with generic solver\n\n\nIllustrates the use of the generic solver for regularized OT with\nuser-designed regularization term. It uses Conditional gradient as in [6] and\ngeneralized Conditional Gradient as proposed in [5][7].\n\n\n[5] N. Courty; R. Flamary; D. Tuia; A. Rakotomamonjy, Optimal Transport for\nDomain Adaptation, in IEEE Transactions on Pattern Analysis and Machine\nIntelligence , vol.PP, no.99, pp.1-1.\n\n[6] Ferradans, S., Papadakis, N., Peyr\u00e9, G., & Aujol, J. F. (2014).\nRegularized discrete optimal transport. SIAM Journal on Imaging Sciences,\n7(3), 1853-1882.\n\n[7] Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized\nconditional gradient: analysis of convergence and applications.\narXiv preprint arXiv:1510.06567.\n\n\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\nb = ot.datasets.make_1D_gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve EMD\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "G0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve EMD with Frobenius norm regularization\n--------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg = 1e-1\n\nGl2 = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(3)\not.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve EMD with entropic regularization\n--------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def f(G):\n return np.sum(G * np.log(G))\n\n\ndef df(G):\n return np.log(G) + 1.\n\n\nreg = 1e-3\n\nGe = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve EMD with Frobenius norm + entropic regularization\n-------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg1 = 1e-3\nreg2 = 1e-1\n\nGel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True)\n\npl.figure(5, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg')\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_optim_OTreg.py b/docs/source/auto_examples/plot_optim_OTreg.py deleted file mode 100644 index 2c58def..0000000 --- a/docs/source/auto_examples/plot_optim_OTreg.py +++ /dev/null @@ -1,129 +0,0 @@ -# -*- coding: utf-8 -*- -""" -================================== -Regularized OT with generic solver -================================== - -Illustrates the use of the generic solver for regularized OT with -user-designed regularization term. It uses Conditional gradient as in [6] and -generalized Conditional Gradient as proposed in [5][7]. - - -[5] N. Courty; R. Flamary; D. Tuia; A. Rakotomamonjy, Optimal Transport for -Domain Adaptation, in IEEE Transactions on Pattern Analysis and Machine -Intelligence , vol.PP, no.99, pp.1-1. - -[6] Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). -Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, -7(3), 1853-1882. - -[7] Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized -conditional gradient: analysis of convergence and applications. -arXiv preprint arXiv:1510.06567. - - - -""" - -import numpy as np -import matplotlib.pylab as pl -import ot -import ot.plot - -############################################################################## -# Generate data -# ------------- - -#%% parameters - -n = 100 # nb bins - -# bin positions -x = np.arange(n, dtype=np.float64) - -# Gaussian distributions -a = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std -b = ot.datasets.make_1D_gauss(n, m=60, s=10) - -# loss matrix -M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) -M /= M.max() - -############################################################################## -# Solve EMD -# --------- - -#%% EMD - -G0 = ot.emd(a, b, M) - -pl.figure(3, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') - -############################################################################## -# Solve EMD with Frobenius norm regularization -# -------------------------------------------- - -#%% Example with Frobenius norm regularization - - -def f(G): - return 0.5 * np.sum(G**2) - - -def df(G): - return G - - -reg = 1e-1 - -Gl2 = ot.optim.cg(a, b, M, reg, f, df, verbose=True) - -pl.figure(3) -ot.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg') - -############################################################################## -# Solve EMD with entropic regularization -# -------------------------------------- - -#%% Example with entropic regularization - - -def f(G): - return np.sum(G * np.log(G)) - - -def df(G): - return np.log(G) + 1. - - -reg = 1e-3 - -Ge = ot.optim.cg(a, b, M, reg, f, df, verbose=True) - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg') - -############################################################################## -# Solve EMD with Frobenius norm + entropic regularization -# ------------------------------------------------------- - -#%% Example with Frobenius norm + entropic regularization with gcg - - -def f(G): - return 0.5 * np.sum(G**2) - - -def df(G): - return G - - -reg1 = 1e-3 -reg2 = 1e-1 - -Gel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True) - -pl.figure(5, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg') -pl.show() diff --git a/docs/source/auto_examples/plot_optim_OTreg.rst b/docs/source/auto_examples/plot_optim_OTreg.rst deleted file mode 100644 index cd5bcf5..0000000 --- a/docs/source/auto_examples/plot_optim_OTreg.rst +++ /dev/null @@ -1,593 +0,0 @@ -.. 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_optim_OTreg.py: - - -================================== -Regularized OT with generic solver -================================== - -Illustrates the use of the generic solver for regularized OT with -user-designed regularization term. It uses Conditional gradient as in [6] and -generalized Conditional Gradient as proposed in [5][7]. - - -[5] N. Courty; R. Flamary; D. Tuia; A. Rakotomamonjy, Optimal Transport for -Domain Adaptation, in IEEE Transactions on Pattern Analysis and Machine -Intelligence , vol.PP, no.99, pp.1-1. - -[6] Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). -Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, -7(3), 1853-1882. - -[7] Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized -conditional gradient: analysis of convergence and applications. -arXiv preprint arXiv:1510.06567. - - - - - -.. code-block:: default - - - import numpy as np - import matplotlib.pylab as pl - import ot - import ot.plot - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - n = 100 # nb bins - - # bin positions - x = np.arange(n, dtype=np.float64) - - # Gaussian distributions - a = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std - b = ot.datasets.make_1D_gauss(n, m=60, s=10) - - # loss matrix - M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) - M /= M.max() - - - - - - - - -Solve EMD ---------- - - -.. code-block:: default - - - G0 = ot.emd(a, b, M) - - pl.figure(3, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_001.png - :class: sphx-glr-single-img - - - - - -Solve EMD with Frobenius norm regularization --------------------------------------------- - - -.. code-block:: default - - - - def f(G): - return 0.5 * np.sum(G**2) - - - def df(G): - return G - - - reg = 1e-1 - - Gl2 = ot.optim.cg(a, b, M, reg, f, df, verbose=True) - - pl.figure(3) - ot.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 0|1.760578e-01|0.000000e+00|0.000000e+00 - 1|1.669467e-01|5.457501e-02|9.111116e-03 - 2|1.665639e-01|2.298130e-03|3.827855e-04 - 3|1.664378e-01|7.572776e-04|1.260396e-04 - 4|1.664077e-01|1.811855e-04|3.015066e-05 - 5|1.663912e-01|9.936787e-05|1.653393e-05 - 6|1.663852e-01|3.555826e-05|5.916369e-06 - 7|1.663814e-01|2.305693e-05|3.836245e-06 - 8|1.663785e-01|1.760450e-05|2.929009e-06 - 9|1.663767e-01|1.078011e-05|1.793559e-06 - 10|1.663751e-01|9.525192e-06|1.584755e-06 - 11|1.663737e-01|8.396466e-06|1.396951e-06 - 12|1.663727e-01|6.086938e-06|1.012700e-06 - 13|1.663720e-01|4.042609e-06|6.725769e-07 - 14|1.663713e-01|4.160914e-06|6.922568e-07 - 15|1.663707e-01|3.823502e-06|6.361187e-07 - 16|1.663702e-01|3.022440e-06|5.028438e-07 - 17|1.663697e-01|3.181249e-06|5.292634e-07 - 18|1.663692e-01|2.698532e-06|4.489527e-07 - 19|1.663687e-01|3.258253e-06|5.420712e-07 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 20|1.663682e-01|2.741118e-06|4.560349e-07 - 21|1.663678e-01|2.624135e-06|4.365715e-07 - 22|1.663673e-01|2.645179e-06|4.400714e-07 - 23|1.663670e-01|1.957237e-06|3.256196e-07 - 24|1.663666e-01|2.261541e-06|3.762450e-07 - 25|1.663663e-01|1.851305e-06|3.079948e-07 - 26|1.663660e-01|1.942296e-06|3.231320e-07 - 27|1.663657e-01|2.092896e-06|3.481860e-07 - 28|1.663653e-01|1.924361e-06|3.201470e-07 - 29|1.663651e-01|1.625455e-06|2.704189e-07 - 30|1.663648e-01|1.641123e-06|2.730250e-07 - 31|1.663645e-01|1.566666e-06|2.606377e-07 - 32|1.663643e-01|1.338514e-06|2.226810e-07 - 33|1.663641e-01|1.222711e-06|2.034152e-07 - 34|1.663639e-01|1.221805e-06|2.032642e-07 - 35|1.663637e-01|1.440781e-06|2.396935e-07 - 36|1.663634e-01|1.520091e-06|2.528875e-07 - 37|1.663632e-01|1.288193e-06|2.143080e-07 - 38|1.663630e-01|1.123055e-06|1.868347e-07 - 39|1.663628e-01|1.024487e-06|1.704365e-07 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 40|1.663627e-01|1.079606e-06|1.796061e-07 - 41|1.663625e-01|1.172093e-06|1.949922e-07 - 42|1.663623e-01|1.047880e-06|1.743277e-07 - 43|1.663621e-01|1.010577e-06|1.681217e-07 - 44|1.663619e-01|1.064438e-06|1.770820e-07 - 45|1.663618e-01|9.882375e-07|1.644049e-07 - 46|1.663616e-01|8.532647e-07|1.419505e-07 - 47|1.663615e-01|9.930189e-07|1.652001e-07 - 48|1.663613e-01|8.728955e-07|1.452161e-07 - 49|1.663612e-01|9.524214e-07|1.584459e-07 - 50|1.663610e-01|9.088418e-07|1.511958e-07 - 51|1.663609e-01|7.639430e-07|1.270902e-07 - 52|1.663608e-01|6.662611e-07|1.108397e-07 - 53|1.663607e-01|7.133700e-07|1.186767e-07 - 54|1.663605e-01|7.648141e-07|1.272349e-07 - 55|1.663604e-01|6.557516e-07|1.090911e-07 - 56|1.663603e-01|7.304213e-07|1.215131e-07 - 57|1.663602e-01|6.353809e-07|1.057021e-07 - 58|1.663601e-01|7.968279e-07|1.325603e-07 - 59|1.663600e-01|6.367159e-07|1.059240e-07 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 60|1.663599e-01|5.610790e-07|9.334102e-08 - 61|1.663598e-01|5.787466e-07|9.628015e-08 - 62|1.663596e-01|6.937777e-07|1.154166e-07 - 63|1.663596e-01|5.599432e-07|9.315190e-08 - 64|1.663595e-01|5.813048e-07|9.670555e-08 - 65|1.663594e-01|5.724600e-07|9.523409e-08 - 66|1.663593e-01|6.081892e-07|1.011779e-07 - 67|1.663592e-01|5.948732e-07|9.896260e-08 - 68|1.663591e-01|4.941833e-07|8.221188e-08 - 69|1.663590e-01|5.213739e-07|8.673523e-08 - 70|1.663589e-01|5.127355e-07|8.529811e-08 - 71|1.663588e-01|4.349251e-07|7.235363e-08 - 72|1.663588e-01|5.007084e-07|8.329722e-08 - 73|1.663587e-01|4.880265e-07|8.118744e-08 - 74|1.663586e-01|4.931950e-07|8.204723e-08 - 75|1.663585e-01|4.981309e-07|8.286832e-08 - 76|1.663584e-01|3.952959e-07|6.576082e-08 - 77|1.663584e-01|4.544857e-07|7.560750e-08 - 78|1.663583e-01|4.237579e-07|7.049564e-08 - 79|1.663582e-01|4.382386e-07|7.290460e-08 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 80|1.663582e-01|3.646051e-07|6.065503e-08 - 81|1.663581e-01|4.197994e-07|6.983702e-08 - 82|1.663580e-01|4.072764e-07|6.775370e-08 - 83|1.663580e-01|3.994645e-07|6.645410e-08 - 84|1.663579e-01|4.842721e-07|8.056248e-08 - 85|1.663578e-01|3.276486e-07|5.450691e-08 - 86|1.663578e-01|3.737346e-07|6.217366e-08 - 87|1.663577e-01|4.282043e-07|7.123508e-08 - 88|1.663576e-01|4.020937e-07|6.689135e-08 - 89|1.663576e-01|3.431951e-07|5.709310e-08 - 90|1.663575e-01|3.052335e-07|5.077789e-08 - 91|1.663575e-01|3.500538e-07|5.823407e-08 - 92|1.663574e-01|3.063176e-07|5.095821e-08 - 93|1.663573e-01|3.576367e-07|5.949549e-08 - 94|1.663573e-01|3.224681e-07|5.364492e-08 - 95|1.663572e-01|3.673221e-07|6.110670e-08 - 96|1.663572e-01|3.635561e-07|6.048017e-08 - 97|1.663571e-01|3.527236e-07|5.867807e-08 - 98|1.663571e-01|2.788548e-07|4.638946e-08 - 99|1.663570e-01|2.727141e-07|4.536791e-08 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 100|1.663570e-01|3.127278e-07|5.202445e-08 - 101|1.663569e-01|2.637504e-07|4.387670e-08 - 102|1.663569e-01|2.922750e-07|4.862195e-08 - 103|1.663568e-01|3.076454e-07|5.117891e-08 - 104|1.663568e-01|2.911509e-07|4.843492e-08 - 105|1.663567e-01|2.403398e-07|3.998215e-08 - 106|1.663567e-01|2.439790e-07|4.058755e-08 - 107|1.663567e-01|2.634542e-07|4.382735e-08 - 108|1.663566e-01|2.452203e-07|4.079401e-08 - 109|1.663566e-01|2.852991e-07|4.746137e-08 - 110|1.663565e-01|2.165490e-07|3.602434e-08 - 111|1.663565e-01|2.450250e-07|4.076149e-08 - 112|1.663564e-01|2.685294e-07|4.467159e-08 - 113|1.663564e-01|2.821800e-07|4.694245e-08 - 114|1.663564e-01|2.237390e-07|3.722040e-08 - 115|1.663563e-01|1.992842e-07|3.315219e-08 - 116|1.663563e-01|2.166739e-07|3.604506e-08 - 117|1.663563e-01|2.086064e-07|3.470297e-08 - 118|1.663562e-01|2.435945e-07|4.052346e-08 - 119|1.663562e-01|2.292497e-07|3.813711e-08 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 120|1.663561e-01|2.366209e-07|3.936334e-08 - 121|1.663561e-01|2.138746e-07|3.557935e-08 - 122|1.663561e-01|2.009637e-07|3.343153e-08 - 123|1.663560e-01|2.386258e-07|3.969683e-08 - 124|1.663560e-01|1.927442e-07|3.206415e-08 - 125|1.663560e-01|2.081681e-07|3.463000e-08 - 126|1.663559e-01|1.759123e-07|2.926406e-08 - 127|1.663559e-01|1.890771e-07|3.145409e-08 - 128|1.663559e-01|1.971315e-07|3.279398e-08 - 129|1.663558e-01|2.101983e-07|3.496771e-08 - 130|1.663558e-01|2.035645e-07|3.386414e-08 - 131|1.663558e-01|1.984492e-07|3.301317e-08 - 132|1.663557e-01|1.849064e-07|3.076024e-08 - 133|1.663557e-01|1.795703e-07|2.987255e-08 - 134|1.663557e-01|1.624087e-07|2.701762e-08 - 135|1.663557e-01|1.689557e-07|2.810673e-08 - 136|1.663556e-01|1.644308e-07|2.735399e-08 - 137|1.663556e-01|1.618007e-07|2.691644e-08 - 138|1.663556e-01|1.483013e-07|2.467075e-08 - 139|1.663555e-01|1.708771e-07|2.842636e-08 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 140|1.663555e-01|2.013847e-07|3.350146e-08 - 141|1.663555e-01|1.721217e-07|2.863339e-08 - 142|1.663554e-01|2.027911e-07|3.373540e-08 - 143|1.663554e-01|1.764565e-07|2.935449e-08 - 144|1.663554e-01|1.677151e-07|2.790030e-08 - 145|1.663554e-01|1.351982e-07|2.249094e-08 - 146|1.663553e-01|1.423360e-07|2.367836e-08 - 147|1.663553e-01|1.541112e-07|2.563722e-08 - 148|1.663553e-01|1.491601e-07|2.481358e-08 - 149|1.663553e-01|1.466407e-07|2.439446e-08 - 150|1.663552e-01|1.801524e-07|2.996929e-08 - 151|1.663552e-01|1.714107e-07|2.851507e-08 - 152|1.663552e-01|1.491257e-07|2.480784e-08 - 153|1.663552e-01|1.513799e-07|2.518282e-08 - 154|1.663551e-01|1.354539e-07|2.253345e-08 - 155|1.663551e-01|1.233818e-07|2.052519e-08 - 156|1.663551e-01|1.576219e-07|2.622121e-08 - 157|1.663551e-01|1.452791e-07|2.416792e-08 - 158|1.663550e-01|1.262867e-07|2.100843e-08 - 159|1.663550e-01|1.316379e-07|2.189863e-08 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 160|1.663550e-01|1.295447e-07|2.155041e-08 - 161|1.663550e-01|1.283286e-07|2.134810e-08 - 162|1.663550e-01|1.569222e-07|2.610479e-08 - 163|1.663549e-01|1.172942e-07|1.951247e-08 - 164|1.663549e-01|1.399809e-07|2.328651e-08 - 165|1.663549e-01|1.229432e-07|2.045221e-08 - 166|1.663549e-01|1.326191e-07|2.206184e-08 - 167|1.663548e-01|1.209694e-07|2.012384e-08 - 168|1.663548e-01|1.372136e-07|2.282614e-08 - 169|1.663548e-01|1.338395e-07|2.226484e-08 - 170|1.663548e-01|1.416497e-07|2.356410e-08 - 171|1.663548e-01|1.298576e-07|2.160242e-08 - 172|1.663547e-01|1.190590e-07|1.980603e-08 - 173|1.663547e-01|1.167083e-07|1.941497e-08 - 174|1.663547e-01|1.069425e-07|1.779038e-08 - 175|1.663547e-01|1.217780e-07|2.025834e-08 - 176|1.663547e-01|1.140754e-07|1.897697e-08 - 177|1.663546e-01|1.160707e-07|1.930890e-08 - 178|1.663546e-01|1.101798e-07|1.832892e-08 - 179|1.663546e-01|1.114904e-07|1.854694e-08 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 180|1.663546e-01|1.064022e-07|1.770049e-08 - 181|1.663546e-01|9.258231e-08|1.540149e-08 - 182|1.663546e-01|1.213120e-07|2.018080e-08 - 183|1.663545e-01|1.164296e-07|1.936859e-08 - 184|1.663545e-01|1.188762e-07|1.977559e-08 - 185|1.663545e-01|9.394153e-08|1.562760e-08 - 186|1.663545e-01|1.028656e-07|1.711216e-08 - 187|1.663545e-01|1.115348e-07|1.855431e-08 - 188|1.663544e-01|9.768310e-08|1.625002e-08 - 189|1.663544e-01|1.021806e-07|1.699820e-08 - 190|1.663544e-01|1.086303e-07|1.807113e-08 - 191|1.663544e-01|9.879008e-08|1.643416e-08 - 192|1.663544e-01|1.050210e-07|1.747071e-08 - 193|1.663544e-01|1.002463e-07|1.667641e-08 - 194|1.663543e-01|1.062747e-07|1.767925e-08 - 195|1.663543e-01|9.348538e-08|1.555170e-08 - 196|1.663543e-01|7.992512e-08|1.329589e-08 - 197|1.663543e-01|9.558020e-08|1.590018e-08 - 198|1.663543e-01|9.993772e-08|1.662507e-08 - 199|1.663543e-01|8.588499e-08|1.428734e-08 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 200|1.663543e-01|8.737134e-08|1.453459e-08 - - - - -Solve EMD with entropic regularization --------------------------------------- - - -.. code-block:: default - - - - def f(G): - return np.sum(G * np.log(G)) - - - def df(G): - return np.log(G) + 1. - - - reg = 1e-3 - - Ge = ot.optim.cg(a, b, M, reg, f, df, verbose=True) - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 0|1.692289e-01|0.000000e+00|0.000000e+00 - 1|1.617643e-01|4.614437e-02|7.464513e-03 - 2|1.612639e-01|3.102965e-03|5.003963e-04 - 3|1.611291e-01|8.371098e-04|1.348827e-04 - 4|1.610468e-01|5.110558e-04|8.230389e-05 - 5|1.610198e-01|1.672927e-04|2.693743e-05 - 6|1.610130e-01|4.232417e-05|6.814742e-06 - 7|1.610090e-01|2.513455e-05|4.046887e-06 - 8|1.610002e-01|5.443507e-05|8.764057e-06 - 9|1.609996e-01|3.657071e-06|5.887869e-07 - 10|1.609948e-01|2.998735e-05|4.827807e-06 - 11|1.609695e-01|1.569217e-04|2.525962e-05 - 12|1.609533e-01|1.010779e-04|1.626881e-05 - 13|1.609520e-01|8.043897e-06|1.294681e-06 - 14|1.609465e-01|3.415246e-05|5.496718e-06 - 15|1.609386e-01|4.898605e-05|7.883745e-06 - 16|1.609324e-01|3.837052e-05|6.175060e-06 - 17|1.609298e-01|1.617826e-05|2.603564e-06 - 18|1.609184e-01|7.080015e-05|1.139305e-05 - 19|1.609083e-01|6.273206e-05|1.009411e-05 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 20|1.608988e-01|5.940805e-05|9.558681e-06 - 21|1.608853e-01|8.380030e-05|1.348223e-05 - 22|1.608844e-01|5.185045e-06|8.341930e-07 - 23|1.608824e-01|1.279113e-05|2.057868e-06 - 24|1.608819e-01|3.156821e-06|5.078753e-07 - 25|1.608783e-01|2.205746e-05|3.548567e-06 - 26|1.608764e-01|1.189894e-05|1.914259e-06 - 27|1.608755e-01|5.474607e-06|8.807303e-07 - 28|1.608737e-01|1.144227e-05|1.840760e-06 - 29|1.608676e-01|3.775335e-05|6.073291e-06 - 30|1.608638e-01|2.348020e-05|3.777116e-06 - 31|1.608627e-01|6.863136e-06|1.104023e-06 - 32|1.608529e-01|6.110230e-05|9.828482e-06 - 33|1.608487e-01|2.641106e-05|4.248184e-06 - 34|1.608409e-01|4.823638e-05|7.758383e-06 - 35|1.608373e-01|2.256641e-05|3.629519e-06 - 36|1.608338e-01|2.132444e-05|3.429691e-06 - 37|1.608310e-01|1.786649e-05|2.873484e-06 - 38|1.608260e-01|3.103848e-05|4.991794e-06 - 39|1.608206e-01|3.321265e-05|5.341279e-06 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 40|1.608201e-01|3.054747e-06|4.912648e-07 - 41|1.608195e-01|4.198335e-06|6.751739e-07 - 42|1.608193e-01|8.458736e-07|1.360328e-07 - 43|1.608159e-01|2.153759e-05|3.463587e-06 - 44|1.608115e-01|2.738314e-05|4.403523e-06 - 45|1.608108e-01|3.960032e-06|6.368161e-07 - 46|1.608081e-01|1.675447e-05|2.694254e-06 - 47|1.608072e-01|5.976340e-06|9.610383e-07 - 48|1.608046e-01|1.604130e-05|2.579515e-06 - 49|1.608020e-01|1.617036e-05|2.600226e-06 - 50|1.608014e-01|3.957795e-06|6.364188e-07 - 51|1.608011e-01|1.292411e-06|2.078211e-07 - 52|1.607998e-01|8.431795e-06|1.355831e-06 - 53|1.607964e-01|2.127054e-05|3.420225e-06 - 54|1.607947e-01|1.021878e-05|1.643126e-06 - 55|1.607947e-01|3.560621e-07|5.725288e-08 - 56|1.607900e-01|2.929781e-05|4.710793e-06 - 57|1.607890e-01|5.740229e-06|9.229659e-07 - 58|1.607858e-01|2.039550e-05|3.279306e-06 - 59|1.607836e-01|1.319545e-05|2.121612e-06 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 60|1.607826e-01|6.378947e-06|1.025624e-06 - 61|1.607808e-01|1.145102e-05|1.841105e-06 - 62|1.607776e-01|1.941743e-05|3.121889e-06 - 63|1.607743e-01|2.087422e-05|3.356037e-06 - 64|1.607741e-01|1.310249e-06|2.106541e-07 - 65|1.607738e-01|1.682752e-06|2.705425e-07 - 66|1.607691e-01|2.913936e-05|4.684709e-06 - 67|1.607671e-01|1.288855e-05|2.072055e-06 - 68|1.607654e-01|1.002448e-05|1.611590e-06 - 69|1.607641e-01|8.209492e-06|1.319792e-06 - 70|1.607632e-01|5.588467e-06|8.984199e-07 - 71|1.607619e-01|8.050388e-06|1.294196e-06 - 72|1.607618e-01|9.417493e-07|1.513973e-07 - 73|1.607598e-01|1.210509e-05|1.946012e-06 - 74|1.607591e-01|4.392914e-06|7.062009e-07 - 75|1.607579e-01|7.759587e-06|1.247415e-06 - 76|1.607574e-01|2.760280e-06|4.437356e-07 - 77|1.607556e-01|1.146469e-05|1.843012e-06 - 78|1.607550e-01|3.689456e-06|5.930984e-07 - 79|1.607550e-01|4.065631e-08|6.535705e-09 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 80|1.607539e-01|6.555681e-06|1.053852e-06 - 81|1.607528e-01|7.177470e-06|1.153798e-06 - 82|1.607527e-01|5.306068e-07|8.529648e-08 - 83|1.607514e-01|7.816045e-06|1.256440e-06 - 84|1.607511e-01|2.301970e-06|3.700442e-07 - 85|1.607504e-01|4.281072e-06|6.881840e-07 - 86|1.607503e-01|7.821886e-07|1.257370e-07 - 87|1.607480e-01|1.403013e-05|2.255315e-06 - 88|1.607480e-01|1.169298e-08|1.879624e-09 - 89|1.607473e-01|4.235982e-06|6.809227e-07 - 90|1.607470e-01|1.717105e-06|2.760195e-07 - 91|1.607470e-01|6.148402e-09|9.883374e-10 - - - - -Solve EMD with Frobenius norm + entropic regularization -------------------------------------------------------- - - -.. code-block:: default - - - - def f(G): - return 0.5 * np.sum(G**2) - - - def df(G): - return G - - - reg1 = 1e-3 - reg2 = 1e-1 - - Gel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True) - - pl.figure(5, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg') - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_004.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 0|1.693084e-01|0.000000e+00|0.000000e+00 - 1|1.610202e-01|5.147342e-02|8.288260e-03 - 2|1.609508e-01|4.309685e-04|6.936474e-05 - 3|1.609484e-01|1.524885e-05|2.454278e-06 - 4|1.609477e-01|3.863641e-06|6.218444e-07 - 5|1.609475e-01|1.433633e-06|2.307397e-07 - 6|1.609474e-01|6.332412e-07|1.019185e-07 - 7|1.609474e-01|2.950826e-07|4.749276e-08 - 8|1.609473e-01|1.508393e-07|2.427718e-08 - 9|1.609473e-01|7.859971e-08|1.265041e-08 - 10|1.609473e-01|4.337432e-08|6.980981e-09 - /home/rflamary/PYTHON/POT/examples/plot_optim_OTreg.py:129: 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 0.985 seconds) - - -.. _sphx_glr_download_auto_examples_plot_optim_OTreg.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_optim_OTreg.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_optim_OTreg.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_classes.ipynb b/docs/source/auto_examples/plot_otda_classes.ipynb deleted file mode 100644 index 283d227..0000000 --- a/docs/source/auto_examples/plot_otda_classes.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# OT for domain adaptation\n\n\nThis example introduces a domain adaptation in a 2D setting and the 4 OTDA\napproaches currently supported in POT.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \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=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\n\n# Sinkhorn Transport with Group lasso regularization\not_lpl1 = ot.da.SinkhornLpl1Transport(reg_e=1e-1, reg_cl=1e0)\not_lpl1.fit(Xs=Xs, ys=ys, Xt=Xt)\n\n# Sinkhorn Transport with Group lasso regularization l1l2\not_l1l2 = ot.da.SinkhornL1l2Transport(reg_e=1e-1, reg_cl=2e0, max_iter=20,\n verbose=True)\not_l1l2.fit(Xs=Xs, ys=ys, 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_lpl1 = ot_lpl1.transform(Xs=Xs)\ntransp_Xs_l1l2 = ot_l1l2.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, 4, 1)\npl.imshow(ot_emd.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nEMDTransport')\n\npl.subplot(2, 4, 2)\npl.imshow(ot_sinkhorn.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSinkhornTransport')\n\npl.subplot(2, 4, 3)\npl.imshow(ot_lpl1.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSinkhornLpl1Transport')\n\npl.subplot(2, 4, 4)\npl.imshow(ot_l1l2.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSinkhornL1l2Transport')\n\npl.subplot(2, 4, 5)\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, 4, 6)\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, 4, 7)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_lpl1[:, 0], transp_Xs_lpl1[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nSinkhornLpl1Transport')\n\npl.subplot(2, 4, 8)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_l1l2[:, 0], transp_Xs_l1l2[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nSinkhornL1l2Transport')\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_classes.py b/docs/source/auto_examples/plot_otda_classes.py deleted file mode 100644 index f028022..0000000 --- a/docs/source/auto_examples/plot_otda_classes.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -""" -======================== -OT for domain adaptation -======================== - -This example introduces a domain adaptation in a 2D setting and the 4 OTDA -approaches currently supported in POT. - -""" - -# Authors: Remi Flamary -# Stanislas Chambon -# -# 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=1e-1) -ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - -# Sinkhorn Transport with Group lasso regularization -ot_lpl1 = ot.da.SinkhornLpl1Transport(reg_e=1e-1, reg_cl=1e0) -ot_lpl1.fit(Xs=Xs, ys=ys, Xt=Xt) - -# Sinkhorn Transport with Group lasso regularization l1l2 -ot_l1l2 = ot.da.SinkhornL1l2Transport(reg_e=1e-1, reg_cl=2e0, max_iter=20, - verbose=True) -ot_l1l2.fit(Xs=Xs, ys=ys, 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_lpl1 = ot_lpl1.transform(Xs=Xs) -transp_Xs_l1l2 = ot_l1l2.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, 4, 1) -pl.imshow(ot_emd.coupling_, **param_img) -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nEMDTransport') - -pl.subplot(2, 4, 2) -pl.imshow(ot_sinkhorn.coupling_, **param_img) -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nSinkhornTransport') - -pl.subplot(2, 4, 3) -pl.imshow(ot_lpl1.coupling_, **param_img) -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nSinkhornLpl1Transport') - -pl.subplot(2, 4, 4) -pl.imshow(ot_l1l2.coupling_, **param_img) -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nSinkhornL1l2Transport') - -pl.subplot(2, 4, 5) -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, 4, 6) -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, 4, 7) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.3) -pl.scatter(transp_Xs_lpl1[:, 0], transp_Xs_lpl1[:, 1], c=ys, - marker='+', label='Transp samples', s=30) -pl.xticks([]) -pl.yticks([]) -pl.title('Transported samples\nSinkhornLpl1Transport') - -pl.subplot(2, 4, 8) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.3) -pl.scatter(transp_Xs_l1l2[:, 0], transp_Xs_l1l2[:, 1], c=ys, - marker='+', label='Transp samples', s=30) -pl.xticks([]) -pl.yticks([]) -pl.title('Transported samples\nSinkhornL1l2Transport') -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_otda_classes.rst b/docs/source/auto_examples/plot_otda_classes.rst deleted file mode 100644 index 9cf31ee..0000000 --- a/docs/source/auto_examples/plot_otda_classes.rst +++ /dev/null @@ -1,287 +0,0 @@ -.. 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_otda_classes.py: - - -======================== -OT for domain adaptation -======================== - -This example introduces a domain adaptation in a 2D setting and the 4 OTDA -approaches currently supported in POT. - - - -.. code-block:: default - - - # Authors: Remi Flamary - # Stanislas Chambon - # - # 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=1e-1) - ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - - # Sinkhorn Transport with Group lasso regularization - ot_lpl1 = ot.da.SinkhornLpl1Transport(reg_e=1e-1, reg_cl=1e0) - ot_lpl1.fit(Xs=Xs, ys=ys, Xt=Xt) - - # Sinkhorn Transport with Group lasso regularization l1l2 - ot_l1l2 = ot.da.SinkhornL1l2Transport(reg_e=1e-1, reg_cl=2e0, max_iter=20, - verbose=True) - ot_l1l2.fit(Xs=Xs, ys=ys, 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_lpl1 = ot_lpl1.transform(Xs=Xs) - transp_Xs_l1l2 = ot_l1l2.transform(Xs=Xs) - - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 0|9.484039e+00|0.000000e+00|0.000000e+00 - 1|1.976107e+00|3.799355e+00|7.507932e+00 - 2|1.749871e+00|1.292876e-01|2.262365e-01 - 3|1.692667e+00|3.379504e-02|5.720374e-02 - 4|1.676256e+00|9.790077e-03|1.641068e-02 - 5|1.667458e+00|5.276422e-03|8.798212e-03 - 6|1.661775e+00|3.419693e-03|5.682762e-03 - 7|1.658009e+00|2.271789e-03|3.766646e-03 - 8|1.655167e+00|1.716870e-03|2.841707e-03 - 9|1.651825e+00|2.023380e-03|3.342270e-03 - 10|1.649431e+00|1.451076e-03|2.393450e-03 - 11|1.648649e+00|4.742894e-04|7.819369e-04 - 12|1.647901e+00|4.538219e-04|7.478538e-04 - 13|1.647356e+00|3.313134e-04|5.457909e-04 - 14|1.646923e+00|2.627246e-04|4.326871e-04 - 15|1.646038e+00|5.375014e-04|8.847478e-04 - 16|1.645629e+00|2.483240e-04|4.086492e-04 - 17|1.645616e+00|8.248172e-06|1.357332e-05 - 18|1.645377e+00|1.452648e-04|2.390153e-04 - 19|1.644745e+00|3.838976e-04|6.314139e-04 - It. |Loss |Relative loss|Absolute loss - ------------------------------------------------ - 20|1.644164e+00|3.538439e-04|5.817773e-04 - - - - -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_classes_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, 4, 1) - pl.imshow(ot_emd.coupling_, **param_img) - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nEMDTransport') - - pl.subplot(2, 4, 2) - pl.imshow(ot_sinkhorn.coupling_, **param_img) - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nSinkhornTransport') - - pl.subplot(2, 4, 3) - pl.imshow(ot_lpl1.coupling_, **param_img) - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nSinkhornLpl1Transport') - - pl.subplot(2, 4, 4) - pl.imshow(ot_l1l2.coupling_, **param_img) - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nSinkhornL1l2Transport') - - pl.subplot(2, 4, 5) - 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, 4, 6) - 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, 4, 7) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.3) - pl.scatter(transp_Xs_lpl1[:, 0], transp_Xs_lpl1[:, 1], c=ys, - marker='+', label='Transp samples', s=30) - pl.xticks([]) - pl.yticks([]) - pl.title('Transported samples\nSinkhornLpl1Transport') - - pl.subplot(2, 4, 8) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.3) - pl.scatter(transp_Xs_l1l2[:, 0], transp_Xs_l1l2[:, 1], c=ys, - marker='+', label='Transp samples', s=30) - pl.xticks([]) - pl.yticks([]) - pl.title('Transported samples\nSinkhornL1l2Transport') - pl.tight_layout() - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_classes_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_classes.py:149: 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 2.083 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_classes.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_classes.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_classes.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_color_images.ipynb b/docs/source/auto_examples/plot_otda_color_images.ipynb deleted file mode 100644 index c2afd41..0000000 --- a/docs/source/auto_examples/plot_otda_color_images.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# OT for image color adaptation\n\n\nThis example presents a way of transferring colors between two images\nwith Optimal Transport as introduced in [6]\n\n[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014).\nRegularized discrete optimal transport.\nSIAM Journal on Imaging Sciences, 7(3), 1853-1882.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\n\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts an image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Loading images\nI1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot original image\n-------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\n\npl.subplot(1, 2, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Scatter plot of colors\n----------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(6.4, 3))\n\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 2], c=Xs)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 2], c=Xt)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 2')\npl.tight_layout()" - ] - }, - { - "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": [ - "# EMDTransport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\n\n# SinkhornTransport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\n\n# prediction between images (using out of sample prediction as in [6])\ntransp_Xs_emd = ot_emd.transform(Xs=X1)\ntransp_Xt_emd = ot_emd.inverse_transform(Xt=X2)\n\ntransp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1)\ntransp_Xt_sinkhorn = ot_sinkhorn.inverse_transform(Xt=X2)\n\nI1t = minmax(mat2im(transp_Xs_emd, I1.shape))\nI2t = minmax(mat2im(transp_Xt_emd, I2.shape))\n\nI1te = minmax(mat2im(transp_Xs_sinkhorn, I1.shape))\nI2te = minmax(mat2im(transp_Xt_sinkhorn, I2.shape))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot new images\n---------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(3, figsize=(8, 4))\n\npl.subplot(2, 3, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(2, 3, 2)\npl.imshow(I1t)\npl.axis('off')\npl.title('Image 1 Adapt')\n\npl.subplot(2, 3, 3)\npl.imshow(I1te)\npl.axis('off')\npl.title('Image 1 Adapt (reg)')\n\npl.subplot(2, 3, 4)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')\n\npl.subplot(2, 3, 5)\npl.imshow(I2t)\npl.axis('off')\npl.title('Image 2 Adapt')\n\npl.subplot(2, 3, 6)\npl.imshow(I2te)\npl.axis('off')\npl.title('Image 2 Adapt (reg)')\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_color_images.py b/docs/source/auto_examples/plot_otda_color_images.py deleted file mode 100644 index d9cbd2b..0000000 --- a/docs/source/auto_examples/plot_otda_color_images.py +++ /dev/null @@ -1,164 +0,0 @@ -# -*- coding: utf-8 -*- -""" -============================= -OT for image color adaptation -============================= - -This example presents a way of transferring colors between two images -with Optimal Transport as introduced in [6] - -[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). -Regularized discrete optimal transport. -SIAM Journal on Imaging Sciences, 7(3), 1853-1882. -""" - -# Authors: Remi Flamary -# Stanislas Chambon -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot - - -r = np.random.RandomState(42) - - -def im2mat(I): - """Converts an image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - -def mat2im(X, shape): - """Converts back a matrix to an image""" - return X.reshape(shape) - - -def minmax(I): - return np.clip(I, 0, 1) - - -############################################################################## -# Generate data -# ------------- - -# Loading images -I1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256 -I2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 - -X1 = im2mat(I1) -X2 = im2mat(I2) - -# training samples -nb = 1000 -idx1 = r.randint(X1.shape[0], size=(nb,)) -idx2 = r.randint(X2.shape[0], size=(nb,)) - -Xs = X1[idx1, :] -Xt = X2[idx2, :] - - -############################################################################## -# Plot original image -# ------------------- - -pl.figure(1, figsize=(6.4, 3)) - -pl.subplot(1, 2, 1) -pl.imshow(I1) -pl.axis('off') -pl.title('Image 1') - -pl.subplot(1, 2, 2) -pl.imshow(I2) -pl.axis('off') -pl.title('Image 2') - - -############################################################################## -# Scatter plot of colors -# ---------------------- - -pl.figure(2, figsize=(6.4, 3)) - -pl.subplot(1, 2, 1) -pl.scatter(Xs[:, 0], Xs[:, 2], c=Xs) -pl.axis([0, 1, 0, 1]) -pl.xlabel('Red') -pl.ylabel('Blue') -pl.title('Image 1') - -pl.subplot(1, 2, 2) -pl.scatter(Xt[:, 0], Xt[:, 2], c=Xt) -pl.axis([0, 1, 0, 1]) -pl.xlabel('Red') -pl.ylabel('Blue') -pl.title('Image 2') -pl.tight_layout() - - -############################################################################## -# Instantiate the different transport algorithms and fit them -# ----------------------------------------------------------- - -# EMDTransport -ot_emd = ot.da.EMDTransport() -ot_emd.fit(Xs=Xs, Xt=Xt) - -# SinkhornTransport -ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) -ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - -# prediction between images (using out of sample prediction as in [6]) -transp_Xs_emd = ot_emd.transform(Xs=X1) -transp_Xt_emd = ot_emd.inverse_transform(Xt=X2) - -transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) -transp_Xt_sinkhorn = ot_sinkhorn.inverse_transform(Xt=X2) - -I1t = minmax(mat2im(transp_Xs_emd, I1.shape)) -I2t = minmax(mat2im(transp_Xt_emd, I2.shape)) - -I1te = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) -I2te = minmax(mat2im(transp_Xt_sinkhorn, I2.shape)) - - -############################################################################## -# Plot new images -# --------------- - -pl.figure(3, figsize=(8, 4)) - -pl.subplot(2, 3, 1) -pl.imshow(I1) -pl.axis('off') -pl.title('Image 1') - -pl.subplot(2, 3, 2) -pl.imshow(I1t) -pl.axis('off') -pl.title('Image 1 Adapt') - -pl.subplot(2, 3, 3) -pl.imshow(I1te) -pl.axis('off') -pl.title('Image 1 Adapt (reg)') - -pl.subplot(2, 3, 4) -pl.imshow(I2) -pl.axis('off') -pl.title('Image 2') - -pl.subplot(2, 3, 5) -pl.imshow(I2t) -pl.axis('off') -pl.title('Image 2 Adapt') - -pl.subplot(2, 3, 6) -pl.imshow(I2te) -pl.axis('off') -pl.title('Image 2 Adapt (reg)') -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_otda_color_images.rst b/docs/source/auto_examples/plot_otda_color_images.rst deleted file mode 100644 index a5b0d53..0000000 --- a/docs/source/auto_examples/plot_otda_color_images.rst +++ /dev/null @@ -1,291 +0,0 @@ -.. 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_otda_color_images.py: - - -============================= -OT for image color adaptation -============================= - -This example presents a way of transferring colors between two images -with Optimal Transport as introduced in [6] - -[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). -Regularized discrete optimal transport. -SIAM Journal on Imaging Sciences, 7(3), 1853-1882. - - -.. code-block:: default - - - # Authors: Remi Flamary - # Stanislas Chambon - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - - - r = np.random.RandomState(42) - - - def im2mat(I): - """Converts an image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - - def mat2im(X, shape): - """Converts back a matrix to an image""" - return X.reshape(shape) - - - def minmax(I): - return np.clip(I, 0, 1) - - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - # Loading images - I1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256 - I2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 - - X1 = im2mat(I1) - X2 = im2mat(I2) - - # training samples - nb = 1000 - idx1 = r.randint(X1.shape[0], size=(nb,)) - idx2 = r.randint(X2.shape[0], size=(nb,)) - - Xs = X1[idx1, :] - Xt = X2[idx2, :] - - - - - - - - - -Plot original image -------------------- - - -.. code-block:: default - - - pl.figure(1, figsize=(6.4, 3)) - - pl.subplot(1, 2, 1) - pl.imshow(I1) - pl.axis('off') - pl.title('Image 1') - - pl.subplot(1, 2, 2) - pl.imshow(I2) - pl.axis('off') - pl.title('Image 2') - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - Text(0.5, 1.0, 'Image 2') - - - -Scatter plot of colors ----------------------- - - -.. code-block:: default - - - pl.figure(2, figsize=(6.4, 3)) - - pl.subplot(1, 2, 1) - pl.scatter(Xs[:, 0], Xs[:, 2], c=Xs) - pl.axis([0, 1, 0, 1]) - pl.xlabel('Red') - pl.ylabel('Blue') - pl.title('Image 1') - - pl.subplot(1, 2, 2) - pl.scatter(Xt[:, 0], Xt[:, 2], c=Xt) - pl.axis([0, 1, 0, 1]) - pl.xlabel('Red') - pl.ylabel('Blue') - pl.title('Image 2') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_002.png - :class: sphx-glr-single-img - - - - - -Instantiate the different transport algorithms and fit them ------------------------------------------------------------ - - -.. code-block:: default - - - # EMDTransport - ot_emd = ot.da.EMDTransport() - ot_emd.fit(Xs=Xs, Xt=Xt) - - # SinkhornTransport - ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) - ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - - # prediction between images (using out of sample prediction as in [6]) - transp_Xs_emd = ot_emd.transform(Xs=X1) - transp_Xt_emd = ot_emd.inverse_transform(Xt=X2) - - transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) - transp_Xt_sinkhorn = ot_sinkhorn.inverse_transform(Xt=X2) - - I1t = minmax(mat2im(transp_Xs_emd, I1.shape)) - I2t = minmax(mat2im(transp_Xt_emd, I2.shape)) - - I1te = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) - I2te = minmax(mat2im(transp_Xt_sinkhorn, I2.shape)) - - - - - - - - - -Plot new images ---------------- - - -.. code-block:: default - - - pl.figure(3, figsize=(8, 4)) - - pl.subplot(2, 3, 1) - pl.imshow(I1) - pl.axis('off') - pl.title('Image 1') - - pl.subplot(2, 3, 2) - pl.imshow(I1t) - pl.axis('off') - pl.title('Image 1 Adapt') - - pl.subplot(2, 3, 3) - pl.imshow(I1te) - pl.axis('off') - pl.title('Image 1 Adapt (reg)') - - pl.subplot(2, 3, 4) - pl.imshow(I2) - pl.axis('off') - pl.title('Image 2') - - pl.subplot(2, 3, 5) - pl.imshow(I2t) - pl.axis('off') - pl.title('Image 2 Adapt') - - pl.subplot(2, 3, 6) - pl.imshow(I2te) - pl.axis('off') - pl.title('Image 2 Adapt (reg)') - pl.tight_layout() - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_color_images.py:164: 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:** ( 2 minutes 28.821 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_color_images.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_color_images.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_color_images.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_d2.ipynb b/docs/source/auto_examples/plot_otda_d2.ipynb deleted file mode 100644 index a2a7839..0000000 --- a/docs/source/auto_examples/plot_otda_d2.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# OT for domain adaptation on empirical distributions\n\n\nThis example introduces a domain adaptation in a 2D setting. It explicits\nthe problem of domain adaptation and introduces some optimal transport\napproaches to solve it.\n\nQuantities such as optimal couplings, greater coupling coefficients and\ntransported samples are represented in order to give a visual understanding\nof what the transport methods are doing.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_samples_source = 150\nn_samples_target = 150\n\nXs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source)\nXt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target)\n\n# Cost matrix\nM = ot.dist(Xs, Xt, metric='sqeuclidean')" - ] - }, - { - "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=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\n\n# Sinkhorn Transport with Group lasso regularization\not_lpl1 = ot.da.SinkhornLpl1Transport(reg_e=1e-1, reg_cl=1e0)\not_lpl1.fit(Xs=Xs, ys=ys, 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_lpl1 = ot_lpl1.transform(Xs=Xs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Fig 1 : plots source and target samples + matrix of pairwise distance\n---------------------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(10, 10))\npl.subplot(2, 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(2, 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')\n\npl.subplot(2, 2, 3)\npl.imshow(M, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Matrix of pairwise distances')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Fig 2 : plots optimal couplings for the different methods\n---------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(10, 6))\n\npl.subplot(2, 3, 1)\npl.imshow(ot_emd.coupling_, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nEMDTransport')\n\npl.subplot(2, 3, 2)\npl.imshow(ot_sinkhorn.coupling_, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSinkhornTransport')\n\npl.subplot(2, 3, 3)\npl.imshow(ot_lpl1.coupling_, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSinkhornLpl1Transport')\n\npl.subplot(2, 3, 4)\not.plot.plot2D_samples_mat(Xs, Xt, ot_emd.coupling_, c=[.5, .5, 1])\npl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')\npl.xticks([])\npl.yticks([])\npl.title('Main coupling coefficients\\nEMDTransport')\n\npl.subplot(2, 3, 5)\not.plot.plot2D_samples_mat(Xs, Xt, ot_sinkhorn.coupling_, c=[.5, .5, 1])\npl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')\npl.xticks([])\npl.yticks([])\npl.title('Main coupling coefficients\\nSinkhornTransport')\n\npl.subplot(2, 3, 6)\not.plot.plot2D_samples_mat(Xs, Xt, ot_lpl1.coupling_, c=[.5, .5, 1])\npl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')\npl.xticks([])\npl.yticks([])\npl.title('Main coupling coefficients\\nSinkhornLpl1Transport')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Fig 3 : plot transported samples\n--------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# display transported samples\npl.figure(4, figsize=(10, 4))\npl.subplot(1, 3, 1)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.5)\npl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.title('Transported samples\\nEmdTransport')\npl.legend(loc=0)\npl.xticks([])\npl.yticks([])\n\npl.subplot(1, 3, 2)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.5)\npl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.title('Transported samples\\nSinkhornTransport')\npl.xticks([])\npl.yticks([])\n\npl.subplot(1, 3, 3)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.5)\npl.scatter(transp_Xs_lpl1[:, 0], transp_Xs_lpl1[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.title('Transported samples\\nSinkhornLpl1Transport')\npl.xticks([])\npl.yticks([])\n\npl.tight_layout()\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_d2.py b/docs/source/auto_examples/plot_otda_d2.py deleted file mode 100644 index cf22c2f..0000000 --- a/docs/source/auto_examples/plot_otda_d2.py +++ /dev/null @@ -1,172 +0,0 @@ -# -*- coding: utf-8 -*- -""" -=================================================== -OT for domain adaptation on empirical distributions -=================================================== - -This example introduces a domain adaptation in a 2D setting. It explicits -the problem of domain adaptation and introduces some optimal transport -approaches to solve it. - -Quantities such as optimal couplings, greater coupling coefficients and -transported samples are represented in order to give a visual understanding -of what the transport methods are doing. -""" - -# Authors: Remi Flamary -# Stanislas Chambon -# -# License: MIT License - -import matplotlib.pylab as pl -import ot -import ot.plot - -############################################################################## -# generate data -# ------------- - -n_samples_source = 150 -n_samples_target = 150 - -Xs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source) -Xt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target) - -# Cost matrix -M = ot.dist(Xs, Xt, metric='sqeuclidean') - - -############################################################################## -# 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=1e-1) -ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - -# Sinkhorn Transport with Group lasso regularization -ot_lpl1 = ot.da.SinkhornLpl1Transport(reg_e=1e-1, reg_cl=1e0) -ot_lpl1.fit(Xs=Xs, ys=ys, 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_lpl1 = ot_lpl1.transform(Xs=Xs) - - -############################################################################## -# Fig 1 : plots source and target samples + matrix of pairwise distance -# --------------------------------------------------------------------- - -pl.figure(1, figsize=(10, 10)) -pl.subplot(2, 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(2, 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.subplot(2, 2, 3) -pl.imshow(M, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Matrix of pairwise distances') -pl.tight_layout() - - -############################################################################## -# Fig 2 : plots optimal couplings for the different methods -# --------------------------------------------------------- -pl.figure(2, figsize=(10, 6)) - -pl.subplot(2, 3, 1) -pl.imshow(ot_emd.coupling_, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nEMDTransport') - -pl.subplot(2, 3, 2) -pl.imshow(ot_sinkhorn.coupling_, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nSinkhornTransport') - -pl.subplot(2, 3, 3) -pl.imshow(ot_lpl1.coupling_, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nSinkhornLpl1Transport') - -pl.subplot(2, 3, 4) -ot.plot.plot2D_samples_mat(Xs, Xt, ot_emd.coupling_, c=[.5, .5, 1]) -pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') -pl.xticks([]) -pl.yticks([]) -pl.title('Main coupling coefficients\nEMDTransport') - -pl.subplot(2, 3, 5) -ot.plot.plot2D_samples_mat(Xs, Xt, ot_sinkhorn.coupling_, c=[.5, .5, 1]) -pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') -pl.xticks([]) -pl.yticks([]) -pl.title('Main coupling coefficients\nSinkhornTransport') - -pl.subplot(2, 3, 6) -ot.plot.plot2D_samples_mat(Xs, Xt, ot_lpl1.coupling_, c=[.5, .5, 1]) -pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') -pl.xticks([]) -pl.yticks([]) -pl.title('Main coupling coefficients\nSinkhornLpl1Transport') -pl.tight_layout() - - -############################################################################## -# Fig 3 : plot transported samples -# -------------------------------- - -# display transported samples -pl.figure(4, figsize=(10, 4)) -pl.subplot(1, 3, 1) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) -pl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys, - marker='+', label='Transp samples', s=30) -pl.title('Transported samples\nEmdTransport') -pl.legend(loc=0) -pl.xticks([]) -pl.yticks([]) - -pl.subplot(1, 3, 2) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) -pl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys, - marker='+', label='Transp samples', s=30) -pl.title('Transported samples\nSinkhornTransport') -pl.xticks([]) -pl.yticks([]) - -pl.subplot(1, 3, 3) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) -pl.scatter(transp_Xs_lpl1[:, 0], transp_Xs_lpl1[:, 1], c=ys, - marker='+', label='Transp samples', s=30) -pl.title('Transported samples\nSinkhornLpl1Transport') -pl.xticks([]) -pl.yticks([]) - -pl.tight_layout() -pl.show() diff --git a/docs/source/auto_examples/plot_otda_d2.rst b/docs/source/auto_examples/plot_otda_d2.rst deleted file mode 100644 index 6d8e429..0000000 --- a/docs/source/auto_examples/plot_otda_d2.rst +++ /dev/null @@ -1,291 +0,0 @@ -.. 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_otda_d2.py: - - -=================================================== -OT for domain adaptation on empirical distributions -=================================================== - -This example introduces a domain adaptation in a 2D setting. It explicits -the problem of domain adaptation and introduces some optimal transport -approaches to solve it. - -Quantities such as optimal couplings, greater coupling coefficients and -transported samples are represented in order to give a visual understanding -of what the transport methods are doing. - - -.. code-block:: default - - - # Authors: Remi Flamary - # Stanislas Chambon - # - # License: MIT License - - import matplotlib.pylab as pl - import ot - import ot.plot - - - - - - - - -generate data -------------- - - -.. code-block:: default - - - n_samples_source = 150 - n_samples_target = 150 - - Xs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source) - Xt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target) - - # Cost matrix - M = ot.dist(Xs, Xt, metric='sqeuclidean') - - - - - - - - - -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=1e-1) - ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - - # Sinkhorn Transport with Group lasso regularization - ot_lpl1 = ot.da.SinkhornLpl1Transport(reg_e=1e-1, reg_cl=1e0) - ot_lpl1.fit(Xs=Xs, ys=ys, 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_lpl1 = ot_lpl1.transform(Xs=Xs) - - - - - - - - - -Fig 1 : plots source and target samples + matrix of pairwise distance ---------------------------------------------------------------------- - - -.. code-block:: default - - - pl.figure(1, figsize=(10, 10)) - pl.subplot(2, 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(2, 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.subplot(2, 2, 3) - pl.imshow(M, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Matrix of pairwise distances') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_d2_001.png - :class: sphx-glr-single-img - - - - - -Fig 2 : plots optimal couplings for the different methods ---------------------------------------------------------- - - -.. code-block:: default - - pl.figure(2, figsize=(10, 6)) - - pl.subplot(2, 3, 1) - pl.imshow(ot_emd.coupling_, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nEMDTransport') - - pl.subplot(2, 3, 2) - pl.imshow(ot_sinkhorn.coupling_, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nSinkhornTransport') - - pl.subplot(2, 3, 3) - pl.imshow(ot_lpl1.coupling_, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nSinkhornLpl1Transport') - - pl.subplot(2, 3, 4) - ot.plot.plot2D_samples_mat(Xs, Xt, ot_emd.coupling_, c=[.5, .5, 1]) - pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') - pl.xticks([]) - pl.yticks([]) - pl.title('Main coupling coefficients\nEMDTransport') - - pl.subplot(2, 3, 5) - ot.plot.plot2D_samples_mat(Xs, Xt, ot_sinkhorn.coupling_, c=[.5, .5, 1]) - pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') - pl.xticks([]) - pl.yticks([]) - pl.title('Main coupling coefficients\nSinkhornTransport') - - pl.subplot(2, 3, 6) - ot.plot.plot2D_samples_mat(Xs, Xt, ot_lpl1.coupling_, c=[.5, .5, 1]) - pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') - pl.xticks([]) - pl.yticks([]) - pl.title('Main coupling coefficients\nSinkhornLpl1Transport') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_d2_002.png - :class: sphx-glr-single-img - - - - - -Fig 3 : plot transported samples --------------------------------- - - -.. code-block:: default - - - # display transported samples - pl.figure(4, figsize=(10, 4)) - pl.subplot(1, 3, 1) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) - pl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys, - marker='+', label='Transp samples', s=30) - pl.title('Transported samples\nEmdTransport') - pl.legend(loc=0) - pl.xticks([]) - pl.yticks([]) - - pl.subplot(1, 3, 2) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) - pl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys, - marker='+', label='Transp samples', s=30) - pl.title('Transported samples\nSinkhornTransport') - pl.xticks([]) - pl.yticks([]) - - pl.subplot(1, 3, 3) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) - pl.scatter(transp_Xs_lpl1[:, 0], transp_Xs_lpl1[:, 1], c=ys, - marker='+', label='Transp samples', s=30) - pl.title('Transported samples\nSinkhornLpl1Transport') - pl.xticks([]) - pl.yticks([]) - - pl.tight_layout() - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_d2_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_d2.py:172: 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 21.323 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_d2.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_d2.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_d2.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_jcpot.ipynb b/docs/source/auto_examples/plot_otda_jcpot.ipynb deleted file mode 100644 index a81d47a..0000000 --- a/docs/source/auto_examples/plot_otda_jcpot.ipynb +++ /dev/null @@ -1,173 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# OT for multi-source target shift\n\n\nThis example introduces a target shift problem with two 2D source and 1 target domain.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Authors: Remi Flamary \n# Ievgen Redko \n#\n# License: MIT License\n\nimport pylab as pl\nimport numpy as np\nimport ot\nfrom ot.datasets import make_data_classif" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 50\nsigma = 0.3\nnp.random.seed(1985)\n\np1 = .2\ndec1 = [0, 2]\n\np2 = .9\ndec2 = [0, -2]\n\npt = .4\ndect = [4, 0]\n\nxs1, ys1 = make_data_classif('2gauss_prop', n, nz=sigma, p=p1, bias=dec1)\nxs2, ys2 = make_data_classif('2gauss_prop', n + 1, nz=sigma, p=p2, bias=dec2)\nxt, yt = make_data_classif('2gauss_prop', n, nz=sigma, p=pt, bias=dect)\n\nall_Xr = [xs1, xs2]\nall_Yr = [ys1, ys2]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "da = 1.5\n\n\ndef plot_ax(dec, name):\n pl.plot([dec[0], dec[0]], [dec[1] - da, dec[1] + da], 'k', alpha=0.5)\n pl.plot([dec[0] - da, dec[0] + da], [dec[1], dec[1]], 'k', alpha=0.5)\n pl.text(dec[0] - .5, dec[1] + 2, name)" - ] - }, - { - "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)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9,\n label='Source 1 ({:1.2f}, {:1.2f})'.format(1 - p1, p1))\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9,\n label='Source 2 ({:1.2f}, {:1.2f})'.format(1 - p2, p2))\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9,\n label='Target ({:1.2f}, {:1.2f})'.format(1 - pt, pt))\npl.title('Data')\n\npl.legend()\npl.axis('equal')\npl.axis('off')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Instantiate Sinkhorn transport algorithm and fit them for all source domains\n----------------------------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1, metric='sqeuclidean')\n\n\ndef print_G(G, xs, ys, xt):\n for i in range(G.shape[0]):\n for j in range(G.shape[1]):\n if G[i, j] > 5e-4:\n if ys[i]:\n c = 'b'\n else:\n c = 'r'\n pl.plot([xs[i, 0], xt[j, 0]], [xs[i, 1], xt[j, 1]], c, alpha=.2)" - ] - }, - { - "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": [ - "pl.figure(2)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\nprint_G(ot_sinkhorn.fit(Xs=xs1, Xt=xt).coupling_, xs1, ys1, xt)\nprint_G(ot_sinkhorn.fit(Xs=xs2, Xt=xt).coupling_, xs2, ys2, xt)\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9)\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9)\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9)\n\npl.plot([], [], 'r', alpha=.2, label='Mass from Class 1')\npl.plot([], [], 'b', alpha=.2, label='Mass from Class 2')\n\npl.title('Independent OT')\n\npl.legend()\npl.axis('equal')\npl.axis('off')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Instantiate JCPOT adaptation algorithm and fit it\n----------------------------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "otda = ot.da.JCPOTTransport(reg_e=1, max_iter=1000, metric='sqeuclidean', tol=1e-9, verbose=True, log=True)\notda.fit(all_Xr, all_Yr, xt)\n\nws1 = otda.proportions_.dot(otda.log_['D2'][0])\nws2 = otda.proportions_.dot(otda.log_['D2'][1])\n\npl.figure(3)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\nprint_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt)\nprint_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt)\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9)\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9)\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9)\n\npl.plot([], [], 'r', alpha=.2, label='Mass from Class 1')\npl.plot([], [], 'b', alpha=.2, label='Mass from Class 2')\n\npl.title('OT with prop estimation ({:1.3f},{:1.3f})'.format(otda.proportions_[0], otda.proportions_[1]))\n\npl.legend()\npl.axis('equal')\npl.axis('off')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Run oracle transport algorithm with known proportions\n----------------------------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "h_res = np.array([1 - pt, pt])\n\nws1 = h_res.dot(otda.log_['D2'][0])\nws2 = h_res.dot(otda.log_['D2'][1])\n\npl.figure(4)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\nprint_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt)\nprint_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt)\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9)\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9)\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9)\n\npl.plot([], [], 'r', alpha=.2, label='Mass from Class 1')\npl.plot([], [], 'b', alpha=.2, label='Mass from Class 2')\n\npl.title('OT with known proportion ({:1.1f},{:1.1f})'.format(h_res[0], h_res[1]))\n\npl.legend()\npl.axis('equal')\npl.axis('off')\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_jcpot.py b/docs/source/auto_examples/plot_otda_jcpot.py deleted file mode 100644 index c495690..0000000 --- a/docs/source/auto_examples/plot_otda_jcpot.py +++ /dev/null @@ -1,171 +0,0 @@ -# -*- coding: utf-8 -*- -""" -======================== -OT for multi-source target shift -======================== - -This example introduces a target shift problem with two 2D source and 1 target domain. - -""" - -# Authors: Remi Flamary -# Ievgen Redko -# -# License: MIT License - -import pylab as pl -import numpy as np -import ot -from ot.datasets import make_data_classif - -############################################################################## -# Generate data -# ------------- -n = 50 -sigma = 0.3 -np.random.seed(1985) - -p1 = .2 -dec1 = [0, 2] - -p2 = .9 -dec2 = [0, -2] - -pt = .4 -dect = [4, 0] - -xs1, ys1 = make_data_classif('2gauss_prop', n, nz=sigma, p=p1, bias=dec1) -xs2, ys2 = make_data_classif('2gauss_prop', n + 1, nz=sigma, p=p2, bias=dec2) -xt, yt = make_data_classif('2gauss_prop', n, nz=sigma, p=pt, bias=dect) - -all_Xr = [xs1, xs2] -all_Yr = [ys1, ys2] -# %% - -da = 1.5 - - -def plot_ax(dec, name): - pl.plot([dec[0], dec[0]], [dec[1] - da, dec[1] + da], 'k', alpha=0.5) - pl.plot([dec[0] - da, dec[0] + da], [dec[1], dec[1]], 'k', alpha=0.5) - pl.text(dec[0] - .5, dec[1] + 2, name) - - -############################################################################## -# Fig 1 : plots source and target samples -# --------------------------------------- - -pl.figure(1) -pl.clf() -plot_ax(dec1, 'Source 1') -plot_ax(dec2, 'Source 2') -plot_ax(dect, 'Target') -pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9, - label='Source 1 ({:1.2f}, {:1.2f})'.format(1 - p1, p1)) -pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9, - label='Source 2 ({:1.2f}, {:1.2f})'.format(1 - p2, p2)) -pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9, - label='Target ({:1.2f}, {:1.2f})'.format(1 - pt, pt)) -pl.title('Data') - -pl.legend() -pl.axis('equal') -pl.axis('off') - -############################################################################## -# Instantiate Sinkhorn transport algorithm and fit them for all source domains -# ---------------------------------------------------------------------------- -ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1, metric='sqeuclidean') - - -def print_G(G, xs, ys, xt): - for i in range(G.shape[0]): - for j in range(G.shape[1]): - if G[i, j] > 5e-4: - if ys[i]: - c = 'b' - else: - c = 'r' - pl.plot([xs[i, 0], xt[j, 0]], [xs[i, 1], xt[j, 1]], c, alpha=.2) - - -############################################################################## -# Fig 2 : plot optimal couplings and transported samples -# ------------------------------------------------------ -pl.figure(2) -pl.clf() -plot_ax(dec1, 'Source 1') -plot_ax(dec2, 'Source 2') -plot_ax(dect, 'Target') -print_G(ot_sinkhorn.fit(Xs=xs1, Xt=xt).coupling_, xs1, ys1, xt) -print_G(ot_sinkhorn.fit(Xs=xs2, Xt=xt).coupling_, xs2, ys2, xt) -pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) -pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) -pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) - -pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') -pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') - -pl.title('Independent OT') - -pl.legend() -pl.axis('equal') -pl.axis('off') - -############################################################################## -# Instantiate JCPOT adaptation algorithm and fit it -# ---------------------------------------------------------------------------- -otda = ot.da.JCPOTTransport(reg_e=1, max_iter=1000, metric='sqeuclidean', tol=1e-9, verbose=True, log=True) -otda.fit(all_Xr, all_Yr, xt) - -ws1 = otda.proportions_.dot(otda.log_['D2'][0]) -ws2 = otda.proportions_.dot(otda.log_['D2'][1]) - -pl.figure(3) -pl.clf() -plot_ax(dec1, 'Source 1') -plot_ax(dec2, 'Source 2') -plot_ax(dect, 'Target') -print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) -print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) -pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) -pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) -pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) - -pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') -pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') - -pl.title('OT with prop estimation ({:1.3f},{:1.3f})'.format(otda.proportions_[0], otda.proportions_[1])) - -pl.legend() -pl.axis('equal') -pl.axis('off') - -############################################################################## -# Run oracle transport algorithm with known proportions -# ---------------------------------------------------------------------------- -h_res = np.array([1 - pt, pt]) - -ws1 = h_res.dot(otda.log_['D2'][0]) -ws2 = h_res.dot(otda.log_['D2'][1]) - -pl.figure(4) -pl.clf() -plot_ax(dec1, 'Source 1') -plot_ax(dec2, 'Source 2') -plot_ax(dect, 'Target') -print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) -print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) -pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) -pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) -pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) - -pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') -pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') - -pl.title('OT with known proportion ({:1.1f},{:1.1f})'.format(h_res[0], h_res[1])) - -pl.legend() -pl.axis('equal') -pl.axis('off') -pl.show() diff --git a/docs/source/auto_examples/plot_otda_jcpot.rst b/docs/source/auto_examples/plot_otda_jcpot.rst deleted file mode 100644 index 3433190..0000000 --- a/docs/source/auto_examples/plot_otda_jcpot.rst +++ /dev/null @@ -1,336 +0,0 @@ -.. 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_otda_jcpot.py: - - -======================== -OT for multi-source target shift -======================== - -This example introduces a target shift problem with two 2D source and 1 target domain. - - - -.. code-block:: default - - - # Authors: Remi Flamary - # Ievgen Redko - # - # License: MIT License - - import pylab as pl - import numpy as np - import ot - from ot.datasets import make_data_classif - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - n = 50 - sigma = 0.3 - np.random.seed(1985) - - p1 = .2 - dec1 = [0, 2] - - p2 = .9 - dec2 = [0, -2] - - pt = .4 - dect = [4, 0] - - xs1, ys1 = make_data_classif('2gauss_prop', n, nz=sigma, p=p1, bias=dec1) - xs2, ys2 = make_data_classif('2gauss_prop', n + 1, nz=sigma, p=p2, bias=dec2) - xt, yt = make_data_classif('2gauss_prop', n, nz=sigma, p=pt, bias=dect) - - all_Xr = [xs1, xs2] - all_Yr = [ys1, ys2] - - - - - - - - -.. code-block:: default - - - da = 1.5 - - - def plot_ax(dec, name): - pl.plot([dec[0], dec[0]], [dec[1] - da, dec[1] + da], 'k', alpha=0.5) - pl.plot([dec[0] - da, dec[0] + da], [dec[1], dec[1]], 'k', alpha=0.5) - pl.text(dec[0] - .5, dec[1] + 2, name) - - - - - - - - - -Fig 1 : plots source and target samples ---------------------------------------- - - -.. code-block:: default - - - pl.figure(1) - pl.clf() - plot_ax(dec1, 'Source 1') - plot_ax(dec2, 'Source 2') - plot_ax(dect, 'Target') - pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9, - label='Source 1 ({:1.2f}, {:1.2f})'.format(1 - p1, p1)) - pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9, - label='Source 2 ({:1.2f}, {:1.2f})'.format(1 - p2, p2)) - pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9, - label='Target ({:1.2f}, {:1.2f})'.format(1 - pt, pt)) - pl.title('Data') - - pl.legend() - pl.axis('equal') - pl.axis('off') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - (-1.85, 5.85, -4.1171725099266725, 4.197384527473105) - - - -Instantiate Sinkhorn transport algorithm and fit them for all source domains ----------------------------------------------------------------------------- - - -.. code-block:: default - - ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1, metric='sqeuclidean') - - - def print_G(G, xs, ys, xt): - for i in range(G.shape[0]): - for j in range(G.shape[1]): - if G[i, j] > 5e-4: - if ys[i]: - c = 'b' - else: - c = 'r' - pl.plot([xs[i, 0], xt[j, 0]], [xs[i, 1], xt[j, 1]], c, alpha=.2) - - - - - - - - - -Fig 2 : plot optimal couplings and transported samples ------------------------------------------------------- - - -.. code-block:: default - - pl.figure(2) - pl.clf() - plot_ax(dec1, 'Source 1') - plot_ax(dec2, 'Source 2') - plot_ax(dect, 'Target') - print_G(ot_sinkhorn.fit(Xs=xs1, Xt=xt).coupling_, xs1, ys1, xt) - print_G(ot_sinkhorn.fit(Xs=xs2, Xt=xt).coupling_, xs2, ys2, xt) - pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) - pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) - pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) - - pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') - pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') - - pl.title('Independent OT') - - pl.legend() - pl.axis('equal') - pl.axis('off') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - (-1.85, 5.85, -4.11901398007908, 4.201462272227509) - - - -Instantiate JCPOT adaptation algorithm and fit it ----------------------------------------------------------------------------- - - -.. code-block:: default - - otda = ot.da.JCPOTTransport(reg_e=1, max_iter=1000, metric='sqeuclidean', tol=1e-9, verbose=True, log=True) - otda.fit(all_Xr, all_Yr, xt) - - ws1 = otda.proportions_.dot(otda.log_['D2'][0]) - ws2 = otda.proportions_.dot(otda.log_['D2'][1]) - - pl.figure(3) - pl.clf() - plot_ax(dec1, 'Source 1') - plot_ax(dec2, 'Source 2') - plot_ax(dect, 'Target') - print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) - print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) - pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) - pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) - pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) - - pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') - pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') - - pl.title('OT with prop estimation ({:1.3f},{:1.3f})'.format(otda.proportions_[0], otda.proportions_[1])) - - pl.legend() - pl.axis('equal') - pl.axis('off') - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - (-1.85, 5.85, -4.11901398007908, 4.201462272227509) - - - -Run oracle transport algorithm with known proportions ----------------------------------------------------------------------------- - - -.. code-block:: default - - h_res = np.array([1 - pt, pt]) - - ws1 = h_res.dot(otda.log_['D2'][0]) - ws2 = h_res.dot(otda.log_['D2'][1]) - - pl.figure(4) - pl.clf() - plot_ax(dec1, 'Source 1') - plot_ax(dec2, 'Source 2') - plot_ax(dect, 'Target') - print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) - print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) - pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) - pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) - pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) - - pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') - pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') - - pl.title('OT with known proportion ({:1.1f},{:1.1f})'.format(h_res[0], h_res[1])) - - pl.legend() - pl.axis('equal') - pl.axis('off') - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_004.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_jcpot.py:171: 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 4.725 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_jcpot.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_jcpot.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_jcpot.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_laplacian.ipynb b/docs/source/auto_examples/plot_otda_laplacian.ipynb deleted file mode 100644 index c1e9efe..0000000 --- a/docs/source/auto_examples/plot_otda_laplacian.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "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 \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 deleted file mode 100644 index 67c8f67..0000000 --- a/docs/source/auto_examples/plot_otda_laplacian.py +++ /dev/null @@ -1,127 +0,0 @@ -# -*- 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 - -# 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 deleted file mode 100644 index 12cd7b9..0000000 --- a/docs/source/auto_examples/plot_otda_laplacian.rst +++ /dev/null @@ -1,233 +0,0 @@ -.. 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_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 - - # 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 ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_laplacian.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_linear_mapping.ipynb b/docs/source/auto_examples/plot_otda_linear_mapping.ipynb deleted file mode 100644 index 96eccbe..0000000 --- a/docs/source/auto_examples/plot_otda_linear_mapping.ipynb +++ /dev/null @@ -1,180 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Linear OT mapping estimation\n\n\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Remi Flamary \n#\n# License: MIT License\n\nimport numpy as np\nimport 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 = 1000\nd = 2\nsigma = .1\n\n# source samples\nangles = np.random.rand(n, 1) * 2 * np.pi\nxs = np.concatenate((np.sin(angles), np.cos(angles)),\n axis=1) + sigma * np.random.randn(n, 2)\nxs[:n // 2, 1] += 2\n\n\n# target samples\nanglet = np.random.rand(n, 1) * 2 * np.pi\nxt = np.concatenate((np.sin(anglet), np.cos(anglet)),\n axis=1) + sigma * np.random.randn(n, 2)\nxt[:n // 2, 1] += 2\n\n\nA = np.array([[1.5, .7], [.7, 1.5]])\nb = np.array([[4, 2]])\nxt = xt.dot(A) + b" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, (5, 5))\npl.plot(xs[:, 0], xs[:, 1], '+')\npl.plot(xt[:, 0], xt[:, 1], 'o')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Estimate linear mapping and transport\n-------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "Ae, be = ot.da.OT_mapping_linear(xs, xt)\n\nxst = xs.dot(Ae) + be" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot transported samples\n------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, (5, 5))\npl.clf()\npl.plot(xs[:, 0], xs[:, 1], '+')\npl.plot(xt[:, 0], xt[:, 1], 'o')\npl.plot(xst[:, 0], xst[:, 1], '+')\n\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Load image data\n---------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)\n\n\n# Loading images\nI1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Estimate mapping and adapt\n----------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "mapping = ot.da.LinearTransport()\n\nmapping.fit(Xs=X1, Xt=X2)\n\n\nxst = mapping.transform(Xs=X1)\nxts = mapping.inverse_transform(Xt=X2)\n\nI1t = minmax(mat2im(xst, I1.shape))\nI2t = minmax(mat2im(xts, I2.shape))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot transformed images\n-----------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(10, 7))\n\npl.subplot(2, 2, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Im. 1')\n\npl.subplot(2, 2, 2)\npl.imshow(I2)\npl.axis('off')\npl.title('Im. 2')\n\npl.subplot(2, 2, 3)\npl.imshow(I1t)\npl.axis('off')\npl.title('Mapping Im. 1')\n\npl.subplot(2, 2, 4)\npl.imshow(I2t)\npl.axis('off')\npl.title('Inverse mapping Im. 2')" - ] - } - ], - "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_linear_mapping.py b/docs/source/auto_examples/plot_otda_linear_mapping.py deleted file mode 100644 index c65bd4f..0000000 --- a/docs/source/auto_examples/plot_otda_linear_mapping.py +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -============================ -Linear OT mapping estimation -============================ - - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import pylab as pl -import ot - -############################################################################## -# Generate data -# ------------- - -n = 1000 -d = 2 -sigma = .1 - -# source samples -angles = np.random.rand(n, 1) * 2 * np.pi -xs = np.concatenate((np.sin(angles), np.cos(angles)), - axis=1) + sigma * np.random.randn(n, 2) -xs[:n // 2, 1] += 2 - - -# target samples -anglet = np.random.rand(n, 1) * 2 * np.pi -xt = np.concatenate((np.sin(anglet), np.cos(anglet)), - axis=1) + sigma * np.random.randn(n, 2) -xt[:n // 2, 1] += 2 - - -A = np.array([[1.5, .7], [.7, 1.5]]) -b = np.array([[4, 2]]) -xt = xt.dot(A) + b - -############################################################################## -# Plot data -# --------- - -pl.figure(1, (5, 5)) -pl.plot(xs[:, 0], xs[:, 1], '+') -pl.plot(xt[:, 0], xt[:, 1], 'o') - - -############################################################################## -# Estimate linear mapping and transport -# ------------------------------------- - -Ae, be = ot.da.OT_mapping_linear(xs, xt) - -xst = xs.dot(Ae) + be - - -############################################################################## -# Plot transported samples -# ------------------------ - -pl.figure(1, (5, 5)) -pl.clf() -pl.plot(xs[:, 0], xs[:, 1], '+') -pl.plot(xt[:, 0], xt[:, 1], 'o') -pl.plot(xst[:, 0], xst[:, 1], '+') - -pl.show() - -############################################################################## -# Load image data -# --------------- - - -def im2mat(I): - """Converts and image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - -def mat2im(X, shape): - """Converts back a matrix to an image""" - return X.reshape(shape) - - -def minmax(I): - return np.clip(I, 0, 1) - - -# Loading images -I1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256 -I2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 - - -X1 = im2mat(I1) -X2 = im2mat(I2) - -############################################################################## -# Estimate mapping and adapt -# ---------------------------- - -mapping = ot.da.LinearTransport() - -mapping.fit(Xs=X1, Xt=X2) - - -xst = mapping.transform(Xs=X1) -xts = mapping.inverse_transform(Xt=X2) - -I1t = minmax(mat2im(xst, I1.shape)) -I2t = minmax(mat2im(xts, I2.shape)) - -# %% - - -############################################################################## -# Plot transformed images -# ----------------------- - -pl.figure(2, figsize=(10, 7)) - -pl.subplot(2, 2, 1) -pl.imshow(I1) -pl.axis('off') -pl.title('Im. 1') - -pl.subplot(2, 2, 2) -pl.imshow(I2) -pl.axis('off') -pl.title('Im. 2') - -pl.subplot(2, 2, 3) -pl.imshow(I1t) -pl.axis('off') -pl.title('Mapping Im. 1') - -pl.subplot(2, 2, 4) -pl.imshow(I2t) -pl.axis('off') -pl.title('Inverse mapping Im. 2') diff --git a/docs/source/auto_examples/plot_otda_linear_mapping.rst b/docs/source/auto_examples/plot_otda_linear_mapping.rst deleted file mode 100644 index 63848d2..0000000 --- a/docs/source/auto_examples/plot_otda_linear_mapping.rst +++ /dev/null @@ -1,295 +0,0 @@ -.. 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_otda_linear_mapping.py: - - -============================ -Linear OT mapping estimation -============================ - - - - -.. code-block:: default - - - # Author: Remi Flamary - # - # License: MIT License - - import numpy as np - import pylab as pl - import ot - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - n = 1000 - d = 2 - sigma = .1 - - # source samples - angles = np.random.rand(n, 1) * 2 * np.pi - xs = np.concatenate((np.sin(angles), np.cos(angles)), - axis=1) + sigma * np.random.randn(n, 2) - xs[:n // 2, 1] += 2 - - - # target samples - anglet = np.random.rand(n, 1) * 2 * np.pi - xt = np.concatenate((np.sin(anglet), np.cos(anglet)), - axis=1) + sigma * np.random.randn(n, 2) - xt[:n // 2, 1] += 2 - - - A = np.array([[1.5, .7], [.7, 1.5]]) - b = np.array([[4, 2]]) - xt = xt.dot(A) + b - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - pl.figure(1, (5, 5)) - pl.plot(xs[:, 0], xs[:, 1], '+') - pl.plot(xt[:, 0], xt[:, 1], 'o') - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - [] - - - -Estimate linear mapping and transport -------------------------------------- - - -.. code-block:: default - - - Ae, be = ot.da.OT_mapping_linear(xs, xt) - - xst = xs.dot(Ae) + be - - - - - - - - - -Plot transported samples ------------------------- - - -.. code-block:: default - - - pl.figure(1, (5, 5)) - pl.clf() - pl.plot(xs[:, 0], xs[:, 1], '+') - pl.plot(xt[:, 0], xt[:, 1], 'o') - pl.plot(xst[:, 0], xst[:, 1], '+') - - pl.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_linear_mapping.py:73: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Load image data ---------------- - - -.. code-block:: default - - - - def im2mat(I): - """Converts and image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - - def mat2im(X, shape): - """Converts back a matrix to an image""" - return X.reshape(shape) - - - def minmax(I): - return np.clip(I, 0, 1) - - - # Loading images - I1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256 - I2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 - - - X1 = im2mat(I1) - X2 = im2mat(I2) - - - - - - - - -Estimate mapping and adapt ----------------------------- - - -.. code-block:: default - - - mapping = ot.da.LinearTransport() - - mapping.fit(Xs=X1, Xt=X2) - - - xst = mapping.transform(Xs=X1) - xts = mapping.inverse_transform(Xt=X2) - - I1t = minmax(mat2im(xst, I1.shape)) - I2t = minmax(mat2im(xts, I2.shape)) - - - - - - - - -Plot transformed images ------------------------ - - -.. code-block:: default - - - pl.figure(2, figsize=(10, 7)) - - pl.subplot(2, 2, 1) - pl.imshow(I1) - pl.axis('off') - pl.title('Im. 1') - - pl.subplot(2, 2, 2) - pl.imshow(I2) - pl.axis('off') - pl.title('Im. 2') - - pl.subplot(2, 2, 3) - pl.imshow(I1t) - pl.axis('off') - pl.title('Mapping Im. 1') - - pl.subplot(2, 2, 4) - pl.imshow(I2t) - pl.axis('off') - pl.title('Inverse mapping Im. 2') - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - Text(0.5, 1.0, 'Inverse mapping Im. 2') - - - - -.. rst-class:: sphx-glr-timing - - **Total running time of the script:** ( 0 minutes 0.787 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_linear_mapping.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_linear_mapping.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_linear_mapping.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_mapping.ipynb b/docs/source/auto_examples/plot_otda_mapping.ipynb deleted file mode 100644 index ac02255..0000000 --- a/docs/source/auto_examples/plot_otda_mapping.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# OT mapping estimation for domain adaptation\n\n\nThis example presents how to use MappingTransport to estimate at the same\ntime both the coupling transport and approximate the transport map with either\na linear or a kernelized mapping as introduced in [8].\n\n[8] M. Perrot, N. Courty, R. Flamary, A. Habrard,\n \"Mapping estimation for discrete optimal transport\",\n Neural Information Processing Systems (NIPS), 2016.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport numpy as np\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 = 100\nn_target_samples = 100\ntheta = 2 * np.pi / 20\nnoise_level = 0.1\n\nXs, ys = ot.datasets.make_data_classif(\n 'gaussrot', n_source_samples, nz=noise_level)\nXs_new, _ = ot.datasets.make_data_classif(\n 'gaussrot', n_source_samples, nz=noise_level)\nXt, yt = ot.datasets.make_data_classif(\n 'gaussrot', n_target_samples, theta=theta, nz=noise_level)\n\n# one of the target mode changes its variance (no linear mapping)\nXt[yt == 2] *= 3\nXt = Xt + 4" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot data\n---------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, (10, 5))\npl.clf()\npl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')\npl.legend(loc=0)\npl.title('Source and target distributions')" - ] - }, - { - "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": [ - "# MappingTransport with linear kernel\not_mapping_linear = ot.da.MappingTransport(\n kernel=\"linear\", mu=1e0, eta=1e-8, bias=True,\n max_iter=20, verbose=True)\n\not_mapping_linear.fit(Xs=Xs, Xt=Xt)\n\n# for original source samples, transform applies barycentric mapping\ntransp_Xs_linear = ot_mapping_linear.transform(Xs=Xs)\n\n# for out of source samples, transform applies the linear mapping\ntransp_Xs_linear_new = ot_mapping_linear.transform(Xs=Xs_new)\n\n\n# MappingTransport with gaussian kernel\not_mapping_gaussian = ot.da.MappingTransport(\n kernel=\"gaussian\", eta=1e-5, mu=1e-1, bias=True, sigma=1,\n max_iter=10, verbose=True)\not_mapping_gaussian.fit(Xs=Xs, Xt=Xt)\n\n# for original source samples, transform applies barycentric mapping\ntransp_Xs_gaussian = ot_mapping_gaussian.transform(Xs=Xs)\n\n# for out of source samples, transform applies the gaussian mapping\ntransp_Xs_gaussian_new = ot_mapping_gaussian.transform(Xs=Xs_new)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot transported samples\n------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2)\npl.clf()\npl.subplot(2, 2, 1)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=.2)\npl.scatter(transp_Xs_linear[:, 0], transp_Xs_linear[:, 1], c=ys, marker='+',\n label='Mapped source samples')\npl.title(\"Bary. mapping (linear)\")\npl.legend(loc=0)\n\npl.subplot(2, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=.2)\npl.scatter(transp_Xs_linear_new[:, 0], transp_Xs_linear_new[:, 1],\n c=ys, marker='+', label='Learned mapping')\npl.title(\"Estim. mapping (linear)\")\n\npl.subplot(2, 2, 3)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=.2)\npl.scatter(transp_Xs_gaussian[:, 0], transp_Xs_gaussian[:, 1], c=ys,\n marker='+', label='barycentric mapping')\npl.title(\"Bary. mapping (kernel)\")\n\npl.subplot(2, 2, 4)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=.2)\npl.scatter(transp_Xs_gaussian_new[:, 0], transp_Xs_gaussian_new[:, 1], c=ys,\n marker='+', label='Learned mapping')\npl.title(\"Estim. mapping (kernel)\")\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_mapping.py b/docs/source/auto_examples/plot_otda_mapping.py deleted file mode 100644 index 5880adf..0000000 --- a/docs/source/auto_examples/plot_otda_mapping.py +++ /dev/null @@ -1,125 +0,0 @@ -# -*- coding: utf-8 -*- -""" -=========================================== -OT mapping estimation for domain adaptation -=========================================== - -This example presents how to use MappingTransport to estimate at the same -time both the coupling transport and approximate the transport map with either -a linear or a kernelized mapping as introduced in [8]. - -[8] M. Perrot, N. Courty, R. Flamary, A. Habrard, - "Mapping estimation for discrete optimal transport", - Neural Information Processing Systems (NIPS), 2016. -""" - -# Authors: Remi Flamary -# Stanislas Chambon -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot - - -############################################################################## -# Generate data -# ------------- - -n_source_samples = 100 -n_target_samples = 100 -theta = 2 * np.pi / 20 -noise_level = 0.1 - -Xs, ys = ot.datasets.make_data_classif( - 'gaussrot', n_source_samples, nz=noise_level) -Xs_new, _ = ot.datasets.make_data_classif( - 'gaussrot', n_source_samples, nz=noise_level) -Xt, yt = ot.datasets.make_data_classif( - 'gaussrot', n_target_samples, theta=theta, nz=noise_level) - -# one of the target mode changes its variance (no linear mapping) -Xt[yt == 2] *= 3 -Xt = Xt + 4 - -############################################################################## -# Plot data -# --------- - -pl.figure(1, (10, 5)) -pl.clf() -pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') -pl.legend(loc=0) -pl.title('Source and target distributions') - - -############################################################################## -# Instantiate the different transport algorithms and fit them -# ----------------------------------------------------------- - -# MappingTransport with linear kernel -ot_mapping_linear = ot.da.MappingTransport( - kernel="linear", mu=1e0, eta=1e-8, bias=True, - max_iter=20, verbose=True) - -ot_mapping_linear.fit(Xs=Xs, Xt=Xt) - -# for original source samples, transform applies barycentric mapping -transp_Xs_linear = ot_mapping_linear.transform(Xs=Xs) - -# for out of source samples, transform applies the linear mapping -transp_Xs_linear_new = ot_mapping_linear.transform(Xs=Xs_new) - - -# MappingTransport with gaussian kernel -ot_mapping_gaussian = ot.da.MappingTransport( - kernel="gaussian", eta=1e-5, mu=1e-1, bias=True, sigma=1, - max_iter=10, verbose=True) -ot_mapping_gaussian.fit(Xs=Xs, Xt=Xt) - -# for original source samples, transform applies barycentric mapping -transp_Xs_gaussian = ot_mapping_gaussian.transform(Xs=Xs) - -# for out of source samples, transform applies the gaussian mapping -transp_Xs_gaussian_new = ot_mapping_gaussian.transform(Xs=Xs_new) - - -############################################################################## -# Plot transported samples -# ------------------------ - -pl.figure(2) -pl.clf() -pl.subplot(2, 2, 1) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) -pl.scatter(transp_Xs_linear[:, 0], transp_Xs_linear[:, 1], c=ys, marker='+', - label='Mapped source samples') -pl.title("Bary. mapping (linear)") -pl.legend(loc=0) - -pl.subplot(2, 2, 2) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) -pl.scatter(transp_Xs_linear_new[:, 0], transp_Xs_linear_new[:, 1], - c=ys, marker='+', label='Learned mapping') -pl.title("Estim. mapping (linear)") - -pl.subplot(2, 2, 3) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) -pl.scatter(transp_Xs_gaussian[:, 0], transp_Xs_gaussian[:, 1], c=ys, - marker='+', label='barycentric mapping') -pl.title("Bary. mapping (kernel)") - -pl.subplot(2, 2, 4) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) -pl.scatter(transp_Xs_gaussian_new[:, 0], transp_Xs_gaussian_new[:, 1], c=ys, - marker='+', label='Learned mapping') -pl.title("Estim. mapping (kernel)") -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_otda_mapping.rst b/docs/source/auto_examples/plot_otda_mapping.rst deleted file mode 100644 index 99787f7..0000000 --- a/docs/source/auto_examples/plot_otda_mapping.rst +++ /dev/null @@ -1,268 +0,0 @@ -.. 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_otda_mapping.py: - - -=========================================== -OT mapping estimation for domain adaptation -=========================================== - -This example presents how to use MappingTransport to estimate at the same -time both the coupling transport and approximate the transport map with either -a linear or a kernelized mapping as introduced in [8]. - -[8] M. Perrot, N. Courty, R. Flamary, A. Habrard, - "Mapping estimation for discrete optimal transport", - Neural Information Processing Systems (NIPS), 2016. - - -.. code-block:: default - - - # Authors: Remi Flamary - # Stanislas Chambon - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - n_source_samples = 100 - n_target_samples = 100 - theta = 2 * np.pi / 20 - noise_level = 0.1 - - Xs, ys = ot.datasets.make_data_classif( - 'gaussrot', n_source_samples, nz=noise_level) - Xs_new, _ = ot.datasets.make_data_classif( - 'gaussrot', n_source_samples, nz=noise_level) - Xt, yt = ot.datasets.make_data_classif( - 'gaussrot', n_target_samples, theta=theta, nz=noise_level) - - # one of the target mode changes its variance (no linear mapping) - Xt[yt == 2] *= 3 - Xt = Xt + 4 - - - - - - - - -Plot data ---------- - - -.. code-block:: default - - - pl.figure(1, (10, 5)) - pl.clf() - pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') - pl.legend(loc=0) - pl.title('Source and target distributions') - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - - Text(0.5, 1.0, 'Source and target distributions') - - - -Instantiate the different transport algorithms and fit them ------------------------------------------------------------ - - -.. code-block:: default - - - # MappingTransport with linear kernel - ot_mapping_linear = ot.da.MappingTransport( - kernel="linear", mu=1e0, eta=1e-8, bias=True, - max_iter=20, verbose=True) - - ot_mapping_linear.fit(Xs=Xs, Xt=Xt) - - # for original source samples, transform applies barycentric mapping - transp_Xs_linear = ot_mapping_linear.transform(Xs=Xs) - - # for out of source samples, transform applies the linear mapping - transp_Xs_linear_new = ot_mapping_linear.transform(Xs=Xs_new) - - - # MappingTransport with gaussian kernel - ot_mapping_gaussian = ot.da.MappingTransport( - kernel="gaussian", eta=1e-5, mu=1e-1, bias=True, sigma=1, - max_iter=10, verbose=True) - ot_mapping_gaussian.fit(Xs=Xs, Xt=Xt) - - # for original source samples, transform applies barycentric mapping - transp_Xs_gaussian = ot_mapping_gaussian.transform(Xs=Xs) - - # for out of source samples, transform applies the gaussian mapping - transp_Xs_gaussian_new = ot_mapping_gaussian.transform(Xs=Xs_new) - - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Delta loss - -------------------------------- - 0|4.212661e+03|0.000000e+00 - 1|4.198567e+03|-3.345626e-03 - 2|4.198198e+03|-8.797101e-05 - 3|4.198027e+03|-4.059527e-05 - 4|4.197928e+03|-2.355659e-05 - 5|4.197886e+03|-1.002352e-05 - 6|4.197853e+03|-7.873125e-06 - It. |Loss |Delta loss - -------------------------------- - 0|4.231694e+02|0.000000e+00 - 1|4.185911e+02|-1.081889e-02 - 2|4.182717e+02|-7.631953e-04 - 3|4.181271e+02|-3.455908e-04 - 4|4.180328e+02|-2.255461e-04 - 5|4.179645e+02|-1.634435e-04 - 6|4.179136e+02|-1.216359e-04 - 7|4.178752e+02|-9.198108e-05 - 8|4.178465e+02|-6.870868e-05 - 9|4.178243e+02|-5.321390e-05 - 10|4.178054e+02|-4.521725e-05 - - - - -Plot transported samples ------------------------- - - -.. code-block:: default - - - pl.figure(2) - pl.clf() - pl.subplot(2, 2, 1) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) - pl.scatter(transp_Xs_linear[:, 0], transp_Xs_linear[:, 1], c=ys, marker='+', - label='Mapped source samples') - pl.title("Bary. mapping (linear)") - pl.legend(loc=0) - - pl.subplot(2, 2, 2) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) - pl.scatter(transp_Xs_linear_new[:, 0], transp_Xs_linear_new[:, 1], - c=ys, marker='+', label='Learned mapping') - pl.title("Estim. mapping (linear)") - - pl.subplot(2, 2, 3) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) - pl.scatter(transp_Xs_gaussian[:, 0], transp_Xs_gaussian[:, 1], c=ys, - marker='+', label='barycentric mapping') - pl.title("Bary. mapping (kernel)") - - pl.subplot(2, 2, 4) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=.2) - pl.scatter(transp_Xs_gaussian_new[:, 0], transp_Xs_gaussian_new[:, 1], c=ys, - marker='+', label='Learned mapping') - pl.title("Estim. mapping (kernel)") - pl.tight_layout() - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_mapping.py:125: 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 0.843 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_mapping.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_mapping.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_mapping.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb b/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb deleted file mode 100644 index de46629..0000000 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# OT for image color adaptation with mapping estimation\n\n\nOT for domain adaptation with image color adaptation [6] with mapping\nestimation [8].\n\n[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). Regularized\n discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3),\n 1853-1882.\n[8] M. Perrot, N. Courty, R. Flamary, A. Habrard, \"Mapping estimation for\n discrete optimal transport\", Neural Information Processing Systems (NIPS),\n 2016.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Loading images\nI1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Domain adaptation for pixel distribution transfer\n-------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# EMDTransport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\ntransp_Xs_emd = ot_emd.transform(Xs=X1)\nImage_emd = minmax(mat2im(transp_Xs_emd, I1.shape))\n\n# SinkhornTransport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\ntransp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1)\nImage_sinkhorn = minmax(mat2im(transp_Xs_sinkhorn, I1.shape))\n\not_mapping_linear = ot.da.MappingTransport(\n mu=1e0, eta=1e-8, bias=True, max_iter=20, verbose=True)\not_mapping_linear.fit(Xs=Xs, Xt=Xt)\n\nX1tl = ot_mapping_linear.transform(Xs=X1)\nImage_mapping_linear = minmax(mat2im(X1tl, I1.shape))\n\not_mapping_gaussian = ot.da.MappingTransport(\n mu=1e0, eta=1e-2, sigma=1, bias=False, max_iter=10, verbose=True)\not_mapping_gaussian.fit(Xs=Xs, Xt=Xt)\n\nX1tn = ot_mapping_gaussian.transform(Xs=X1) # use the estimated mapping\nImage_mapping_gaussian = minmax(mat2im(X1tn, I1.shape))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot original images\n--------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\npl.subplot(1, 2, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot pixel values distribution\n------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(6.4, 5))\n\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 2], c=Xs)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 2], c=Xt)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 2')\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot transformed images\n-----------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(10, 5))\n\npl.subplot(2, 3, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Im. 1')\n\npl.subplot(2, 3, 4)\npl.imshow(I2)\npl.axis('off')\npl.title('Im. 2')\n\npl.subplot(2, 3, 2)\npl.imshow(Image_emd)\npl.axis('off')\npl.title('EmdTransport')\n\npl.subplot(2, 3, 5)\npl.imshow(Image_sinkhorn)\npl.axis('off')\npl.title('SinkhornTransport')\n\npl.subplot(2, 3, 3)\npl.imshow(Image_mapping_linear)\npl.axis('off')\npl.title('MappingTransport (linear)')\n\npl.subplot(2, 3, 6)\npl.imshow(Image_mapping_gaussian)\npl.axis('off')\npl.title('MappingTransport (gaussian)')\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_mapping_colors_images.py b/docs/source/auto_examples/plot_otda_mapping_colors_images.py deleted file mode 100644 index bc9afba..0000000 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.py +++ /dev/null @@ -1,173 +0,0 @@ -# -*- coding: utf-8 -*- -""" -===================================================== -OT for image color adaptation with mapping estimation -===================================================== - -OT for domain adaptation with image color adaptation [6] with mapping -estimation [8]. - -[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). Regularized - discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), - 1853-1882. -[8] M. Perrot, N. Courty, R. Flamary, A. Habrard, "Mapping estimation for - discrete optimal transport", Neural Information Processing Systems (NIPS), - 2016. - -""" - -# Authors: Remi Flamary -# Stanislas Chambon -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot - -r = np.random.RandomState(42) - - -def im2mat(I): - """Converts and image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - -def mat2im(X, shape): - """Converts back a matrix to an image""" - return X.reshape(shape) - - -def minmax(I): - return np.clip(I, 0, 1) - - -############################################################################## -# Generate data -# ------------- - -# Loading images -I1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256 -I2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 - - -X1 = im2mat(I1) -X2 = im2mat(I2) - -# training samples -nb = 1000 -idx1 = r.randint(X1.shape[0], size=(nb,)) -idx2 = r.randint(X2.shape[0], size=(nb,)) - -Xs = X1[idx1, :] -Xt = X2[idx2, :] - - -############################################################################## -# Domain adaptation for pixel distribution transfer -# ------------------------------------------------- - -# EMDTransport -ot_emd = ot.da.EMDTransport() -ot_emd.fit(Xs=Xs, Xt=Xt) -transp_Xs_emd = ot_emd.transform(Xs=X1) -Image_emd = minmax(mat2im(transp_Xs_emd, I1.shape)) - -# SinkhornTransport -ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) -ot_sinkhorn.fit(Xs=Xs, Xt=Xt) -transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) -Image_sinkhorn = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) - -ot_mapping_linear = ot.da.MappingTransport( - mu=1e0, eta=1e-8, bias=True, max_iter=20, verbose=True) -ot_mapping_linear.fit(Xs=Xs, Xt=Xt) - -X1tl = ot_mapping_linear.transform(Xs=X1) -Image_mapping_linear = minmax(mat2im(X1tl, I1.shape)) - -ot_mapping_gaussian = ot.da.MappingTransport( - mu=1e0, eta=1e-2, sigma=1, bias=False, max_iter=10, verbose=True) -ot_mapping_gaussian.fit(Xs=Xs, Xt=Xt) - -X1tn = ot_mapping_gaussian.transform(Xs=X1) # use the estimated mapping -Image_mapping_gaussian = minmax(mat2im(X1tn, I1.shape)) - - -############################################################################## -# Plot original images -# -------------------- - -pl.figure(1, figsize=(6.4, 3)) -pl.subplot(1, 2, 1) -pl.imshow(I1) -pl.axis('off') -pl.title('Image 1') - -pl.subplot(1, 2, 2) -pl.imshow(I2) -pl.axis('off') -pl.title('Image 2') -pl.tight_layout() - - -############################################################################## -# Plot pixel values distribution -# ------------------------------ - -pl.figure(2, figsize=(6.4, 5)) - -pl.subplot(1, 2, 1) -pl.scatter(Xs[:, 0], Xs[:, 2], c=Xs) -pl.axis([0, 1, 0, 1]) -pl.xlabel('Red') -pl.ylabel('Blue') -pl.title('Image 1') - -pl.subplot(1, 2, 2) -pl.scatter(Xt[:, 0], Xt[:, 2], c=Xt) -pl.axis([0, 1, 0, 1]) -pl.xlabel('Red') -pl.ylabel('Blue') -pl.title('Image 2') -pl.tight_layout() - - -############################################################################## -# Plot transformed images -# ----------------------- - -pl.figure(2, figsize=(10, 5)) - -pl.subplot(2, 3, 1) -pl.imshow(I1) -pl.axis('off') -pl.title('Im. 1') - -pl.subplot(2, 3, 4) -pl.imshow(I2) -pl.axis('off') -pl.title('Im. 2') - -pl.subplot(2, 3, 2) -pl.imshow(Image_emd) -pl.axis('off') -pl.title('EmdTransport') - -pl.subplot(2, 3, 5) -pl.imshow(Image_sinkhorn) -pl.axis('off') -pl.title('SinkhornTransport') - -pl.subplot(2, 3, 3) -pl.imshow(Image_mapping_linear) -pl.axis('off') -pl.title('MappingTransport (linear)') - -pl.subplot(2, 3, 6) -pl.imshow(Image_mapping_gaussian) -pl.axis('off') -pl.title('MappingTransport (gaussian)') -pl.tight_layout() - -pl.show() diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.rst b/docs/source/auto_examples/plot_otda_mapping_colors_images.rst deleted file mode 100644 index 26664e3..0000000 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.rst +++ /dev/null @@ -1,334 +0,0 @@ -.. 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_otda_mapping_colors_images.py: - - -===================================================== -OT for image color adaptation with mapping estimation -===================================================== - -OT for domain adaptation with image color adaptation [6] with mapping -estimation [8]. - -[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). Regularized - discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), - 1853-1882. -[8] M. Perrot, N. Courty, R. Flamary, A. Habrard, "Mapping estimation for - discrete optimal transport", Neural Information Processing Systems (NIPS), - 2016. - - - -.. code-block:: default - - - # Authors: Remi Flamary - # Stanislas Chambon - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - - r = np.random.RandomState(42) - - - def im2mat(I): - """Converts and image to matrix (one pixel per line)""" - return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - - - def mat2im(X, shape): - """Converts back a matrix to an image""" - return X.reshape(shape) - - - def minmax(I): - return np.clip(I, 0, 1) - - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - # Loading images - I1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256 - I2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 - - - X1 = im2mat(I1) - X2 = im2mat(I2) - - # training samples - nb = 1000 - idx1 = r.randint(X1.shape[0], size=(nb,)) - idx2 = r.randint(X2.shape[0], size=(nb,)) - - Xs = X1[idx1, :] - Xt = X2[idx2, :] - - - - - - - - - -Domain adaptation for pixel distribution transfer -------------------------------------------------- - - -.. code-block:: default - - - # EMDTransport - ot_emd = ot.da.EMDTransport() - ot_emd.fit(Xs=Xs, Xt=Xt) - transp_Xs_emd = ot_emd.transform(Xs=X1) - Image_emd = minmax(mat2im(transp_Xs_emd, I1.shape)) - - # SinkhornTransport - ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) - ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) - Image_sinkhorn = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) - - ot_mapping_linear = ot.da.MappingTransport( - mu=1e0, eta=1e-8, bias=True, max_iter=20, verbose=True) - ot_mapping_linear.fit(Xs=Xs, Xt=Xt) - - X1tl = ot_mapping_linear.transform(Xs=X1) - Image_mapping_linear = minmax(mat2im(X1tl, I1.shape)) - - ot_mapping_gaussian = ot.da.MappingTransport( - mu=1e0, eta=1e-2, sigma=1, bias=False, max_iter=10, verbose=True) - ot_mapping_gaussian.fit(Xs=Xs, Xt=Xt) - - X1tn = ot_mapping_gaussian.transform(Xs=X1) # use the estimated mapping - Image_mapping_gaussian = minmax(mat2im(X1tn, I1.shape)) - - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - It. |Loss |Delta loss - -------------------------------- - 0|3.680534e+02|0.000000e+00 - 1|3.592501e+02|-2.391854e-02 - 2|3.590682e+02|-5.061555e-04 - 3|3.589745e+02|-2.610227e-04 - 4|3.589167e+02|-1.611644e-04 - 5|3.588768e+02|-1.109242e-04 - 6|3.588482e+02|-7.972733e-05 - 7|3.588261e+02|-6.166174e-05 - 8|3.588086e+02|-4.871697e-05 - 9|3.587946e+02|-3.919056e-05 - 10|3.587830e+02|-3.228124e-05 - 11|3.587731e+02|-2.744744e-05 - 12|3.587648e+02|-2.334451e-05 - 13|3.587576e+02|-1.995629e-05 - 14|3.587513e+02|-1.761058e-05 - 15|3.587457e+02|-1.542568e-05 - 16|3.587408e+02|-1.366315e-05 - 17|3.587365e+02|-1.221732e-05 - 18|3.587325e+02|-1.102488e-05 - 19|3.587303e+02|-6.062107e-06 - It. |Loss |Delta loss - -------------------------------- - 0|3.784871e+02|0.000000e+00 - 1|3.646491e+02|-3.656142e-02 - 2|3.642975e+02|-9.642655e-04 - 3|3.641626e+02|-3.702413e-04 - 4|3.640888e+02|-2.026301e-04 - 5|3.640419e+02|-1.289607e-04 - 6|3.640097e+02|-8.831646e-05 - 7|3.639861e+02|-6.487612e-05 - 8|3.639679e+02|-4.994063e-05 - 9|3.639536e+02|-3.941436e-05 - 10|3.639419e+02|-3.209753e-05 - - - - -Plot original images --------------------- - - -.. code-block:: default - - - pl.figure(1, figsize=(6.4, 3)) - pl.subplot(1, 2, 1) - pl.imshow(I1) - pl.axis('off') - pl.title('Image 1') - - pl.subplot(1, 2, 2) - pl.imshow(I2) - pl.axis('off') - pl.title('Image 2') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png - :class: sphx-glr-single-img - - - - - -Plot pixel values distribution ------------------------------- - - -.. code-block:: default - - - pl.figure(2, figsize=(6.4, 5)) - - pl.subplot(1, 2, 1) - pl.scatter(Xs[:, 0], Xs[:, 2], c=Xs) - pl.axis([0, 1, 0, 1]) - pl.xlabel('Red') - pl.ylabel('Blue') - pl.title('Image 1') - - pl.subplot(1, 2, 2) - pl.scatter(Xt[:, 0], Xt[:, 2], c=Xt) - pl.axis([0, 1, 0, 1]) - pl.xlabel('Red') - pl.ylabel('Blue') - pl.title('Image 2') - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png - :class: sphx-glr-single-img - - - - - -Plot transformed images ------------------------ - - -.. code-block:: default - - - pl.figure(2, figsize=(10, 5)) - - pl.subplot(2, 3, 1) - pl.imshow(I1) - pl.axis('off') - pl.title('Im. 1') - - pl.subplot(2, 3, 4) - pl.imshow(I2) - pl.axis('off') - pl.title('Im. 2') - - pl.subplot(2, 3, 2) - pl.imshow(Image_emd) - pl.axis('off') - pl.title('EmdTransport') - - pl.subplot(2, 3, 5) - pl.imshow(Image_sinkhorn) - pl.axis('off') - pl.title('SinkhornTransport') - - pl.subplot(2, 3, 3) - pl.imshow(Image_mapping_linear) - pl.axis('off') - pl.title('MappingTransport (linear)') - - pl.subplot(2, 3, 6) - pl.imshow(Image_mapping_gaussian) - pl.axis('off') - pl.title('MappingTransport (gaussian)') - pl.tight_layout() - - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_mapping_colors_images.py:173: 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:** ( 2 minutes 24.007 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_mapping_colors_images.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_mapping_colors_images.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_mapping_colors_images.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_semi_supervised.ipynb b/docs/source/auto_examples/plot_otda_semi_supervised.ipynb deleted file mode 100644 index d2157fb..0000000 --- a/docs/source/auto_examples/plot_otda_semi_supervised.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# OTDA unsupervised vs semi-supervised setting\n\n\nThis example introduces a semi supervised domain adaptation in a 2D setting.\nIt explicits the problem of semi supervised domain adaptation and introduces\nsome optimal transport approaches to solve it.\n\nQuantities such as optimal couplings, greater coupling coefficients and\ntransported samples are represented in order to give a visual understanding\nof what the transport methods are doing.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \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_samples_source = 150\nn_samples_target = 150\n\nXs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source)\nXt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Transport source samples onto target samples\n--------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# unsupervised domain adaptation\not_sinkhorn_un = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn_un.fit(Xs=Xs, Xt=Xt)\ntransp_Xs_sinkhorn_un = ot_sinkhorn_un.transform(Xs=Xs)\n\n# semi-supervised domain adaptation\not_sinkhorn_semi = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn_semi.fit(Xs=Xs, Xt=Xt, ys=ys, yt=yt)\ntransp_Xs_sinkhorn_semi = ot_sinkhorn_semi.transform(Xs=Xs)\n\n# semi supervised DA uses available labaled target samples to modify the cost\n# matrix involved in the OT problem. The cost of transporting a source sample\n# of class A onto a target sample of class B != A is set to infinite, or a\n# very large value\n\n# note that in the present case we consider that all the target samples are\n# labeled. For daily applications, some target sample might not have labels,\n# in this case the element of yt corresponding to these samples should be\n# filled with -1.\n\n# Warning: we recall that -1 cannot be used as a class label" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Fig 1 : plots source and target samples + matrix of pairwise distance\n---------------------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(10, 10))\npl.subplot(2, 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(2, 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')\n\npl.subplot(2, 2, 3)\npl.imshow(ot_sinkhorn_un.cost_, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Cost matrix - unsupervised DA')\n\npl.subplot(2, 2, 4)\npl.imshow(ot_sinkhorn_semi.cost_, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Cost matrix - semisupervised DA')\n\npl.tight_layout()\n\n# the optimal coupling in the semi-supervised DA case will exhibit \" shape\n# similar\" to the cost matrix, (block diagonal matrix)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Fig 2 : plots optimal couplings for the different methods\n---------------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(2, figsize=(8, 4))\n\npl.subplot(1, 2, 1)\npl.imshow(ot_sinkhorn_un.coupling_, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nUnsupervised DA')\n\npl.subplot(1, 2, 2)\npl.imshow(ot_sinkhorn_semi.coupling_, interpolation='nearest')\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSemi-supervised DA')\n\npl.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Fig 3 : plot transported samples\n--------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# display transported samples\npl.figure(4, figsize=(8, 4))\npl.subplot(1, 2, 1)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.5)\npl.scatter(transp_Xs_sinkhorn_un[:, 0], transp_Xs_sinkhorn_un[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.title('Transported samples\\nEmdTransport')\npl.legend(loc=0)\npl.xticks([])\npl.yticks([])\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.5)\npl.scatter(transp_Xs_sinkhorn_semi[:, 0], transp_Xs_sinkhorn_semi[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.title('Transported samples\\nSinkhornTransport')\npl.xticks([])\npl.yticks([])\n\npl.tight_layout()\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_semi_supervised.py b/docs/source/auto_examples/plot_otda_semi_supervised.py deleted file mode 100644 index 8a67720..0000000 --- a/docs/source/auto_examples/plot_otda_semi_supervised.py +++ /dev/null @@ -1,148 +0,0 @@ -# -*- coding: utf-8 -*- -""" -============================================ -OTDA unsupervised vs semi-supervised setting -============================================ - -This example introduces a semi supervised domain adaptation in a 2D setting. -It explicits the problem of semi supervised domain adaptation and introduces -some optimal transport approaches to solve it. - -Quantities such as optimal couplings, greater coupling coefficients and -transported samples are represented in order to give a visual understanding -of what the transport methods are doing. -""" - -# Authors: Remi Flamary -# Stanislas Chambon -# -# License: MIT License - -import matplotlib.pylab as pl -import ot - - -############################################################################## -# Generate data -# ------------- - -n_samples_source = 150 -n_samples_target = 150 - -Xs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source) -Xt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target) - - -############################################################################## -# Transport source samples onto target samples -# -------------------------------------------- - - -# unsupervised domain adaptation -ot_sinkhorn_un = ot.da.SinkhornTransport(reg_e=1e-1) -ot_sinkhorn_un.fit(Xs=Xs, Xt=Xt) -transp_Xs_sinkhorn_un = ot_sinkhorn_un.transform(Xs=Xs) - -# semi-supervised domain adaptation -ot_sinkhorn_semi = ot.da.SinkhornTransport(reg_e=1e-1) -ot_sinkhorn_semi.fit(Xs=Xs, Xt=Xt, ys=ys, yt=yt) -transp_Xs_sinkhorn_semi = ot_sinkhorn_semi.transform(Xs=Xs) - -# semi supervised DA uses available labaled target samples to modify the cost -# matrix involved in the OT problem. The cost of transporting a source sample -# of class A onto a target sample of class B != A is set to infinite, or a -# very large value - -# note that in the present case we consider that all the target samples are -# labeled. For daily applications, some target sample might not have labels, -# in this case the element of yt corresponding to these samples should be -# filled with -1. - -# Warning: we recall that -1 cannot be used as a class label - - -############################################################################## -# Fig 1 : plots source and target samples + matrix of pairwise distance -# --------------------------------------------------------------------- - -pl.figure(1, figsize=(10, 10)) -pl.subplot(2, 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(2, 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.subplot(2, 2, 3) -pl.imshow(ot_sinkhorn_un.cost_, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Cost matrix - unsupervised DA') - -pl.subplot(2, 2, 4) -pl.imshow(ot_sinkhorn_semi.cost_, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Cost matrix - semisupervised DA') - -pl.tight_layout() - -# the optimal coupling in the semi-supervised DA case will exhibit " shape -# similar" to the cost matrix, (block diagonal matrix) - - -############################################################################## -# Fig 2 : plots optimal couplings for the different methods -# --------------------------------------------------------- - -pl.figure(2, figsize=(8, 4)) - -pl.subplot(1, 2, 1) -pl.imshow(ot_sinkhorn_un.coupling_, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nUnsupervised DA') - -pl.subplot(1, 2, 2) -pl.imshow(ot_sinkhorn_semi.coupling_, interpolation='nearest') -pl.xticks([]) -pl.yticks([]) -pl.title('Optimal coupling\nSemi-supervised DA') - -pl.tight_layout() - - -############################################################################## -# Fig 3 : plot transported samples -# -------------------------------- - -# display transported samples -pl.figure(4, figsize=(8, 4)) -pl.subplot(1, 2, 1) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) -pl.scatter(transp_Xs_sinkhorn_un[:, 0], transp_Xs_sinkhorn_un[:, 1], c=ys, - marker='+', label='Transp samples', s=30) -pl.title('Transported samples\nEmdTransport') -pl.legend(loc=0) -pl.xticks([]) -pl.yticks([]) - -pl.subplot(1, 2, 2) -pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) -pl.scatter(transp_Xs_sinkhorn_semi[:, 0], transp_Xs_sinkhorn_semi[:, 1], c=ys, - marker='+', label='Transp samples', s=30) -pl.title('Transported samples\nSinkhornTransport') -pl.xticks([]) -pl.yticks([]) - -pl.tight_layout() -pl.show() diff --git a/docs/source/auto_examples/plot_otda_semi_supervised.rst b/docs/source/auto_examples/plot_otda_semi_supervised.rst deleted file mode 100644 index 4a355e7..0000000 --- a/docs/source/auto_examples/plot_otda_semi_supervised.rst +++ /dev/null @@ -1,267 +0,0 @@ -.. 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_otda_semi_supervised.py: - - -============================================ -OTDA unsupervised vs semi-supervised setting -============================================ - -This example introduces a semi supervised domain adaptation in a 2D setting. -It explicits the problem of semi supervised domain adaptation and introduces -some optimal transport approaches to solve it. - -Quantities such as optimal couplings, greater coupling coefficients and -transported samples are represented in order to give a visual understanding -of what the transport methods are doing. - - -.. code-block:: default - - - # Authors: Remi Flamary - # Stanislas Chambon - # - # License: MIT License - - import matplotlib.pylab as pl - import ot - - - - - - - - - -Generate data -------------- - - -.. code-block:: default - - - n_samples_source = 150 - n_samples_target = 150 - - Xs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source) - Xt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target) - - - - - - - - - -Transport source samples onto target samples --------------------------------------------- - - -.. code-block:: default - - - - # unsupervised domain adaptation - ot_sinkhorn_un = ot.da.SinkhornTransport(reg_e=1e-1) - ot_sinkhorn_un.fit(Xs=Xs, Xt=Xt) - transp_Xs_sinkhorn_un = ot_sinkhorn_un.transform(Xs=Xs) - - # semi-supervised domain adaptation - ot_sinkhorn_semi = ot.da.SinkhornTransport(reg_e=1e-1) - ot_sinkhorn_semi.fit(Xs=Xs, Xt=Xt, ys=ys, yt=yt) - transp_Xs_sinkhorn_semi = ot_sinkhorn_semi.transform(Xs=Xs) - - # semi supervised DA uses available labaled target samples to modify the cost - # matrix involved in the OT problem. The cost of transporting a source sample - # of class A onto a target sample of class B != A is set to infinite, or a - # very large value - - # note that in the present case we consider that all the target samples are - # labeled. For daily applications, some target sample might not have labels, - # in this case the element of yt corresponding to these samples should be - # filled with -1. - - # Warning: we recall that -1 cannot be used as a class label - - - - - - - - - -Fig 1 : plots source and target samples + matrix of pairwise distance ---------------------------------------------------------------------- - - -.. code-block:: default - - - pl.figure(1, figsize=(10, 10)) - pl.subplot(2, 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(2, 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.subplot(2, 2, 3) - pl.imshow(ot_sinkhorn_un.cost_, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Cost matrix - unsupervised DA') - - pl.subplot(2, 2, 4) - pl.imshow(ot_sinkhorn_semi.cost_, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Cost matrix - semisupervised DA') - - pl.tight_layout() - - # the optimal coupling in the semi-supervised DA case will exhibit " shape - # similar" to the cost matrix, (block diagonal matrix) - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_001.png - :class: sphx-glr-single-img - - - - - -Fig 2 : plots optimal couplings for the different methods ---------------------------------------------------------- - - -.. code-block:: default - - - pl.figure(2, figsize=(8, 4)) - - pl.subplot(1, 2, 1) - pl.imshow(ot_sinkhorn_un.coupling_, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nUnsupervised DA') - - pl.subplot(1, 2, 2) - pl.imshow(ot_sinkhorn_semi.coupling_, interpolation='nearest') - pl.xticks([]) - pl.yticks([]) - pl.title('Optimal coupling\nSemi-supervised DA') - - pl.tight_layout() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png - :class: sphx-glr-single-img - - - - - -Fig 3 : plot transported samples --------------------------------- - - -.. code-block:: default - - - # display transported samples - pl.figure(4, figsize=(8, 4)) - pl.subplot(1, 2, 1) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) - pl.scatter(transp_Xs_sinkhorn_un[:, 0], transp_Xs_sinkhorn_un[:, 1], c=ys, - marker='+', label='Transp samples', s=30) - pl.title('Transported samples\nEmdTransport') - pl.legend(loc=0) - pl.xticks([]) - pl.yticks([]) - - pl.subplot(1, 2, 2) - pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', - label='Target samples', alpha=0.5) - pl.scatter(transp_Xs_sinkhorn_semi[:, 0], transp_Xs_sinkhorn_semi[:, 1], c=ys, - marker='+', label='Transp samples', s=30) - pl.title('Transported samples\nSinkhornTransport') - pl.xticks([]) - pl.yticks([]) - - pl.tight_layout() - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_otda_semi_supervised.py:148: 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 0.660 seconds) - - -.. _sphx_glr_download_auto_examples_plot_otda_semi_supervised.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_semi_supervised.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_otda_semi_supervised.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb b/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb deleted file mode 100644 index 539d575..0000000 --- a/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Partial Wasserstein and Gromov-Wasserstein example\n\n\nThis example is designed to show how to use the Partial (Gromov-)Wassertsein\ndistance computation in POT.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Laetitia Chapel \n# License: MIT License\n\n# necessary for 3d plot even if not used\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nimport scipy as sp\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Sample two 2D Gaussian distributions and plot them\n--------------------------------------------------\n\nFor demonstration purpose, we sample two Gaussian distributions in 2-d\nspaces and add some random noise.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_samples = 20 # nb samples (gaussian)\nn_noise = 20 # nb of samples (noise)\n\nmu = np.array([0, 0])\ncov = np.array([[1, 0], [0, 2]])\n\nxs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)\nxs = np.append(xs, (np.random.rand(n_noise, 2) + 1) * 4).reshape((-1, 2))\nxt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)\nxt = np.append(xt, (np.random.rand(n_noise, 2) + 1) * -3).reshape((-1, 2))\n\nM = sp.spatial.distance.cdist(xs, xt)\n\nfig = pl.figure()\nax1 = fig.add_subplot(131)\nax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\nax2 = fig.add_subplot(132)\nax2.scatter(xt[:, 0], xt[:, 1], color='r')\nax3 = fig.add_subplot(133)\nax3.imshow(M)\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute partial Wasserstein plans and distance\n----------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "p = ot.unif(n_samples + n_noise)\nq = ot.unif(n_samples + n_noise)\n\nw0, log0 = ot.partial.partial_wasserstein(p, q, M, m=0.5, log=True)\nw, log = ot.partial.entropic_partial_wasserstein(p, q, M, reg=0.1, m=0.5,\n log=True)\n\nprint('Partial Wasserstein distance (m = 0.5): ' + str(log0['partial_w_dist']))\nprint('Entropic partial Wasserstein distance (m = 0.5): ' +\n str(log['partial_w_dist']))\n\npl.figure(1, (10, 5))\npl.subplot(1, 2, 1)\npl.imshow(w0, cmap='jet')\npl.title('Partial Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(w, cmap='jet')\npl.title('Entropic partial Wasserstein')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Sample one 2D and 3D Gaussian distributions and plot them\n---------------------------------------------------------\n\nThe Gromov-Wasserstein distance allows to compute distances with samples that\ndo not belong to the same metric space. For demonstration purpose, we sample\ntwo Gaussian distributions in 2- and 3-dimensional spaces.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_samples = 20 # nb samples\nn_noise = 10 # nb of samples (noise)\n\np = ot.unif(n_samples + n_noise)\nq = ot.unif(n_samples + n_noise)\n\nmu_s = np.array([0, 0])\ncov_s = np.array([[1, 0], [0, 1]])\n\nmu_t = np.array([0, 0, 0])\ncov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])\n\n\nxs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s)\nxs = np.concatenate((xs, ((np.random.rand(n_noise, 2) + 1) * 4)), axis=0)\nP = sp.linalg.sqrtm(cov_t)\nxt = np.random.randn(n_samples, 3).dot(P) + mu_t\nxt = np.concatenate((xt, ((np.random.rand(n_noise, 3) + 1) * 10)), axis=0)\n\nfig = pl.figure()\nax1 = fig.add_subplot(121)\nax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\nax2 = fig.add_subplot(122, projection='3d')\nax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute partial Gromov-Wasserstein plans and distance\n-----------------------------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "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()" - ] - } - ], - "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_partial_wass_and_gromov.py b/docs/source/auto_examples/plot_partial_wass_and_gromov.py deleted file mode 100644 index 9f95a70..0000000 --- a/docs/source/auto_examples/plot_partial_wass_and_gromov.py +++ /dev/null @@ -1,163 +0,0 @@ -# -*- 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. -""" - -# Author: Laetitia Chapel -# License: MIT License - -# necessary for 3d plot even if not used -from mpl_toolkits.mplot3d import Axes3D # noqa -import scipy as sp -import numpy as np -import matplotlib.pylab as pl -import ot - - -############################################################################# -# -# Sample two 2D Gaussian distributions and plot them -# -------------------------------------------------- -# -# For demonstration purpose, we sample two Gaussian distributions in 2-d -# spaces and add some random noise. - - -n_samples = 20 # nb samples (gaussian) -n_noise = 20 # nb of samples (noise) - -mu = np.array([0, 0]) -cov = np.array([[1, 0], [0, 2]]) - -xs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov) -xs = np.append(xs, (np.random.rand(n_noise, 2) + 1) * 4).reshape((-1, 2)) -xt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov) -xt = np.append(xt, (np.random.rand(n_noise, 2) + 1) * -3).reshape((-1, 2)) - -M = sp.spatial.distance.cdist(xs, xt) - -fig = pl.figure() -ax1 = fig.add_subplot(131) -ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -ax2 = fig.add_subplot(132) -ax2.scatter(xt[:, 0], xt[:, 1], color='r') -ax3 = fig.add_subplot(133) -ax3.imshow(M) -pl.show() - -############################################################################# -# -# Compute partial Wasserstein plans and distance -# ---------------------------------------------- - -p = ot.unif(n_samples + n_noise) -q = ot.unif(n_samples + n_noise) - -w0, log0 = ot.partial.partial_wasserstein(p, q, M, m=0.5, log=True) -w, log = ot.partial.entropic_partial_wasserstein(p, q, M, reg=0.1, m=0.5, - log=True) - -print('Partial Wasserstein distance (m = 0.5): ' + str(log0['partial_w_dist'])) -print('Entropic partial Wasserstein distance (m = 0.5): ' + - str(log['partial_w_dist'])) - -pl.figure(1, (10, 5)) -pl.subplot(1, 2, 1) -pl.imshow(w0, cmap='jet') -pl.title('Partial Wasserstein') -pl.subplot(1, 2, 2) -pl.imshow(w, cmap='jet') -pl.title('Entropic partial Wasserstein') -pl.show() - - -############################################################################# -# -# Sample one 2D and 3D Gaussian distributions and plot them -# --------------------------------------------------------- -# -# The Gromov-Wasserstein distance allows to compute distances with samples that -# do not belong to the same metric space. For demonstration purpose, we sample -# two Gaussian distributions in 2- and 3-dimensional spaces. - -n_samples = 20 # nb samples -n_noise = 10 # nb of samples (noise) - -p = ot.unif(n_samples + n_noise) -q = ot.unif(n_samples + n_noise) - -mu_s = np.array([0, 0]) -cov_s = np.array([[1, 0], [0, 1]]) - -mu_t = np.array([0, 0, 0]) -cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) - - -xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s) -xs = np.concatenate((xs, ((np.random.rand(n_noise, 2) + 1) * 4)), axis=0) -P = sp.linalg.sqrtm(cov_t) -xt = np.random.randn(n_samples, 3).dot(P) + mu_t -xt = np.concatenate((xt, ((np.random.rand(n_noise, 3) + 1) * 10)), axis=0) - -fig = pl.figure() -ax1 = fig.add_subplot(121) -ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') -ax2 = fig.add_subplot(122, projection='3d') -ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r') -pl.show() - - -############################################################################# -# -# 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) -res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10, - m=m, log=True) - -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('Wasserstein') -pl.subplot(1, 2, 2) -pl.imshow(res, cmap='jet') -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) -res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10, - m=m, log=True) - -print('Partial Wasserstein distance (m = 2/3): ' + - str(log0['partial_gw_dist'])) -print('Entropic partial Wasserstein distance (m = 2/3): ' + - str(log['partial_gw_dist'])) - -pl.figure(1, (10, 5)) -pl.title("mass to be transported m = 2/3") -pl.subplot(1, 2, 1) -pl.imshow(res0, cmap='jet') -pl.title('Partial Wasserstein') -pl.subplot(1, 2, 2) -pl.imshow(res, cmap='jet') -pl.title('Entropic partial Wasserstein') -pl.show() diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.rst b/docs/source/auto_examples/plot_partial_wass_and_gromov.rst deleted file mode 100644 index 2d51210..0000000 --- a/docs/source/auto_examples/plot_partial_wass_and_gromov.rst +++ /dev/null @@ -1,312 +0,0 @@ -.. 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_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. - - -.. code-block:: default - - - # Author: Laetitia Chapel - # License: MIT License - - # necessary for 3d plot even if not used - from mpl_toolkits.mplot3d import Axes3D # noqa - import scipy as sp - import numpy as np - import matplotlib.pylab as pl - import ot - - - - - - - - - -Sample two 2D Gaussian distributions and plot them --------------------------------------------------- - -For demonstration purpose, we sample two Gaussian distributions in 2-d -spaces and add some random noise. - - -.. code-block:: default - - - - n_samples = 20 # nb samples (gaussian) - n_noise = 20 # nb of samples (noise) - - mu = np.array([0, 0]) - cov = np.array([[1, 0], [0, 2]]) - - xs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov) - xs = np.append(xs, (np.random.rand(n_noise, 2) + 1) * 4).reshape((-1, 2)) - xt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov) - xt = np.append(xt, (np.random.rand(n_noise, 2) + 1) * -3).reshape((-1, 2)) - - M = sp.spatial.distance.cdist(xs, xt) - - fig = pl.figure() - ax1 = fig.add_subplot(131) - ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - ax2 = fig.add_subplot(132) - ax2.scatter(xt[:, 0], xt[:, 1], color='r') - ax3 = fig.add_subplot(133) - ax3.imshow(M) - pl.show() - - - - -.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:51: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Compute partial Wasserstein plans and distance ----------------------------------------------- - - -.. code-block:: default - - - p = ot.unif(n_samples + n_noise) - q = ot.unif(n_samples + n_noise) - - w0, log0 = ot.partial.partial_wasserstein(p, q, M, m=0.5, log=True) - w, log = ot.partial.entropic_partial_wasserstein(p, q, M, reg=0.1, m=0.5, - log=True) - - print('Partial Wasserstein distance (m = 0.5): ' + str(log0['partial_w_dist'])) - print('Entropic partial Wasserstein distance (m = 0.5): ' + - str(log['partial_w_dist'])) - - pl.figure(1, (10, 5)) - pl.subplot(1, 2, 1) - pl.imshow(w0, cmap='jet') - pl.title('Partial Wasserstein') - pl.subplot(1, 2, 2) - pl.imshow(w, cmap='jet') - pl.title('Entropic partial Wasserstein') - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - 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() - - - - -Sample one 2D and 3D Gaussian distributions and plot them ---------------------------------------------------------- - -The Gromov-Wasserstein distance allows to compute distances with samples that -do not belong to the same metric space. For demonstration purpose, we sample -two Gaussian distributions in 2- and 3-dimensional spaces. - - -.. code-block:: default - - - n_samples = 20 # nb samples - n_noise = 10 # nb of samples (noise) - - p = ot.unif(n_samples + n_noise) - q = ot.unif(n_samples + n_noise) - - mu_s = np.array([0, 0]) - cov_s = np.array([[1, 0], [0, 1]]) - - mu_t = np.array([0, 0, 0]) - cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) - - - xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s) - xs = np.concatenate((xs, ((np.random.rand(n_noise, 2) + 1) * 4)), axis=0) - P = sp.linalg.sqrtm(cov_t) - xt = np.random.randn(n_samples, 3).dot(P) + mu_t - xt = np.concatenate((xt, ((np.random.rand(n_noise, 3) + 1) * 10)), axis=0) - - fig = pl.figure() - ax1 = fig.add_subplot(121) - ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') - ax2 = fig.add_subplot(122, projection='3d') - ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r') - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /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 ------------------------------------------------------ - - -.. code-block:: default - - - 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) - res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10, - m=m, log=True) - - 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('Wasserstein') - pl.subplot(1, 2, 2) - pl.imshow(res, cmap='jet') - 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) - res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10, - m=m, log=True) - - print('Partial Wasserstein distance (m = 2/3): ' + - str(log0['partial_gw_dist'])) - print('Entropic partial Wasserstein distance (m = 2/3): ' + - str(log['partial_gw_dist'])) - - pl.figure(1, (10, 5)) - pl.title("mass to be transported m = 2/3") - pl.subplot(1, 2, 1) - pl.imshow(res0, cmap='jet') - pl.title('Partial Wasserstein') - pl.subplot(1, 2, 2) - pl.imshow(res, cmap='jet') - pl.title('Entropic partial Wasserstein') - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - -----m = 1 - 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.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: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:163: 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.543 seconds) - - -.. _sphx_glr_download_auto_examples_plot_partial_wass_and_gromov.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_partial_wass_and_gromov.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_partial_wass_and_gromov.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_screenkhorn_1D.ipynb b/docs/source/auto_examples/plot_screenkhorn_1D.ipynb deleted file mode 100644 index 1c27d3b..0000000 --- a/docs/source/auto_examples/plot_screenkhorn_1D.ipynb +++ /dev/null @@ -1,108 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# 1D Screened optimal transport\n\n\nThis example illustrates the computation of Screenkhorn:\nScreening Sinkhorn Algorithm for Optimal transport.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Mokhtar Z. Alaya \n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot.plot\nfrom ot.datasets import make_1D_gauss as gauss\nfrom ot.bregman import screenkhorn" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Generate data\n-------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot distributions and loss matrix\n----------------------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()\n\n# plot distributions and loss matrix\n\npl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Solve Screenkhorn\n-----------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Screenkhorn\nlambd = 2e-03 # entropy parameter\nns_budget = 30 # budget number of points to be keeped in the source distribution\nnt_budget = 30 # budget number of points to be keeped in the target distribution\n\nG_screen = screenkhorn(a, b, M, lambd, ns_budget, nt_budget, uniform=False, restricted=True, verbose=True)\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G_screen, 'OT matrix Screenkhorn')\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_screenkhorn_1D.py b/docs/source/auto_examples/plot_screenkhorn_1D.py deleted file mode 100644 index 840ead8..0000000 --- a/docs/source/auto_examples/plot_screenkhorn_1D.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -""" -=============================== -1D Screened optimal transport -=============================== - -This example illustrates the computation of Screenkhorn: -Screening Sinkhorn Algorithm for Optimal transport. -""" - -# 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 - -############################################################################## -# Generate data -# ------------- - -#%% parameters - -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() - -############################################################################## -# Plot distributions and loss matrix -# ---------------------------------- - -#%% plot the distributions - -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') - -############################################################################## -# Solve Screenkhorn -# ----------------------- - -# 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() diff --git a/docs/source/auto_examples/plot_screenkhorn_1D.rst b/docs/source/auto_examples/plot_screenkhorn_1D.rst deleted file mode 100644 index 039479e..0000000 --- a/docs/source/auto_examples/plot_screenkhorn_1D.rst +++ /dev/null @@ -1,178 +0,0 @@ -.. 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: -Screening Sinkhorn Algorithm for Optimal transport. - - -.. 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 - - - - - - - - -Generate data -------------- - - -.. 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() - - - - - - - - -Plot distributions and loss matrix ----------------------------------- - - -.. 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:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png - :class: sphx-glr-multi-img - - * - - .. image:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png - :class: sphx-glr-multi-img - - - - - -Solve Screenkhorn ------------------------ - - -.. 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:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/ot/bregman.py:2056: UserWarning: Bottleneck module is not installed. Install it from https://pypi.org/project/Bottleneck/ for better performance. - "Bottleneck module is not installed. Install it from https://pypi.org/project/Bottleneck/ for better performance.") - epsilon = 0.020986042861303855 - - kappa = 3.7476531411890917 - - Cardinality of selected points: |Isel| = 30 |Jsel| = 30 - - /home/rflamary/PYTHON/POT/examples/plot_screenkhorn_1D.py:68: 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 0.228 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 `_ diff --git a/docs/source/auto_examples/plot_stochastic.ipynb b/docs/source/auto_examples/plot_stochastic.ipynb deleted file mode 100644 index c29f75a..0000000 --- a/docs/source/auto_examples/plot_stochastic.ipynb +++ /dev/null @@ -1,295 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Stochastic examples\n\n\nThis example is designed to show how to use the stochatic optimization\nalgorithms for descrete and semicontinous measures from the POT library.\n\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Author: Kilian Fatras \n#\n# License: MIT License\n\nimport matplotlib.pylab as pl\nimport numpy as np\nimport ot\nimport ot.plot" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM\n############################################################################\n############################################################################\n DISCRETE CASE:\n\n Sample two discrete measures for the discrete case\n ---------------------------------------------\n\n Define 2 discrete measures a and b, the points where are defined the source\n and the target measures and finally the cost matrix c.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_source = 7\nn_target = 4\nreg = 1\nnumItermax = 1000\n\na = ot.utils.unif(n_source)\nb = ot.utils.unif(n_target)\n\nrng = np.random.RandomState(0)\nX_source = rng.randn(n_source, 2)\nY_target = rng.randn(n_target, 2)\nM = ot.dist(X_source, Y_target)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Call the \"SAG\" method to find the transportation matrix in the discrete case\n---------------------------------------------\n\nDefine the method \"SAG\", call ot.solve_semi_dual_entropic and plot the\nresults.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "method = \"SAG\"\nsag_pi = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method,\n numItermax)\nprint(sag_pi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SEMICONTINOUS CASE:\n\nSample one general measure a, one discrete measures b for the semicontinous\ncase\n---------------------------------------------\n\nDefine one general measure a, one discrete measures b, the points where\nare defined the source and the target measures and finally the cost matrix c.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_source = 7\nn_target = 4\nreg = 1\nnumItermax = 1000\nlog = True\n\na = ot.utils.unif(n_source)\nb = ot.utils.unif(n_target)\n\nrng = np.random.RandomState(0)\nX_source = rng.randn(n_source, 2)\nY_target = rng.randn(n_target, 2)\nM = ot.dist(X_source, Y_target)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Call the \"ASGD\" method to find the transportation matrix in the semicontinous\ncase\n---------------------------------------------\n\nDefine the method \"ASGD\", call ot.solve_semi_dual_entropic and plot the\nresults.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "method = \"ASGD\"\nasgd_pi, log_asgd = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method,\n numItermax, log=log)\nprint(log_asgd['alpha'], log_asgd['beta'])\nprint(asgd_pi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compare the results with the Sinkhorn algorithm\n---------------------------------------------\n\nCall the Sinkhorn algorithm from POT\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "sinkhorn_pi = ot.sinkhorn(a, b, M, reg)\nprint(sinkhorn_pi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "PLOT TRANSPORTATION MATRIX\n#############################################################################\n\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot SAG results\n----------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, sag_pi, 'semi-dual : OT matrix SAG')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot ASGD results\n-----------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, asgd_pi, 'semi-dual : OT matrix ASGD')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot Sinkhorn results\n---------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, sinkhorn_pi, 'OT matrix Sinkhorn')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM\n############################################################################\n############################################################################\n SEMICONTINOUS CASE:\n\n Sample one general measure a, one discrete measures b for the semicontinous\n case\n ---------------------------------------------\n\n Define one general measure a, one discrete measures b, the points where\n are defined the source and the target measures and finally the cost matrix c.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "n_source = 7\nn_target = 4\nreg = 1\nnumItermax = 100000\nlr = 0.1\nbatch_size = 3\nlog = True\n\na = ot.utils.unif(n_source)\nb = ot.utils.unif(n_target)\n\nrng = np.random.RandomState(0)\nX_source = rng.randn(n_source, 2)\nY_target = rng.randn(n_target, 2)\nM = ot.dist(X_source, Y_target)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Call the \"SGD\" dual method to find the transportation matrix in the\nsemicontinous case\n---------------------------------------------\n\nCall ot.solve_dual_entropic and plot the results.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "sgd_dual_pi, log_sgd = ot.stochastic.solve_dual_entropic(a, b, M, reg,\n batch_size, numItermax,\n lr, log=log)\nprint(log_sgd['alpha'], log_sgd['beta'])\nprint(sgd_dual_pi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compare the results with the Sinkhorn algorithm\n---------------------------------------------\n\nCall the Sinkhorn algorithm from POT\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "sinkhorn_pi = ot.sinkhorn(a, b, M, reg)\nprint(sinkhorn_pi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot SGD results\n-----------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, sgd_dual_pi, 'dual : OT matrix SGD')\npl.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot Sinkhorn results\n---------------------\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, sinkhorn_pi, 'OT matrix Sinkhorn')\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_stochastic.py b/docs/source/auto_examples/plot_stochastic.py deleted file mode 100644 index 742f8d9..0000000 --- a/docs/source/auto_examples/plot_stochastic.py +++ /dev/null @@ -1,208 +0,0 @@ -""" -========================== -Stochastic examples -========================== - -This example is designed to show how to use the stochatic optimization -algorithms for descrete and semicontinous measures from the POT library. - -""" - -# Author: Kilian Fatras -# -# License: MIT License - -import matplotlib.pylab as pl -import numpy as np -import ot -import ot.plot - - -############################################################################# -# COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM -############################################################################# -############################################################################# -# DISCRETE CASE: -# -# Sample two discrete measures for the discrete case -# --------------------------------------------- -# -# Define 2 discrete measures a and b, the points where are defined the source -# and the target measures and finally the cost matrix c. - -n_source = 7 -n_target = 4 -reg = 1 -numItermax = 1000 - -a = ot.utils.unif(n_source) -b = ot.utils.unif(n_target) - -rng = np.random.RandomState(0) -X_source = rng.randn(n_source, 2) -Y_target = rng.randn(n_target, 2) -M = ot.dist(X_source, Y_target) - -############################################################################# -# -# Call the "SAG" method to find the transportation matrix in the discrete case -# --------------------------------------------- -# -# Define the method "SAG", call ot.solve_semi_dual_entropic and plot the -# results. - -method = "SAG" -sag_pi = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method, - numItermax) -print(sag_pi) - -############################################################################# -# SEMICONTINOUS CASE: -# -# Sample one general measure a, one discrete measures b for the semicontinous -# case -# --------------------------------------------- -# -# Define one general measure a, one discrete measures b, the points where -# are defined the source and the target measures and finally the cost matrix c. - -n_source = 7 -n_target = 4 -reg = 1 -numItermax = 1000 -log = True - -a = ot.utils.unif(n_source) -b = ot.utils.unif(n_target) - -rng = np.random.RandomState(0) -X_source = rng.randn(n_source, 2) -Y_target = rng.randn(n_target, 2) -M = ot.dist(X_source, Y_target) - -############################################################################# -# -# Call the "ASGD" method to find the transportation matrix in the semicontinous -# case -# --------------------------------------------- -# -# Define the method "ASGD", call ot.solve_semi_dual_entropic and plot the -# results. - -method = "ASGD" -asgd_pi, log_asgd = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method, - numItermax, log=log) -print(log_asgd['alpha'], log_asgd['beta']) -print(asgd_pi) - -############################################################################# -# -# Compare the results with the Sinkhorn algorithm -# --------------------------------------------- -# -# Call the Sinkhorn algorithm from POT - -sinkhorn_pi = ot.sinkhorn(a, b, M, reg) -print(sinkhorn_pi) - - -############################################################################## -# PLOT TRANSPORTATION MATRIX -############################################################################## - -############################################################################## -# Plot SAG results -# ---------------- - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, sag_pi, 'semi-dual : OT matrix SAG') -pl.show() - - -############################################################################## -# Plot ASGD results -# ----------------- - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, asgd_pi, 'semi-dual : OT matrix ASGD') -pl.show() - - -############################################################################## -# Plot Sinkhorn results -# --------------------- - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, sinkhorn_pi, 'OT matrix Sinkhorn') -pl.show() - - -############################################################################# -# COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM -############################################################################# -############################################################################# -# SEMICONTINOUS CASE: -# -# Sample one general measure a, one discrete measures b for the semicontinous -# case -# --------------------------------------------- -# -# Define one general measure a, one discrete measures b, the points where -# are defined the source and the target measures and finally the cost matrix c. - -n_source = 7 -n_target = 4 -reg = 1 -numItermax = 100000 -lr = 0.1 -batch_size = 3 -log = True - -a = ot.utils.unif(n_source) -b = ot.utils.unif(n_target) - -rng = np.random.RandomState(0) -X_source = rng.randn(n_source, 2) -Y_target = rng.randn(n_target, 2) -M = ot.dist(X_source, Y_target) - -############################################################################# -# -# Call the "SGD" dual method to find the transportation matrix in the -# semicontinous case -# --------------------------------------------- -# -# Call ot.solve_dual_entropic and plot the results. - -sgd_dual_pi, log_sgd = ot.stochastic.solve_dual_entropic(a, b, M, reg, - batch_size, numItermax, - lr, log=log) -print(log_sgd['alpha'], log_sgd['beta']) -print(sgd_dual_pi) - -############################################################################# -# -# Compare the results with the Sinkhorn algorithm -# --------------------------------------------- -# -# Call the Sinkhorn algorithm from POT - -sinkhorn_pi = ot.sinkhorn(a, b, M, reg) -print(sinkhorn_pi) - -############################################################################## -# Plot SGD results -# ----------------- - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, sgd_dual_pi, 'dual : OT matrix SGD') -pl.show() - - -############################################################################## -# Plot Sinkhorn results -# --------------------- - -pl.figure(4, figsize=(5, 5)) -ot.plot.plot1D_mat(a, b, sinkhorn_pi, 'OT matrix Sinkhorn') -pl.show() diff --git a/docs/source/auto_examples/plot_stochastic.rst b/docs/source/auto_examples/plot_stochastic.rst deleted file mode 100644 index 63fc74f..0000000 --- a/docs/source/auto_examples/plot_stochastic.rst +++ /dev/null @@ -1,518 +0,0 @@ -.. 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_stochastic.py: - - -========================== -Stochastic examples -========================== - -This example is designed to show how to use the stochatic optimization -algorithms for descrete and semicontinous measures from the POT library. - - - -.. code-block:: default - - - # Author: Kilian Fatras - # - # License: MIT License - - import matplotlib.pylab as pl - import numpy as np - import ot - import ot.plot - - - - - - - - - -COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM -############################################################################ -############################################################################ - DISCRETE CASE: - - Sample two discrete measures for the discrete case - --------------------------------------------- - - Define 2 discrete measures a and b, the points where are defined the source - and the target measures and finally the cost matrix c. - - -.. code-block:: default - - - n_source = 7 - n_target = 4 - reg = 1 - numItermax = 1000 - - a = ot.utils.unif(n_source) - b = ot.utils.unif(n_target) - - rng = np.random.RandomState(0) - X_source = rng.randn(n_source, 2) - Y_target = rng.randn(n_target, 2) - M = ot.dist(X_source, Y_target) - - - - - - - - -Call the "SAG" method to find the transportation matrix in the discrete case ---------------------------------------------- - -Define the method "SAG", call ot.solve_semi_dual_entropic and plot the -results. - - -.. code-block:: default - - - method = "SAG" - sag_pi = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method, - numItermax) - print(sag_pi) - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - [[2.55553509e-02 9.96395660e-02 1.76579142e-02 4.31178196e-06] - [1.21640234e-01 1.25357448e-02 1.30225078e-03 7.37891338e-03] - [3.56123975e-03 7.61451746e-02 6.31505947e-02 1.33831456e-07] - [2.61515202e-02 3.34246014e-02 8.28734709e-02 4.07550428e-04] - [9.85500870e-03 7.52288517e-04 1.08262628e-02 1.21423583e-01] - [2.16904253e-02 9.03825797e-04 1.87178503e-03 1.18391107e-01] - [4.15462212e-02 2.65987989e-02 7.23177216e-02 2.39440107e-03]] - - - - -SEMICONTINOUS CASE: - -Sample one general measure a, one discrete measures b for the semicontinous -case ---------------------------------------------- - -Define one general measure a, one discrete measures b, the points where -are defined the source and the target measures and finally the cost matrix c. - - -.. code-block:: default - - - n_source = 7 - n_target = 4 - reg = 1 - numItermax = 1000 - log = True - - a = ot.utils.unif(n_source) - b = ot.utils.unif(n_target) - - rng = np.random.RandomState(0) - X_source = rng.randn(n_source, 2) - Y_target = rng.randn(n_target, 2) - M = ot.dist(X_source, Y_target) - - - - - - - - -Call the "ASGD" method to find the transportation matrix in the semicontinous -case ---------------------------------------------- - -Define the method "ASGD", call ot.solve_semi_dual_entropic and plot the -results. - - -.. code-block:: default - - - method = "ASGD" - asgd_pi, log_asgd = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method, - numItermax, log=log) - print(log_asgd['alpha'], log_asgd['beta']) - print(asgd_pi) - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - [3.89943264 7.64823414 3.9284189 2.67501041 1.42825446 3.26039819 - 2.79237712] [-2.50786905 -2.42684838 -0.93647774 5.87119517] - [[2.50229922e-02 1.00367920e-01 1.74615056e-02 4.72486104e-06] - [1.20583329e-01 1.27839737e-02 1.30373565e-03 8.18610462e-03] - [3.49243139e-03 7.68200813e-02 6.25444833e-02 1.46879008e-07] - [2.58205995e-02 3.39501207e-02 8.26360982e-02 4.50324517e-04] - [8.94164918e-03 7.02183713e-04 9.92028326e-03 1.23293027e-01] - [1.97360234e-02 8.46022708e-04 1.72001583e-03 1.20555081e-01] - [4.10386980e-02 2.70289873e-02 7.21425804e-02 2.64687723e-03]] - - - - -Compare the results with the Sinkhorn algorithm ---------------------------------------------- - -Call the Sinkhorn algorithm from POT - - -.. code-block:: default - - - sinkhorn_pi = ot.sinkhorn(a, b, M, reg) - print(sinkhorn_pi) - - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - [[2.55553508e-02 9.96395661e-02 1.76579142e-02 4.31178193e-06] - [1.21640234e-01 1.25357448e-02 1.30225079e-03 7.37891333e-03] - [3.56123974e-03 7.61451746e-02 6.31505947e-02 1.33831455e-07] - [2.61515201e-02 3.34246014e-02 8.28734709e-02 4.07550425e-04] - [9.85500876e-03 7.52288523e-04 1.08262629e-02 1.21423583e-01] - [2.16904255e-02 9.03825804e-04 1.87178504e-03 1.18391107e-01] - [4.15462212e-02 2.65987989e-02 7.23177217e-02 2.39440105e-03]] - - - - -PLOT TRANSPORTATION MATRIX -############################################################################# - -Plot SAG results ----------------- - - -.. code-block:: default - - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, sag_pi, 'semi-dual : OT matrix SAG') - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_001.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:119: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Plot ASGD results ------------------ - - -.. code-block:: default - - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, asgd_pi, 'semi-dual : OT matrix ASGD') - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_002.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:128: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Plot Sinkhorn results ---------------------- - - -.. code-block:: default - - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, sinkhorn_pi, 'OT matrix Sinkhorn') - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_003.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:137: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM -############################################################################ -############################################################################ - SEMICONTINOUS CASE: - - Sample one general measure a, one discrete measures b for the semicontinous - case - --------------------------------------------- - - Define one general measure a, one discrete measures b, the points where - are defined the source and the target measures and finally the cost matrix c. - - -.. code-block:: default - - - n_source = 7 - n_target = 4 - reg = 1 - numItermax = 100000 - lr = 0.1 - batch_size = 3 - log = True - - a = ot.utils.unif(n_source) - b = ot.utils.unif(n_target) - - rng = np.random.RandomState(0) - X_source = rng.randn(n_source, 2) - Y_target = rng.randn(n_target, 2) - M = ot.dist(X_source, Y_target) - - - - - - - - -Call the "SGD" dual method to find the transportation matrix in the -semicontinous case ---------------------------------------------- - -Call ot.solve_dual_entropic and plot the results. - - -.. code-block:: default - - - sgd_dual_pi, log_sgd = ot.stochastic.solve_dual_entropic(a, b, M, reg, - batch_size, numItermax, - lr, log=log) - print(log_sgd['alpha'], log_sgd['beta']) - print(sgd_dual_pi) - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - [0.91421006 2.78075506 1.06828701 0.01979397 0.60914807 1.81887037 - 0.1152939 ] [0.33964624 0.47604281 1.57223631 4.93843308] - [[2.18038772e-02 9.24355133e-02 1.08426805e-02 9.39355366e-08] - [1.59966167e-02 1.79248770e-03 1.23251128e-04 2.47779034e-05] - [3.44864558e-03 8.01760930e-02 4.40119061e-02 3.30922887e-09] - [3.12954103e-02 4.34915712e-02 7.13747533e-02 1.24533534e-05] - [6.79742497e-02 5.64192090e-03 5.37416946e-02 2.13851205e-02] - [8.05141568e-02 3.64790957e-03 5.00040902e-03 1.12213345e-02] - [4.86643900e-02 3.38763749e-02 6.09634969e-02 7.16139950e-05]] - - - - -Compare the results with the Sinkhorn algorithm ---------------------------------------------- - -Call the Sinkhorn algorithm from POT - - -.. code-block:: default - - - sinkhorn_pi = ot.sinkhorn(a, b, M, reg) - print(sinkhorn_pi) - - - - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - [[2.55553508e-02 9.96395661e-02 1.76579142e-02 4.31178193e-06] - [1.21640234e-01 1.25357448e-02 1.30225079e-03 7.37891333e-03] - [3.56123974e-03 7.61451746e-02 6.31505947e-02 1.33831455e-07] - [2.61515201e-02 3.34246014e-02 8.28734709e-02 4.07550425e-04] - [9.85500876e-03 7.52288523e-04 1.08262629e-02 1.21423583e-01] - [2.16904255e-02 9.03825804e-04 1.87178504e-03 1.18391107e-01] - [4.15462212e-02 2.65987989e-02 7.23177217e-02 2.39440105e-03]] - - - - -Plot SGD results ------------------ - - -.. code-block:: default - - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, sgd_dual_pi, 'dual : OT matrix SGD') - pl.show() - - - - - -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_004.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:199: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. - pl.show() - - - - -Plot Sinkhorn results ---------------------- - - -.. code-block:: default - - - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, sinkhorn_pi, 'OT matrix Sinkhorn') - pl.show() - - - -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_005.png - :class: sphx-glr-single-img - - -.. rst-class:: sphx-glr-script-out - - Out: - - .. code-block:: none - - /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:208: 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 8.885 seconds) - - -.. _sphx_glr_download_auto_examples_plot_stochastic.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_stochastic.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_stochastic.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/searchindex b/docs/source/auto_examples/searchindex deleted file mode 100644 index 2cad500..0000000 Binary files a/docs/source/auto_examples/searchindex and /dev/null differ diff --git a/docs/source/conf.py b/docs/source/conf.py index d29b829..880c71d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -34,9 +34,11 @@ class Mock(MagicMock): @classmethod def __getattr__(cls, name): return MagicMock() -MOCK_MODULES = ['ot.lp.emd_wrap','autograd','pymanopt','cupy','autograd.numpy','pymanopt.manifolds','pymanopt.solvers'] + + +MOCK_MODULES = ['ot.lp.emd_wrap', 'autograd', 'pymanopt', 'cupy', 'autograd.numpy', 'pymanopt.manifolds', 'pymanopt.solvers'] # 'autograd.numpy','pymanopt.manifolds','pymanopt.solvers', -sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) +#sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) # !!!! # If extensions (or modules to document with autodoc) are in another directory, @@ -65,7 +67,7 @@ extensions = [ 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', - #'sphinx_gallery.gen_gallery', + 'sphinx_gallery.gen_gallery', ] napoleon_numpy_docstring = True @@ -248,17 +250,17 @@ htmlhelp_basename = 'POTdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # Additional stuff for the LaTeX preamble. + #'preamble': '', -# Latex figure (float) alignment -#'figure_align': 'htbp', + # Latex figure (float) alignment + #'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples @@ -334,7 +336,7 @@ intersphinx_mapping = {'python': ('https://docs.python.org/3', None), 'matplotlib': ('http://matplotlib.sourceforge.net/', None)} sphinx_gallery_conf = { - 'examples_dirs': ['../../examples','../../examples/da'], + 'examples_dirs': ['../../examples', '../../examples/da'], 'gallery_dirs': 'auto_examples', 'backreferences_dir': '../modules/generated/', 'reference_url': { diff --git a/docs/source/index.md b/docs/source/index.md new file mode 100644 index 0000000..9acdcf3 --- /dev/null +++ b/docs/source/index.md @@ -0,0 +1 @@ +` \ No newline at end of file diff --git a/docs/source/readme.rst b/docs/source/readme.rst index 4f6af01..279e5da 100644 --- a/docs/source/readme.rst +++ b/docs/source/readme.rst @@ -1,14 +1,16 @@ POT: Python Optimal Transport ============================= -|PyPI version| |Anaconda Cloud| |Build Status| |Documentation Status| +|PyPI version| |Anaconda Cloud| |Build Status| |Codecov Status| |Downloads| |Anaconda downloads| |License| This open source Python library provide several solvers for optimization problems related to Optimal Transport for signal, image processing and machine learning. -It provides the following solvers: +Website and documentation: https://PythonOT.github.io/ + +POT provides the following solvers: - OT Network Flow solver for the linear program/ Earth Movers Distance [1]. @@ -24,7 +26,7 @@ It provides the following solvers: - Bregman projections for Wasserstein barycenter [3], convolutional barycenter [21] and unmixing [4]. - Optimal transport for domain adaptation with group lasso - regularization [5] + regularization and Laplacian regularization [5][30] - Conditional gradient [6] and Generalized conditional gradient for regularized OT [7]. - Linear OT [14] and Joint OT matrix and mapping estimation [8]. @@ -180,45 +182,45 @@ Examples and Notebooks The examples folder contain several examples and use case for the library. The full documentation is available on -`Readthedocs `__. +https://PythonOT.github.io/. Here is a list of the Python notebooks available -`here `__ if you +`here `__ if you want a quick look: - `1D optimal - transport `__ + transport `__ - `OT Ground - Loss `__ + Loss `__ - `Multiple EMD - computation `__ + computation `__ - `2D optimal transport on empirical - distributions `__ + distributions `__ - `1D Wasserstein - barycenter `__ + barycenter `__ - `OT with user provided - regularization `__ + regularization `__ - `Domain adaptation with optimal - transport `__ + transport `__ - `Color transfer in - images `__ + images `__ - `OT mapping estimation for domain - adaptation `__ + adaptation `__ - `OT mapping estimation for color transfer in - images `__ + images `__ - `Wasserstein Discriminant - Analysis `__ + Analysis `__ - `Gromov - Wasserstein `__ + Wasserstein `__ - `Gromov Wasserstein - Barycenter `__ + Barycenter `__ - `Fused Gromov - Wasserstein `__ + Wasserstein `__ - `Fused Gromov Wasserstein - Barycenter `__ + Barycenter `__ You can also see the notebooks with `Jupyter -nbviewer `__. +nbviewer `__. Acknowledgements ---------------- @@ -247,6 +249,7 @@ The contributors to this library are - `Hicham Janati `__ (Unbalanced OT) - `Romain Tavenard `__ (1d Wasserstein) - `Mokhtar Z. Alaya `__ (Screenkhorn) +- `Ievgen Redko `__ This toolbox benefit a lot from open source research and we would like to thank the following persons for providing some code (in various @@ -422,17 +425,23 @@ Gromov-Wasserstein with Applications on Positive-Unlabeled Learning `__, arXiv preprint arXiv:2002.08276. +[30] Flamary R., Courty N., Tuia D., Rakotomamonjy A. (2014). `Optimal +transport with Laplacian regularization: Applications to domain +adaptation and shape +matching `__, +NIPS Workshop on Optimal Transport and Machine Learning OTML, 2014. + .. |PyPI version| image:: https://badge.fury.io/py/POT.svg :target: https://badge.fury.io/py/POT .. |Anaconda Cloud| image:: https://anaconda.org/conda-forge/pot/badges/version.svg :target: https://anaconda.org/conda-forge/pot -.. |Build Status| image:: https://travis-ci.org/rflamary/POT.svg?branch=master - :target: https://travis-ci.org/rflamary/POT -.. |Documentation Status| image:: https://readthedocs.org/projects/pot/badge/?version=latest - :target: http://pot.readthedocs.io/en/latest/?badge=latest +.. |Build Status| image:: https://travis-ci.org/PythonOT/POT.svg?branch=master + :target: https://travis-ci.org/PythonOT/POT +.. |Codecov Status| image:: https://codecov.io/gh/PythonOT/POT/branch/master/graph/badge.svg + :target: https://codecov.io/gh/PythonOT/POT .. |Downloads| image:: https://pepy.tech/badge/pot :target: https://pepy.tech/project/pot .. |Anaconda downloads| image:: https://anaconda.org/conda-forge/pot/badges/downloads.svg :target: https://anaconda.org/conda-forge/pot .. |License| image:: https://anaconda.org/conda-forge/pot/badges/license.svg - :target: https://github.com/rflamary/POT/blob/master/LICENSE + :target: https://github.com/PythonOT/POT/blob/master/LICENSE diff --git a/examples/plot_fgw.py b/examples/plot_fgw.py index 43efc94..cfdc33b 100644 --- a/examples/plot_fgw.py +++ b/examples/plot_fgw.py @@ -60,14 +60,14 @@ pl.subplot(2, 1, 1) pl.scatter(ys, xs, c=phi, s=70) pl.ylabel('Feature value a', fontsize=20) -pl.title('$\mu=\sum_i \delta_{x_i,a_i}$', fontsize=25, usetex=True, y=1) +pl.title('$\mu=\sum_i \delta_{x_i,a_i}$', fontsize=25, y=1) pl.xticks(()) pl.yticks(()) pl.subplot(2, 1, 2) pl.scatter(yt, xt, c=phi2, s=70) pl.xlabel('coordinates x/y', fontsize=25) pl.ylabel('Feature value b', fontsize=20) -pl.title('$\\nu=\sum_j \delta_{y_j,b_j}$', fontsize=25, usetex=True, y=1) +pl.title('$\\nu=\sum_j \delta_{y_j,b_j}$', fontsize=25, y=1) pl.yticks(()) pl.tight_layout() pl.show() diff --git a/requirements.txt b/requirements.txt index c08822e..bee22f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,9 +2,9 @@ numpy scipy>=1.0 cython matplotlib -sphinx-gallery autograd pymanopt==0.2.4; python_version <'3' pymanopt; python_version >= '3' cvxopt +scikit-learn pytest \ No newline at end of file -- cgit v1.2.3