summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorKilian <kilian.fatras@gmail.com>2018-06-26 11:10:40 -0700
committerGitHub <noreply@github.com>2018-06-26 11:10:40 -0700
commitb4bc86176a5712fdd2f930fbf5d1968edd5efa5e (patch)
tree075c694496216f0a6db61e879ece5eb2e799fc07 /docs
parent208ff4627ba28aa3f35328c5928324019c23ddac (diff)
parent327b0c6e0ccb0c9453179eb316021c34bcdffec4 (diff)
Merge branch 'master' into stochastic_OT
Diffstat (limited to 'docs')
-rw-r--r--docs/cache_nbrun2
-rw-r--r--docs/source/all.rst5
-rw-r--r--docs/source/auto_examples/auto_examples_jupyter.zipbin86995 -> 99990 bytes
-rw-r--r--docs/source/auto_examples/auto_examples_python.zipbin58992 -> 68178 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_1D_001.pngbin21303 -> 21372 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_1D_002.pngbin21334 -> 22051 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_1D_005.pngbin16995 -> 17080 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_1D_007.pngbin18923 -> 19019 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.pngbin20832 -> 22281 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.pngbin20827 -> 20743 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.pngbin9613 -> 9695 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.pngbin82797 -> 90088 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_009.pngbin14508 -> 15036 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_010.pngbin95761 -> 103143 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_001.pngbin11710 -> 11773 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_002.pngbin17184 -> 17253 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.pngbin38780 -> 38849 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_007.pngbin14117 -> 14186 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_008.pngbin18696 -> 18765 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_011.pngbin21300 -> 21369 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_001.pngbin20512 -> 20581 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_002.pngbin41555 -> 41624 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_003.pngbin108687 -> 108756 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_barycenter_1D_004.pngbin105696 -> 105765 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.pngbin0 -> 20581 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.pngbin0 -> 46114 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_compute_emd_001.pngbin162612 -> 162681 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_compute_emd_003.pngbin29276 -> 29345 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_compute_emd_004.pngbin38748 -> 38817 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_gromov_001.pngbin45460 -> 44988 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_gromov_002.pngbin17362 -> 17066 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_gromov_003.pngbin18617 -> 18663 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.pngbin16995 -> 17080 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.pngbin18588 -> 19084 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_006.pngbin19258 -> 19317 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_008.pngbin20440 -> 20484 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_classes_001.pngbin50899 -> 50516 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_classes_003.pngbin197590 -> 207861 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_d2_001.pngbin130442 -> 134104 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_d2_003.pngbin216096 -> 231768 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_d2_006.pngbin102285 -> 107918 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.pngbin0 -> 29432 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.pngbin0 -> 53979 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_004.pngbin0 -> 591554 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_001.pngbin36766 -> 38663 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_003.pngbin75842 -> 76079 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_001.pngbin153695 -> 158896 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.pngbin37987 -> 36909 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_006.pngbin74267 -> 80769 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.pngbin14983 -> 14983 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.pngbin22134 -> 19155 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.pngbin9383 -> 9377 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.pngbin13541 -> 13542 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_lp_vs_entropic_thumb.pngbin0 -> 13542 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.pngbin80805 -> 76133 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.pngbin25219 -> 25604 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.pngbin30868 -> 23180 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.pngbin47553 -> 48206 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.pngbin0 -> 21399 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.pngbin18478 -> 15931 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.pngbin64710 -> 60596 bytes
-rw-r--r--docs/source/auto_examples/index.rst40
-rw-r--r--docs/source/auto_examples/plot_OT_1D.ipynb68
-rw-r--r--docs/source/auto_examples/plot_OT_1D.py2
-rw-r--r--docs/source/auto_examples/plot_OT_1D.rst4
-rw-r--r--docs/source/auto_examples/plot_OT_2D_samples.ipynb168
-rw-r--r--docs/source/auto_examples/plot_OT_2D_samples.py5
-rw-r--r--docs/source/auto_examples/plot_OT_2D_samples.rst18
-rw-r--r--docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb68
-rw-r--r--docs/source/auto_examples/plot_OT_L1_vs_L2.py2
-rw-r--r--docs/source/auto_examples/plot_OT_L1_vs_L2.rst4
-rw-r--r--docs/source/auto_examples/plot_barycenter_1D.ipynb36
-rw-r--r--docs/source/auto_examples/plot_barycenter_1D.py4
-rw-r--r--docs/source/auto_examples/plot_barycenter_1D.rst6
-rw-r--r--docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb108
-rw-r--r--docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py281
-rw-r--r--docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst447
-rw-r--r--docs/source/auto_examples/plot_compute_emd.ipynb168
-rw-r--r--docs/source/auto_examples/plot_compute_emd.py2
-rw-r--r--docs/source/auto_examples/plot_compute_emd.rst15
-rw-r--r--docs/source/auto_examples/plot_gromov.ipynb134
-rw-r--r--docs/source/auto_examples/plot_gromov.py2
-rw-r--r--docs/source/auto_examples/plot_gromov.rst38
-rw-r--r--docs/source/auto_examples/plot_optim_OTreg.ipynb76
-rw-r--r--docs/source/auto_examples/plot_optim_OTreg.py4
-rw-r--r--docs/source/auto_examples/plot_optim_OTreg.rst6
-rw-r--r--docs/source/auto_examples/plot_otda_classes.ipynb168
-rw-r--r--docs/source/auto_examples/plot_otda_classes.py6
-rw-r--r--docs/source/auto_examples/plot_otda_classes.rst61
-rw-r--r--docs/source/auto_examples/plot_otda_d2.ipynb76
-rw-r--r--docs/source/auto_examples/plot_otda_d2.py4
-rw-r--r--docs/source/auto_examples/plot_otda_d2.rst6
-rw-r--r--docs/source/auto_examples/plot_otda_linear_mapping.ipynb180
-rw-r--r--docs/source/auto_examples/plot_otda_linear_mapping.py144
-rw-r--r--docs/source/auto_examples/plot_otda_linear_mapping.rst260
-rw-r--r--docs/source/auto_examples/plot_otda_mapping.ipynb168
-rw-r--r--docs/source/auto_examples/plot_otda_mapping.py6
-rw-r--r--docs/source/auto_examples/plot_otda_mapping.rst55
-rw-r--r--docs/source/auto_examples/plot_otda_semi_supervised.ipynb192
-rw-r--r--docs/source/auto_examples/plot_otda_semi_supervised.py4
-rw-r--r--docs/source/auto_examples/plot_otda_semi_supervised.rst17
-rw-r--r--docs/source/conf.py2
-rw-r--r--docs/source/readme.rst46
103 files changed, 2307 insertions, 801 deletions
diff --git a/docs/cache_nbrun b/docs/cache_nbrun
index 9bf16ad..318bcf4 100644
--- a/docs/cache_nbrun
+++ b/docs/cache_nbrun
@@ -1 +1 @@
-{"plot_otda_mapping_colors_images.ipynb": "4f0587a00a3c082799a75a0ed36e9ce1", "plot_optim_OTreg.ipynb": "2ec33a099bb67120a134332a20f29313", "plot_otda_color_images.ipynb": "d047d635f4987c81072383241590e21f", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_OT_L1_vs_L2.ipynb": "871d60931f5118c085342e11cb638336", "plot_barycenter_1D.ipynb": "95708b025b6d96d97f579d30d268cbff", "plot_otda_classes.ipynb": "44bb8cd93317b5d342cd62e26d9bbe60", "plot_otda_d2.ipynb": "1a9547f07317612e1a161b7d9f07a5a8", "plot_otda_mapping.ipynb": "d335a15af828aaa3439a1c67570d79d6", "plot_gromov.ipynb": "825d79eba255314fe11469c64d38fc3d", "plot_compute_emd.ipynb": "bd95981189df6adcb113d9b360ead734", "plot_OT_1D.ipynb": "54dfea8ccb61f30729519275785c494c", "plot_gromov_barycenter.ipynb": "953e5047b886ec69ec621ec52f5e21d1", "plot_otda_semi_supervised.ipynb": "0261d339a692e339e15d3634488905cc", "plot_OT_2D_samples.ipynb": "3f125714daa35ff3cfe5dae1f71265c4"} \ No newline at end of file
+{"plot_otda_mapping_colors_images.ipynb": "4f0587a00a3c082799a75a0ed36e9ce1", "plot_optim_OTreg.ipynb": "481801bb0d133ef350a65179cf8f739a", "plot_otda_color_images.ipynb": "d047d635f4987c81072383241590e21f", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_otda_linear_mapping.ipynb": "a472c767abe82020e0a58125a528785c", "plot_OT_L1_vs_L2.ipynb": "5d565b8aaf03be4309eba731127851dc", "plot_barycenter_1D.ipynb": "6063193f9ac87517acced2625edb9a54", "plot_otda_classes.ipynb": "39087b6e98217851575f2271c22853a4", "plot_otda_d2.ipynb": "e6feae588103f2a8fab942e5f4eff483", "plot_otda_mapping.ipynb": "2f1ebbdc0f855d9e2b7adf9edec24d25", "plot_gromov.ipynb": "24f2aea489714d34779521f46d5e2c47", "plot_compute_emd.ipynb": "f5cd71cad882ec157dc8222721e9820c", "plot_OT_1D.ipynb": "b5348bdc561c07ec168a1622e5af4b93", "plot_gromov_barycenter.ipynb": "953e5047b886ec69ec621ec52f5e21d1", "plot_otda_semi_supervised.ipynb": "f6dfb02ba2bbd939408ffcd22a3b007c", "plot_OT_2D_samples.ipynb": "07dbc14859fa019a966caa79fa0825bd", "plot_barycenter_lp_vs_entropic.ipynb": "51833e8c76aaedeba9599ac7a30eb357"} \ No newline at end of file
diff --git a/docs/source/all.rst b/docs/source/all.rst
index 94da2ed..9459023 100644
--- a/docs/source/all.rst
+++ b/docs/source/all.rst
@@ -19,6 +19,11 @@ ot.bregman
.. automodule:: ot.bregman
:members:
+
+ot.smooth
+-----
+.. automodule:: ot.smooth
+ :members:
ot.smooth
-----
diff --git a/docs/source/auto_examples/auto_examples_jupyter.zip b/docs/source/auto_examples/auto_examples_jupyter.zip
index 4703026..8102274 100644
--- a/docs/source/auto_examples/auto_examples_jupyter.zip
+++ b/docs/source/auto_examples/auto_examples_jupyter.zip
Binary files differ
diff --git a/docs/source/auto_examples/auto_examples_python.zip b/docs/source/auto_examples/auto_examples_python.zip
index 7c7ff86..d685070 100644
--- a/docs/source/auto_examples/auto_examples_python.zip
+++ b/docs/source/auto_examples/auto_examples_python.zip
Binary files differ
diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_001.png
index e11f5b9..6e74d89 100644
--- 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
Binary files 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
index fcab0bd..0407e44 100644
--- 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
Binary files 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
index a75e649..4421bc7 100644
--- 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
Binary files 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
index 96b42cd..2dbe49b 100644
--- 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
Binary files 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
index 2ea9ead..2e93ed1 100644
--- 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
Binary files 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
index cb6f1a1..d6db0ed 100644
--- 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
Binary files 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
index 895ff65..9a215ab 100644
--- 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
Binary files 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
index a056401..81c4ddb 100644
--- 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
Binary files 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
index 285d474..892b2a2 100644
--- 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
Binary files 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
index 30ef388..c53717f 100644
--- 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
Binary files 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
index 6a21f35..3b1a29e 100644
--- 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
Binary files 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
index 79e4710..5a33824 100644
--- 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
Binary files 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
index 4860d96..1108375 100644
--- 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
Binary files 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
index 22dba2b..6e6f3b9 100644
--- 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
Binary files 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
index 5dbf96b..007d246 100644
--- 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
Binary files 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
index e1e9ba8..75ef929 100644
--- 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
Binary files 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
index 3454396..3500812 100644
--- 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
Binary files 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
index 3b23af5..d8db85e 100644
--- 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
Binary files 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
index eac9230..81cee52 100644
--- 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
Binary files 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
index 2e29ff9..bfa0873 100644
--- 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
Binary files 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
new file mode 100644
index 0000000..3500812
--- /dev/null
+++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png
Binary files 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
new file mode 100644
index 0000000..37fef68
--- /dev/null
+++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png
Binary files 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
index 9cf84c6..03e0b0e 100644
--- 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
Binary files 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
index 2da6ee7..077db3e 100644
--- 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
Binary files 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
index d74c34a..9ef7182 100644
--- 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
Binary files 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
index 8672249..2e9b38e 100644
--- a/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png
Binary files 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
index c4eb8e0..343fd78 100644
--- a/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png
Binary files 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
index c17d386..93e1def 100644
--- a/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png
Binary files 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
index a75e649..4421bc7 100644
--- 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
Binary files 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
index 7afdb53..bf7c076 100644
--- 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
Binary files 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
index 60078c1..afca192 100644
--- 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
Binary files 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
index 8a4882a..daa2a8d 100644
--- 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
Binary files 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
index 48fad93..71ef350 100644
--- 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
Binary files 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
index c92d5c1..3c33d5b 100644
--- 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
Binary files 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
index ff9c008..114871a 100644
--- 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
Binary files 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
index e4831ba..78ac59b 100644
--- 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
Binary files 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
index 81cbbd0..7385dcc 100644
--- 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
Binary files 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
new file mode 100644
index 0000000..88796df
--- /dev/null
+++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.png
Binary files 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
new file mode 100644
index 0000000..22b5d0c
--- /dev/null
+++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.png
Binary files 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
new file mode 100644
index 0000000..ff10b72
--- /dev/null
+++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_004.png
Binary files 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
index 8da464b..16a228a 100644
--- 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
Binary files 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
index fa93ee5..02fe3d6 100644
--- 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
Binary files 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
index 324aee3..9b5ae7a 100644
--- 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
Binary files 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
index 8ad6ca2..26ab6f6 100644
--- 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
Binary files 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
index b4eacb7..2b3bf0e 100644
--- 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
Binary files 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
index a44f37b..4679eb6 100644
--- 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
Binary files 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
index 22281f4..b9135dd 100644
--- 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
Binary files 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
index 4989860..cdf1208 100644
--- 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
Binary files 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
index 9bdd23b..c68e95f 100644
--- 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
Binary files 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
new file mode 100644
index 0000000..c68e95f
--- /dev/null
+++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_lp_vs_entropic_thumb.png
Binary files 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
index 68cbdf7..4531351 100644
--- 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
Binary files 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
index 210c010..6f250a4 100644
--- 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
Binary files 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
index 561c5bb..ec78552 100644
--- 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
Binary files 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
index 80b9a32..4f8f72f 100644
--- 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
Binary files 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
new file mode 100644
index 0000000..277950e
--- /dev/null
+++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png
Binary files 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
index 37d99bd..bd7c939 100644
--- 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
Binary files 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
index e1b5863..b683392 100644
--- 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
Binary files differ
diff --git a/docs/source/auto_examples/index.rst b/docs/source/auto_examples/index.rst
index 9d7c0f0..69fb320 100644
--- a/docs/source/auto_examples/index.rst
+++ b/docs/source/auto_examples/index.rst
@@ -109,6 +109,26 @@ This is a gallery of all the POT example files.
.. raw:: html
+ <div class="sphx-glr-thumbcontainer" tooltip=" ">
+
+.. 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
+
+ </div>
+
+
+.. toctree::
+ :hidden:
+
+ /auto_examples/plot_otda_linear_mapping
+
+.. raw:: html
+
<div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the use of WDA as proposed in [11].">
.. only:: html
@@ -289,6 +309,26 @@ This is a gallery of all the POT example files.
.. raw:: html
+ <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the computation of regularized Wasserstein Barycenter as proposed in [...">
+
+.. 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
+
+ </div>
+
+
+.. toctree::
+ :hidden:
+
+ /auto_examples/plot_barycenter_lp_vs_entropic
+
+.. raw:: html
+
<div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Gromov-Wasserstein distance computation in POT....">
.. only:: html
diff --git a/docs/source/auto_examples/plot_OT_1D.ipynb b/docs/source/auto_examples/plot_OT_1D.ipynb
index 649efa6..bd0439e 100644
--- a/docs/source/auto_examples/plot_OT_1D.ipynb
+++ b/docs/source/auto_examples/plot_OT_1D.ipynb
@@ -1,6 +1,7 @@
{
"cells": [
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -8,35 +9,35 @@
"outputs": [],
"source": [
"%matplotlib inline"
- ],
- "cell_type": "code"
+ ]
},
{
+ "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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
- "# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot\nfrom ot.datasets import get_1D_gauss as gauss"
- ],
- "cell_type": "code"
+ "# Author: Remi Flamary <remi.flamary@unice.fr>\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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -44,17 +45,17 @@
"outputs": [],
"source": [
"#%% parameters\n\nn = 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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Plot distributions and loss matrix\n----------------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -62,17 +63,17 @@
"outputs": [],
"source": [
"#%% plot the distributions\n\npl.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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Solve EMD\n---------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -80,17 +81,17 @@
"outputs": [],
"source": [
"#%% EMD\n\nG0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')"
- ],
- "cell_type": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Solve Sinkhorn\n--------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -98,29 +99,28 @@
"outputs": [],
"source": [
"#%% Sinkhorn\n\nlambd = 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()"
- ],
- "cell_type": "code"
+ ]
}
],
"metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"language_info": {
- "name": "python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
"nbconvert_exporter": "python",
- "version": "3.5.2",
"pygments_lexer": "ipython3",
- "file_extension": ".py",
- "mimetype": "text/x-python"
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3",
- "language": "python"
+ "version": "3.6.5"
}
},
- "nbformat_minor": 0,
- "nbformat": 4
+ "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
index 90325c9..f33e2a4 100644
--- a/docs/source/auto_examples/plot_OT_1D.py
+++ b/docs/source/auto_examples/plot_OT_1D.py
@@ -17,7 +17,7 @@ import numpy as np
import matplotlib.pylab as pl
import ot
import ot.plot
-from ot.datasets import get_1D_gauss as gauss
+from ot.datasets import make_1D_gauss as gauss
##############################################################################
# Generate data
diff --git a/docs/source/auto_examples/plot_OT_1D.rst b/docs/source/auto_examples/plot_OT_1D.rst
index 5e4f73e..b97d67c 100644
--- a/docs/source/auto_examples/plot_OT_1D.rst
+++ b/docs/source/auto_examples/plot_OT_1D.rst
@@ -24,7 +24,7 @@ and their visualization.
import matplotlib.pylab as pl
import ot
import ot.plot
- from ot.datasets import get_1D_gauss as gauss
+ from ot.datasets import make_1D_gauss as gauss
@@ -172,7 +172,7 @@ Solve Sinkhorn
110|1.527180e-10|
-**Total running time of the script:** ( 0 minutes 1.061 seconds)
+**Total running time of the script:** ( 0 minutes 0.561 seconds)
diff --git a/docs/source/auto_examples/plot_OT_2D_samples.ipynb b/docs/source/auto_examples/plot_OT_2D_samples.ipynb
index 41a37f3..26831f9 100644
--- a/docs/source/auto_examples/plot_OT_2D_samples.ipynb
+++ b/docs/source/auto_examples/plot_OT_2D_samples.ipynb
@@ -1,126 +1,126 @@
{
- "nbformat_minor": 0,
- "nbformat": 4,
"cells": [
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "%matplotlib inline"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "# Author: Remi Flamary <remi.flamary@unice.fr>\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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%% parameters and data generation\n\nn = 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.get_2D_samples_gauss(n, mu_s, cov_s)\nxt = ot.datasets.get_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()"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "#%% parameters and data generation\n\nn = 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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%% plot samples\n\npl.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')"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "#%% plot samples\n\npl.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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%% EMD\n\nG0 = 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')"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "#%% EMD\n\nG0 = 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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%% sinkhorn\n\n# 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()"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
+ },
+ "outputs": [],
+ "source": [
+ "#%% sinkhorn\n\n# 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()"
+ ]
}
- ],
+ ],
"metadata": {
"kernelspec": {
- "display_name": "Python 2",
- "name": "python2",
- "language": "python"
- },
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"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"
- }
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.5"
}
- }
+ },
+ "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
index 9818ec5..bb952a0 100644
--- a/docs/source/auto_examples/plot_OT_2D_samples.py
+++ b/docs/source/auto_examples/plot_OT_2D_samples.py
@@ -16,6 +16,7 @@ sum of diracs. The OT matrix is plotted with the samples.
import numpy as np
import matplotlib.pylab as pl
import ot
+import ot.plot
##############################################################################
# Generate data
@@ -31,8 +32,8 @@ 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.get_2D_samples_gauss(n, mu_s, cov_s)
-xt = ot.datasets.get_2D_samples_gauss(n, mu_t, cov_t)
+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
diff --git a/docs/source/auto_examples/plot_OT_2D_samples.rst b/docs/source/auto_examples/plot_OT_2D_samples.rst
index 5565c54..624ae3e 100644
--- a/docs/source/auto_examples/plot_OT_2D_samples.rst
+++ b/docs/source/auto_examples/plot_OT_2D_samples.rst
@@ -23,6 +23,7 @@ sum of diracs. The OT matrix is plotted with the samples.
import numpy as np
import matplotlib.pylab as pl
import ot
+ import ot.plot
@@ -48,8 +49,8 @@ Generate data
mu_t = np.array([4, 4])
cov_t = np.array([[1, -.8], [-.8, 1]])
- xs = ot.datasets.get_2D_samples_gauss(n, mu_s, cov_s)
- xt = ot.datasets.get_2D_samples_gauss(n, mu_t, cov_t)
+ 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
@@ -191,11 +192,13 @@ Compute Sinkhorn
-**Total running time of the script:** ( 0 minutes 3.380 seconds)
+**Total running time of the script:** ( 0 minutes 3.027 seconds)
-.. container:: sphx-glr-footer
+.. only :: html
+
+ .. container:: sphx-glr-footer
.. container:: sphx-glr-download
@@ -208,6 +211,9 @@ Compute Sinkhorn
:download:`Download Jupyter notebook: plot_OT_2D_samples.ipynb <plot_OT_2D_samples.ipynb>`
-.. rst-class:: sphx-glr-signature
- `Generated by Sphinx-Gallery <http://sphinx-gallery.readthedocs.io>`_
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
diff --git a/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb b/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb
index aea1b3d..125d720 100644
--- a/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb
+++ b/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb
@@ -1,6 +1,7 @@
{
"cells": [
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -8,17 +9,17 @@
"outputs": [],
"source": [
"%matplotlib inline"
- ],
- "cell_type": "code"
+ ]
},
{
+ "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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -26,35 +27,35 @@
"outputs": [],
"source": [
"# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot"
- ],
- "cell_type": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Dataset 1 : uniform sampling\n----------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "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 traget 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": "code"
+ "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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -62,17 +63,17 @@
"outputs": [],
"source": [
"#%% EMD\nG1 = 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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Dataset 2 : Partial circle\n--------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -80,17 +81,17 @@
"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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Dataset 2 : Plot OT Matrices\n-----------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -98,29 +99,28 @@
"outputs": [],
"source": [
"#%% EMD\nG1 = 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()"
- ],
- "cell_type": "code"
+ ]
}
],
"metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"language_info": {
- "name": "python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
"nbconvert_exporter": "python",
- "version": "3.5.2",
"pygments_lexer": "ipython3",
- "file_extension": ".py",
- "mimetype": "text/x-python"
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3",
- "language": "python"
+ "version": "3.6.5"
}
},
- "nbformat_minor": 0,
- "nbformat": 4
+ "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
index c1ed226..37b429f 100644
--- a/docs/source/auto_examples/plot_OT_L1_vs_L2.py
+++ b/docs/source/auto_examples/plot_OT_L1_vs_L2.py
@@ -53,7 +53,7 @@ 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')
+pl.title('Source and target distributions')
# Cost matrices
diff --git a/docs/source/auto_examples/plot_OT_L1_vs_L2.rst b/docs/source/auto_examples/plot_OT_L1_vs_L2.rst
index 01d6ac2..5db4b55 100644
--- a/docs/source/auto_examples/plot_OT_L1_vs_L2.rst
+++ b/docs/source/auto_examples/plot_OT_L1_vs_L2.rst
@@ -70,7 +70,7 @@ Dataset 1 : uniform sampling
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')
+ pl.title('Source and target distributions')
# Cost matrices
@@ -291,7 +291,7 @@ Dataset 2 : Plot OT Matrices
-**Total running time of the script:** ( 0 minutes 3.750 seconds)
+**Total running time of the script:** ( 0 minutes 0.958 seconds)
diff --git a/docs/source/auto_examples/plot_barycenter_1D.ipynb b/docs/source/auto_examples/plot_barycenter_1D.ipynb
index 01e759a..5866088 100644
--- a/docs/source/auto_examples/plot_barycenter_1D.ipynb
+++ b/docs/source/auto_examples/plot_barycenter_1D.ipynb
@@ -1,6 +1,7 @@
{
"cells": [
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -8,47 +9,46 @@
"outputs": [],
"source": [
"%matplotlib inline"
- ],
- "cell_type": "code"
+ ]
},
{
+ "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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
- "# Author: Remi Flamary <remi.flamary@unice.fr>\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\n\n#\n# Generate data\n# -------------\n\n#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na1 = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.get_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()\n\n#\n# Plot data\n# ---------\n\n#%% 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()\n\n#\n# Barycenter computation\n# ----------------------\n\n#%% barycenter computation\n\nalpha = 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()\n\n#\n# Barycentric interpolation\n# -------------------------\n\n#%% barycenter interpolation\n\nn_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)\n\n#%% plot interpolation\n\npl.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()"
- ],
- "cell_type": "code"
+ "# Author: Remi Flamary <remi.flamary@unice.fr>\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\n\n#\n# Generate data\n# -------------\n\n#%% 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# 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()\n\n#\n# Plot data\n# ---------\n\n#%% 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()\n\n#\n# Barycenter computation\n# ----------------------\n\n#%% barycenter computation\n\nalpha = 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()\n\n#\n# Barycentric interpolation\n# -------------------------\n\n#%% barycenter interpolation\n\nn_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)\n\n#%% plot interpolation\n\npl.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": {
- "name": "python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
"nbconvert_exporter": "python",
- "version": "3.5.2",
"pygments_lexer": "ipython3",
- "file_extension": ".py",
- "mimetype": "text/x-python"
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3",
- "language": "python"
+ "version": "3.6.5"
}
},
- "nbformat_minor": 0,
- "nbformat": 4
+ "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
index ecf640c..5ed9f3f 100644
--- a/docs/source/auto_examples/plot_barycenter_1D.py
+++ b/docs/source/auto_examples/plot_barycenter_1D.py
@@ -37,8 +37,8 @@ n = 100 # nb bins
x = np.arange(n, dtype=np.float64)
# Gaussian distributions
-a1 = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std
-a2 = ot.datasets.get_1D_gauss(n, m=60, s=8)
+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
diff --git a/docs/source/auto_examples/plot_barycenter_1D.rst b/docs/source/auto_examples/plot_barycenter_1D.rst
index 5b627ca..b314dc1 100644
--- a/docs/source/auto_examples/plot_barycenter_1D.rst
+++ b/docs/source/auto_examples/plot_barycenter_1D.rst
@@ -72,8 +72,8 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138.
x = np.arange(n, dtype=np.float64)
# Gaussian distributions
- a1 = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std
- a2 = ot.datasets.get_1D_gauss(n, m=60, s=8)
+ 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
@@ -194,7 +194,7 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138.
pl.show()
-**Total running time of the script:** ( 0 minutes 0.636 seconds)
+**Total running time of the script:** ( 0 minutes 0.363 seconds)
diff --git a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb
new file mode 100644
index 0000000..2199162
--- /dev/null
+++ b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb
@@ -0,0 +1,108 @@
+{
+ "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 <remi.flamary@unice.fr>\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": [
+ "#%% parameters\n\nproblems = []\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()\n\n\n#%% 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()\n\n#%% barycenter computation\n\nalpha = 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": [
+ "Dirac Data\n----------\n\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "#%% parameters\n\na1 = 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()\n\n\n#%% 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()\n\n\n#%% barycenter computation\n\nalpha = 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()\n\n#%% parameters\n\na1 = 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()\n\n\n#%% 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()\n\n\n#%% barycenter computation\n\nalpha = 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": [
+ "#%% plot\n\nnbm = 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.5"
+ }
+ },
+ "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
new file mode 100644
index 0000000..b82765e
--- /dev/null
+++ b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py
@@ -0,0 +1,281 @@
+# -*- 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 <remi.flamary@unice.fr>
+#
+# 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]])
+
+##############################################################################
+# Dirac 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()
+
+#%% 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
new file mode 100644
index 0000000..bd1c710
--- /dev/null
+++ b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst
@@ -0,0 +1,447 @@
+
+
+.. _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:: python
+
+
+ # Author: Remi Flamary <remi.flamary@unice.fr>
+ #
+ # 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:: python
+
+
+ #%% 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]])
+
+
+
+
+.. rst-class:: sphx-glr-horizontal
+
+
+ *
+
+ .. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png
+ :scale: 47
+
+ *
+
+ .. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png
+ :scale: 47
+
+
+.. rst-class:: sphx-glr-script-out
+
+ Out::
+
+ Elapsed time : 0.010712385177612305 s
+ Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective
+ 1.0 1.0 1.0 - 1.0 1700.336700337
+ 0.006776453137632 0.006776453137633 0.006776453137633 0.9932238647293 0.006776453137633 125.6700527543
+ 0.004018712867874 0.004018712867874 0.004018712867874 0.4301142633 0.004018712867874 12.26594150093
+ 0.001172775061627 0.001172775061627 0.001172775061627 0.7599932455029 0.001172775061627 0.3378536968897
+ 0.0004375137005385 0.0004375137005385 0.0004375137005385 0.6422331807989 0.0004375137005385 0.1468420566358
+ 0.000232669046734 0.0002326690467341 0.000232669046734 0.5016999460893 0.000232669046734 0.09381703231432
+ 7.430121674303e-05 7.430121674303e-05 7.430121674303e-05 0.7035962305812 7.430121674303e-05 0.0577787025717
+ 5.321227838876e-05 5.321227838875e-05 5.321227838876e-05 0.308784186441 5.321227838876e-05 0.05266249477203
+ 1.990900379199e-05 1.990900379196e-05 1.990900379199e-05 0.6520472013244 1.990900379199e-05 0.04526054405519
+ 6.305442046799e-06 6.30544204682e-06 6.3054420468e-06 0.7073953304075 6.305442046798e-06 0.04237597591383
+ 2.290148391577e-06 2.290148391582e-06 2.290148391578e-06 0.6941812711492 2.29014839159e-06 0.041522849321
+ 1.182864875387e-06 1.182864875406e-06 1.182864875427e-06 0.508455204675 1.182864875445e-06 0.04129461872827
+ 3.626786381529e-07 3.626786382468e-07 3.626786382923e-07 0.7101651572101 3.62678638267e-07 0.04113032448923
+ 1.539754244902e-07 1.539754249276e-07 1.539754249356e-07 0.6279322066282 1.539754253892e-07 0.04108867636379
+ 5.193221323143e-08 5.193221463044e-08 5.193221462729e-08 0.6843453436759 5.193221708199e-08 0.04106859618414
+ 1.888205054507e-08 1.888204779723e-08 1.88820477688e-08 0.6673444085651 1.888205650952e-08 0.041062141752
+ 5.676855206925e-09 5.676854518888e-09 5.676854517651e-09 0.7281705804232 5.676885442702e-09 0.04105958648713
+ 3.501157668218e-09 3.501150243546e-09 3.501150216347e-09 0.414020345194 3.501164437194e-09 0.04105916265261
+ 1.110594251499e-09 1.110590786827e-09 1.11059083379e-09 0.6998954759911 1.110636623476e-09 0.04105870073485
+ 5.770971626386e-10 5.772456113791e-10 5.772456200156e-10 0.4999769658132 5.77013379477e-10 0.04105859769135
+ 1.535218204536e-10 1.536993317032e-10 1.536992771966e-10 0.7516471627141 1.536205005991e-10 0.04105851679958
+ 6.724209350756e-11 6.739211232927e-11 6.739210470901e-11 0.5944802416166 6.735465384341e-11 0.04105850033766
+ 1.743382199199e-11 1.736445896691e-11 1.736448490761e-11 0.7573407808104 1.734254328931e-11 0.04105849088824
+ Optimization terminated successfully.
+ Elapsed time : 2.883899211883545 s
+
+
+Dirac Data
+----------
+
+
+
+.. code-block:: python
+
+
+ #%% 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()
+
+ #%% 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()
+
+
+
+
+
+.. rst-class:: sphx-glr-horizontal
+
+
+ *
+
+ .. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png
+ :scale: 47
+
+ *
+
+ .. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png
+ :scale: 47
+
+
+.. rst-class:: sphx-glr-script-out
+
+ Out::
+
+ Elapsed time : 0.014938592910766602 s
+ Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective
+ 1.0 1.0 1.0 - 1.0 1700.336700337
+ 0.006776466288966 0.006776466288966 0.006776466288966 0.9932238515788 0.006776466288966 125.6649255808
+ 0.004036918865495 0.004036918865495 0.004036918865495 0.4272973099316 0.004036918865495 12.3471617011
+ 0.00121923268707 0.00121923268707 0.00121923268707 0.749698685599 0.00121923268707 0.3243835647408
+ 0.0003837422984432 0.0003837422984432 0.0003837422984432 0.6926882608284 0.0003837422984432 0.1361719397493
+ 0.0001070128410183 0.0001070128410183 0.0001070128410183 0.7643889137854 0.0001070128410183 0.07581952832518
+ 0.0001001275033711 0.0001001275033711 0.0001001275033711 0.07058704837812 0.0001001275033712 0.0734739493635
+ 4.550897507844e-05 4.550897507841e-05 4.550897507844e-05 0.5761172484828 4.550897507845e-05 0.05555077655047
+ 8.557124125522e-06 8.5571241255e-06 8.557124125522e-06 0.8535925441152 8.557124125522e-06 0.04439814660221
+ 3.611995628407e-06 3.61199562841e-06 3.611995628414e-06 0.6002277331554 3.611995628415e-06 0.04283007762152
+ 7.590393750365e-07 7.590393750491e-07 7.590393750378e-07 0.8221486533416 7.590393750381e-07 0.04192322976248
+ 8.299929287441e-08 8.299929286079e-08 8.299929287532e-08 0.9017467938799 8.29992928758e-08 0.04170825633295
+ 3.117560203449e-10 3.117560130137e-10 3.11756019954e-10 0.997039969226 3.11756019952e-10 0.04168179329766
+ 1.559749653711e-14 1.558073160926e-14 1.559756940692e-14 0.9999499686183 1.559750643989e-14 0.04168169240444
+ Optimization terminated successfully.
+ Elapsed time : 2.642659902572632 s
+ Elapsed time : 0.002908945083618164 s
+ Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective
+ 1.0 1.0 1.0 - 1.0 1700.336700337
+ 0.006774675520727 0.006774675520727 0.006774675520727 0.9932256422636 0.006774675520727 125.6956034743
+ 0.002048208707562 0.002048208707562 0.002048208707562 0.7343095368143 0.002048208707562 5.213991622123
+ 0.000269736547478 0.0002697365474781 0.0002697365474781 0.8839403501193 0.000269736547478 0.505938390389
+ 6.832109993943e-05 6.832109993944e-05 6.832109993944e-05 0.7601171075965 6.832109993943e-05 0.2339657807272
+ 2.437682932219e-05 2.43768293222e-05 2.437682932219e-05 0.6663448297475 2.437682932219e-05 0.1471256246325
+ 1.13498321631e-05 1.134983216308e-05 1.13498321631e-05 0.5553643816404 1.13498321631e-05 0.1181584941171
+ 3.342312725885e-06 3.342312725884e-06 3.342312725885e-06 0.7238133571615 3.342312725885e-06 0.1006387519747
+ 7.078561231603e-07 7.078561231509e-07 7.078561231604e-07 0.8033142552512 7.078561231603e-07 0.09474734646269
+ 1.966870956916e-07 1.966870954537e-07 1.966870954468e-07 0.752547917788 1.966870954633e-07 0.09354342735766
+ 4.19989524849e-10 4.199895164852e-10 4.199895238758e-10 0.9984019849375 4.19989523951e-10 0.09310367785861
+ 2.101015938666e-14 2.100625691113e-14 2.101023853438e-14 0.999949974425 2.101023691864e-14 0.09310274466458
+ Optimization terminated successfully.
+ Elapsed time : 2.690450668334961 s
+
+
+Final figure
+------------
+
+
+
+
+.. code-block:: python
+
+
+ #%% 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(())
+
+
+
+.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png
+ :align: center
+
+
+
+
+**Total running time of the script:** ( 0 minutes 8.892 seconds)
+
+
+
+.. only :: html
+
+ .. container:: sphx-glr-footer
+
+
+ .. container:: sphx-glr-download
+
+ :download:`Download Python source code: plot_barycenter_lp_vs_entropic.py <plot_barycenter_lp_vs_entropic.py>`
+
+
+
+ .. container:: sphx-glr-download
+
+ :download:`Download Jupyter notebook: plot_barycenter_lp_vs_entropic.ipynb <plot_barycenter_lp_vs_entropic.ipynb>`
+
+
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
diff --git a/docs/source/auto_examples/plot_compute_emd.ipynb b/docs/source/auto_examples/plot_compute_emd.ipynb
index b9b8bc5..562eff8 100644
--- a/docs/source/auto_examples/plot_compute_emd.ipynb
+++ b/docs/source/auto_examples/plot_compute_emd.ipynb
@@ -1,126 +1,126 @@
{
- "nbformat_minor": 0,
- "nbformat": 4,
"cells": [
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "%matplotlib inline"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nfrom ot.datasets import get_1D_gauss as gauss"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "# Author: Remi Flamary <remi.flamary@unice.fr>\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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%% parameters\n\nn = 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()"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "#%% parameters\n\nn = 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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%% plot the distributions\n\npl.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()"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "#%% plot the distributions\n\npl.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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%% Compute and plot distributions and loss matrix\n\nd_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()"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "#%% Compute and plot distributions and loss matrix\n\nd_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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "#%%\nreg = 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()"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
+ },
+ "outputs": [],
+ "source": [
+ "#%%\nreg = 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 2",
- "name": "python2",
- "language": "python"
- },
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"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"
- }
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.5"
}
- }
+ },
+ "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
index 73b42c3..7ed2b01 100644
--- a/docs/source/auto_examples/plot_compute_emd.py
+++ b/docs/source/auto_examples/plot_compute_emd.py
@@ -17,7 +17,7 @@ ground metrics and plot their values for diffeent distributions.
import numpy as np
import matplotlib.pylab as pl
import ot
-from ot.datasets import get_1D_gauss as gauss
+from ot.datasets import make_1D_gauss as gauss
##############################################################################
diff --git a/docs/source/auto_examples/plot_compute_emd.rst b/docs/source/auto_examples/plot_compute_emd.rst
index cdbc620..27bca2c 100644
--- a/docs/source/auto_examples/plot_compute_emd.rst
+++ b/docs/source/auto_examples/plot_compute_emd.rst
@@ -24,7 +24,7 @@ ground metrics and plot their values for diffeent distributions.
import numpy as np
import matplotlib.pylab as pl
import ot
- from ot.datasets import get_1D_gauss as gauss
+ from ot.datasets import make_1D_gauss as gauss
@@ -162,11 +162,13 @@ Compute Sinkhorn for the different losses
-**Total running time of the script:** ( 0 minutes 0.697 seconds)
+**Total running time of the script:** ( 0 minutes 0.446 seconds)
-.. container:: sphx-glr-footer
+.. only :: html
+
+ .. container:: sphx-glr-footer
.. container:: sphx-glr-download
@@ -179,6 +181,9 @@ Compute Sinkhorn for the different losses
:download:`Download Jupyter notebook: plot_compute_emd.ipynb <plot_compute_emd.ipynb>`
-.. rst-class:: sphx-glr-signature
- `Generated by Sphinx-Gallery <http://sphinx-gallery.readthedocs.io>`_
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
diff --git a/docs/source/auto_examples/plot_gromov.ipynb b/docs/source/auto_examples/plot_gromov.ipynb
index 57d6a4a..dc1f179 100644
--- a/docs/source/auto_examples/plot_gromov.ipynb
+++ b/docs/source/auto_examples/plot_gromov.ipynb
@@ -1,126 +1,126 @@
{
- "nbformat_minor": 0,
- "nbformat": 4,
- "metadata": {
- "language_info": {
- "file_extension": ".py",
- "codemirror_mode": {
- "version": 3,
- "name": "ipython"
- },
- "nbconvert_exporter": "python",
- "mimetype": "text/x-python",
- "version": "3.5.2",
- "name": "python",
- "pygments_lexer": "ipython3"
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3",
- "language": "python"
- }
- },
"cells": [
{
- "outputs": [],
- "source": [
- "%matplotlib inline"
- ],
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
- "cell_type": "code"
+ "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"
- ],
- "metadata": {},
- "cell_type": "markdown"
+ ]
},
{
- "outputs": [],
- "source": [
- "# Author: Erwan Vautier <erwan.vautier@gmail.com>\n# Nicolas Courty <ncourty@irisa.fr>\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": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
- "cell_type": "code"
+ "outputs": [],
+ "source": [
+ "# Author: Erwan Vautier <erwan.vautier@gmail.com>\n# Nicolas Courty <ncourty@irisa.fr>\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"
- ],
- "metadata": {},
- "cell_type": "markdown"
+ ]
},
{
- "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.get_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": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
- "cell_type": "code"
+ "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"
- ],
- "metadata": {},
- "cell_type": "markdown"
+ ]
},
{
- "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": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
- "cell_type": "code"
+ "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"
- ],
- "metadata": {},
- "cell_type": "markdown"
+ ]
},
{
- "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": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
- "cell_type": "code"
+ "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"
- ],
- "metadata": {},
- "cell_type": "markdown"
+ ]
},
{
- "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()"
- ],
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
- "cell_type": "code"
+ "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.5"
}
- ]
+ },
+ "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
index 5cd40f6..deb2f86 100644
--- a/docs/source/auto_examples/plot_gromov.py
+++ b/docs/source/auto_examples/plot_gromov.py
@@ -38,7 +38,7 @@ mu_t = np.array([4, 4, 4])
cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
-xs = ot.datasets.get_2D_samples_gauss(n_samples, mu_s, cov_s)
+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
diff --git a/docs/source/auto_examples/plot_gromov.rst b/docs/source/auto_examples/plot_gromov.rst
index 131861f..3ed4e11 100644
--- a/docs/source/auto_examples/plot_gromov.rst
+++ b/docs/source/auto_examples/plot_gromov.rst
@@ -54,7 +54,7 @@ two Gaussian distributions in 2- and 3-dimensional spaces.
cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
- xs = ot.datasets.get_2D_samples_gauss(n_samples, mu_s, cov_s)
+ 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
@@ -166,28 +166,28 @@ Compute Gromov-Wasserstein plans and distance
It. |Loss |Delta loss
--------------------------------
- 0|4.517558e-02|0.000000e+00
- 1|2.563483e-02|-7.622736e-01
- 2|2.443903e-02|-4.892972e-02
- 3|2.231600e-02|-9.513496e-02
- 4|1.676188e-02|-3.313541e-01
- 5|1.464792e-02|-1.443180e-01
- 6|1.454315e-02|-7.204526e-03
- 7|1.454142e-02|-1.185811e-04
- 8|1.454141e-02|-1.190466e-06
- 9|1.454141e-02|-1.190512e-08
- 10|1.454141e-02|-1.190520e-10
+ 0|4.328711e-02|0.000000e+00
+ 1|2.281369e-02|-8.974178e-01
+ 2|1.843659e-02|-2.374139e-01
+ 3|1.602820e-02|-1.502598e-01
+ 4|1.353712e-02|-1.840179e-01
+ 5|1.285687e-02|-5.290977e-02
+ 6|1.284537e-02|-8.952931e-04
+ 7|1.284525e-02|-8.989584e-06
+ 8|1.284525e-02|-8.989950e-08
+ 9|1.284525e-02|-8.989949e-10
It. |Err
-------------------
- 0|6.743761e-02|
- 10|5.477003e-04|
- 20|2.461503e-08|
- 30|1.205155e-11|
- Gromov-Wasserstein distances: 0.014541405718693563
- Entropic Gromov-Wasserstein distances: 0.015800739725237274
+ 0|7.263293e-02|
+ 10|1.737784e-02|
+ 20|7.783978e-03|
+ 30|3.399419e-07|
+ 40|3.751207e-11|
+ Gromov-Wasserstein distances: 0.012845252089244688
+ Entropic Gromov-Wasserstein distances: 0.013543882352191079
-**Total running time of the script:** ( 0 minutes 1.448 seconds)
+**Total running time of the script:** ( 0 minutes 1.916 seconds)
diff --git a/docs/source/auto_examples/plot_optim_OTreg.ipynb b/docs/source/auto_examples/plot_optim_OTreg.ipynb
index 02bf175..107c299 100644
--- a/docs/source/auto_examples/plot_optim_OTreg.ipynb
+++ b/docs/source/auto_examples/plot_optim_OTreg.ipynb
@@ -1,6 +1,7 @@
{
"cells": [
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -8,17 +9,17 @@
"outputs": [],
"source": [
"%matplotlib inline"
- ],
- "cell_type": "code"
+ ]
},
{
+ "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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -26,35 +27,35 @@
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot"
- ],
- "cell_type": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Generate data\n-------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "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\na = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std\nb = ot.datasets.get_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": "code"
+ "#%% parameters\n\nn = 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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -62,17 +63,17 @@
"outputs": [],
"source": [
"#%% EMD\n\nG0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')"
- ],
- "cell_type": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Solve EMD with Frobenius norm regularization\n--------------------------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -80,17 +81,17 @@
"outputs": [],
"source": [
"#%% Example with Frobenius norm regularization\n\n\ndef 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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Solve EMD with entropic regularization\n--------------------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -98,17 +99,17 @@
"outputs": [],
"source": [
"#%% Example with entropic regularization\n\n\ndef 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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Solve EMD with Frobenius norm + entropic regularization\n-------------------------------------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -116,29 +117,28 @@
"outputs": [],
"source": [
"#%% Example with Frobenius norm + entropic regularization with gcg\n\n\ndef 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()"
- ],
- "cell_type": "code"
+ ]
}
],
"metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"language_info": {
- "name": "python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
"nbconvert_exporter": "python",
- "version": "3.5.2",
"pygments_lexer": "ipython3",
- "file_extension": ".py",
- "mimetype": "text/x-python"
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3",
- "language": "python"
+ "version": "3.6.5"
}
},
- "nbformat_minor": 0,
- "nbformat": 4
+ "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
index 92df016..2c58def 100644
--- a/docs/source/auto_examples/plot_optim_OTreg.py
+++ b/docs/source/auto_examples/plot_optim_OTreg.py
@@ -42,8 +42,8 @@ n = 100 # nb bins
x = np.arange(n, dtype=np.float64)
# Gaussian distributions
-a = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std
-b = ot.datasets.get_1D_gauss(n, m=60, s=10)
+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)))
diff --git a/docs/source/auto_examples/plot_optim_OTreg.rst b/docs/source/auto_examples/plot_optim_OTreg.rst
index 5927428..844cba0 100644
--- a/docs/source/auto_examples/plot_optim_OTreg.rst
+++ b/docs/source/auto_examples/plot_optim_OTreg.rst
@@ -59,8 +59,8 @@ Generate data
x = np.arange(n, dtype=np.float64)
# Gaussian distributions
- a = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std
- b = ot.datasets.get_1D_gauss(n, m=60, s=10)
+ 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)))
@@ -636,7 +636,7 @@ Solve EMD with Frobenius norm + entropic regularization
4|1.609284e-01|-1.111407e-12
-**Total running time of the script:** ( 0 minutes 2.589 seconds)
+**Total running time of the script:** ( 0 minutes 1.990 seconds)
diff --git a/docs/source/auto_examples/plot_otda_classes.ipynb b/docs/source/auto_examples/plot_otda_classes.ipynb
index 6754fa5..643e760 100644
--- a/docs/source/auto_examples/plot_otda_classes.ipynb
+++ b/docs/source/auto_examples/plot_otda_classes.ipynb
@@ -1,126 +1,126 @@
{
- "nbformat_minor": 0,
- "nbformat": 4,
"cells": [
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "%matplotlib inline"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Stanislas Chambon <stan.chambon@gmail.com>\n#\n# License: MIT License\n\nimport matplotlib.pylab as pl\nimport ot"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Stanislas Chambon <stan.chambon@gmail.com>\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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "n_source_samples = 150\nn_target_samples = 150\n\nXs, ys = ot.datasets.get_data_classif('3gauss', n_source_samples)\nXt, yt = ot.datasets.get_data_classif('3gauss2', n_target_samples)"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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)"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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()"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "param_img = {'interpolation': 'nearest', 'cmap': 'spectral'}\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()"
- ],
- "outputs": [],
+ "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 2",
- "name": "python2",
- "language": "python"
- },
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"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"
- }
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.5"
}
- }
+ },
+ "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
index b14c11a..c311fbd 100644
--- a/docs/source/auto_examples/plot_otda_classes.py
+++ b/docs/source/auto_examples/plot_otda_classes.py
@@ -25,8 +25,8 @@ import ot
n_source_samples = 150
n_target_samples = 150
-Xs, ys = ot.datasets.get_data_classif('3gauss', n_source_samples)
-Xt, yt = ot.datasets.get_data_classif('3gauss2', n_target_samples)
+Xs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples)
+Xt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples)
##############################################################################
@@ -82,7 +82,7 @@ pl.tight_layout()
# Fig 2 : plot optimal couplings and transported samples
# ------------------------------------------------------
-param_img = {'interpolation': 'nearest', 'cmap': 'spectral'}
+param_img = {'interpolation': 'nearest'}
pl.figure(2, figsize=(15, 8))
pl.subplot(2, 4, 1)
diff --git a/docs/source/auto_examples/plot_otda_classes.rst b/docs/source/auto_examples/plot_otda_classes.rst
index a5ab285..19756ff 100644
--- a/docs/source/auto_examples/plot_otda_classes.rst
+++ b/docs/source/auto_examples/plot_otda_classes.rst
@@ -42,8 +42,8 @@ Generate data
n_source_samples = 150
n_target_samples = 150
- Xs, ys = ot.datasets.get_data_classif('3gauss', n_source_samples)
- Xt, yt = ot.datasets.get_data_classif('3gauss2', n_target_samples)
+ Xs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples)
+ Xt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples)
@@ -94,29 +94,29 @@ Instantiate the different transport algorithms and fit them
It. |Loss |Delta loss
--------------------------------
- 0|1.003747e+01|0.000000e+00
- 1|1.953263e+00|-4.138821e+00
- 2|1.744456e+00|-1.196969e-01
- 3|1.689268e+00|-3.267022e-02
- 4|1.666355e+00|-1.374998e-02
- 5|1.656125e+00|-6.177356e-03
- 6|1.651753e+00|-2.646960e-03
- 7|1.647261e+00|-2.726957e-03
- 8|1.642274e+00|-3.036672e-03
- 9|1.639926e+00|-1.431818e-03
- 10|1.638750e+00|-7.173837e-04
- 11|1.637558e+00|-7.281753e-04
- 12|1.636248e+00|-8.002067e-04
- 13|1.634555e+00|-1.036074e-03
- 14|1.633547e+00|-6.166646e-04
- 15|1.633531e+00|-1.022614e-05
- 16|1.632957e+00|-3.510986e-04
- 17|1.632853e+00|-6.380944e-05
- 18|1.632704e+00|-9.122988e-05
- 19|1.632237e+00|-2.861276e-04
+ 0|9.566309e+00|0.000000e+00
+ 1|2.169680e+00|-3.409088e+00
+ 2|1.914989e+00|-1.329986e-01
+ 3|1.860251e+00|-2.942498e-02
+ 4|1.838073e+00|-1.206621e-02
+ 5|1.827064e+00|-6.025122e-03
+ 6|1.820899e+00|-3.386082e-03
+ 7|1.817290e+00|-1.985705e-03
+ 8|1.814644e+00|-1.458223e-03
+ 9|1.812661e+00|-1.093816e-03
+ 10|1.810239e+00|-1.338121e-03
+ 11|1.809100e+00|-6.296940e-04
+ 12|1.807939e+00|-6.420646e-04
+ 13|1.806965e+00|-5.389118e-04
+ 14|1.806822e+00|-7.889599e-05
+ 15|1.806193e+00|-3.482356e-04
+ 16|1.805735e+00|-2.536930e-04
+ 17|1.805321e+00|-2.292667e-04
+ 18|1.804389e+00|-5.170222e-04
+ 19|1.803908e+00|-2.661907e-04
It. |Loss |Delta loss
--------------------------------
- 20|1.632174e+00|-3.896483e-05
+ 20|1.803696e+00|-1.178279e-04
Fig 1 : plots source and target samples
@@ -161,7 +161,7 @@ Fig 2 : plot optimal couplings and transported samples
.. code-block:: python
- param_img = {'interpolation': 'nearest', 'cmap': 'spectral'}
+ param_img = {'interpolation': 'nearest'}
pl.figure(2, figsize=(15, 8))
pl.subplot(2, 4, 1)
@@ -236,11 +236,13 @@ Fig 2 : plot optimal couplings and transported samples
-**Total running time of the script:** ( 0 minutes 2.308 seconds)
+**Total running time of the script:** ( 0 minutes 1.423 seconds)
-.. container:: sphx-glr-footer
+.. only :: html
+
+ .. container:: sphx-glr-footer
.. container:: sphx-glr-download
@@ -253,6 +255,9 @@ Fig 2 : plot optimal couplings and transported samples
:download:`Download Jupyter notebook: plot_otda_classes.ipynb <plot_otda_classes.ipynb>`
-.. rst-class:: sphx-glr-signature
- `Generated by Sphinx-Gallery <http://sphinx-gallery.readthedocs.io>`_
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
diff --git a/docs/source/auto_examples/plot_otda_d2.ipynb b/docs/source/auto_examples/plot_otda_d2.ipynb
index 9c58e64..b9002ee 100644
--- a/docs/source/auto_examples/plot_otda_d2.ipynb
+++ b/docs/source/auto_examples/plot_otda_d2.ipynb
@@ -1,6 +1,7 @@
{
"cells": [
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -8,17 +9,17 @@
"outputs": [],
"source": [
"%matplotlib inline"
- ],
- "cell_type": "code"
+ ]
},
{
+ "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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -26,35 +27,35 @@
"outputs": [],
"source": [
"# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Stanislas Chambon <stan.chambon@gmail.com>\n#\n# License: MIT License\n\nimport matplotlib.pylab as pl\nimport ot\nimport ot.plot"
- ],
- "cell_type": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"generate data\n-------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
- "n_samples_source = 150\nn_samples_target = 150\n\nXs, ys = ot.datasets.get_data_classif('3gauss', n_samples_source)\nXt, yt = ot.datasets.get_data_classif('3gauss2', n_samples_target)\n\n# Cost matrix\nM = ot.dist(Xs, Xt, metric='sqeuclidean')"
- ],
- "cell_type": "code"
+ "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": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -62,17 +63,17 @@
"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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Fig 1 : plots source and target samples + matrix of pairwise distance\n---------------------------------------------------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -80,17 +81,17 @@
"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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Fig 2 : plots optimal couplings for the different methods\n---------------------------------------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -98,17 +99,17 @@
"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": "code"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Fig 3 : plot transported samples\n--------------------------------\n\n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
@@ -116,29 +117,28 @@
"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()"
- ],
- "cell_type": "code"
+ ]
}
],
"metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"language_info": {
- "name": "python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
"nbconvert_exporter": "python",
- "version": "3.5.2",
"pygments_lexer": "ipython3",
- "file_extension": ".py",
- "mimetype": "text/x-python"
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3",
- "language": "python"
+ "version": "3.6.5"
}
},
- "nbformat_minor": 0,
- "nbformat": 4
+ "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
index 70beb35..cf22c2f 100644
--- a/docs/source/auto_examples/plot_otda_d2.py
+++ b/docs/source/auto_examples/plot_otda_d2.py
@@ -29,8 +29,8 @@ import ot.plot
n_samples_source = 150
n_samples_target = 150
-Xs, ys = ot.datasets.get_data_classif('3gauss', n_samples_source)
-Xt, yt = ot.datasets.get_data_classif('3gauss2', n_samples_target)
+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')
diff --git a/docs/source/auto_examples/plot_otda_d2.rst b/docs/source/auto_examples/plot_otda_d2.rst
index e5a60c4..80cc34c 100644
--- a/docs/source/auto_examples/plot_otda_d2.rst
+++ b/docs/source/auto_examples/plot_otda_d2.rst
@@ -46,8 +46,8 @@ generate data
n_samples_source = 150
n_samples_target = 150
- Xs, ys = ot.datasets.get_data_classif('3gauss', n_samples_source)
- Xt, yt = ot.datasets.get_data_classif('3gauss2', n_samples_target)
+ 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')
@@ -242,7 +242,7 @@ Fig 3 : plot transported samples
-**Total running time of the script:** ( 0 minutes 39.829 seconds)
+**Total running time of the script:** ( 0 minutes 35.515 seconds)
diff --git a/docs/source/auto_examples/plot_otda_linear_mapping.ipynb b/docs/source/auto_examples/plot_otda_linear_mapping.ipynb
new file mode 100644
index 0000000..027b6cb
--- /dev/null
+++ b/docs/source/auto_examples/plot_otda_linear_mapping.ipynb
@@ -0,0 +1,180 @@
+{
+ "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 <remi.flamary@unice.fr>\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))\n\n# %%"
+ ]
+ },
+ {
+ "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.5"
+ }
+ },
+ "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
new file mode 100644
index 0000000..c65bd4f
--- /dev/null
+++ b/docs/source/auto_examples/plot_otda_linear_mapping.py
@@ -0,0 +1,144 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+============================
+Linear OT mapping estimation
+============================
+
+
+"""
+
+# Author: Remi Flamary <remi.flamary@unice.fr>
+#
+# 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
new file mode 100644
index 0000000..8e2e0cf
--- /dev/null
+++ b/docs/source/auto_examples/plot_otda_linear_mapping.rst
@@ -0,0 +1,260 @@
+
+
+.. _sphx_glr_auto_examples_plot_otda_linear_mapping.py:
+
+
+============================
+Linear OT mapping estimation
+============================
+
+
+
+
+
+.. code-block:: python
+
+
+ # Author: Remi Flamary <remi.flamary@unice.fr>
+ #
+ # License: MIT License
+
+ import numpy as np
+ import pylab as pl
+ import ot
+
+
+
+
+
+
+
+Generate data
+-------------
+
+
+
+.. code-block:: python
+
+
+ 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:: python
+
+
+ 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
+ :align: center
+
+
+
+
+Estimate linear mapping and transport
+-------------------------------------
+
+
+
+.. code-block:: python
+
+
+ Ae, be = ot.da.OT_mapping_linear(xs, xt)
+
+ xst = xs.dot(Ae) + be
+
+
+
+
+
+
+
+
+Plot transported samples
+------------------------
+
+
+
+.. code-block:: python
+
+
+ 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
+ :align: center
+
+
+
+
+Load image data
+---------------
+
+
+
+.. code-block:: python
+
+
+
+ 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:: python
+
+
+ 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:: python
+
+
+ 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_004.png
+ :align: center
+
+
+
+
+**Total running time of the script:** ( 0 minutes 0.635 seconds)
+
+
+
+.. only :: html
+
+ .. container:: sphx-glr-footer
+
+
+ .. container:: sphx-glr-download
+
+ :download:`Download Python source code: plot_otda_linear_mapping.py <plot_otda_linear_mapping.py>`
+
+
+
+ .. container:: sphx-glr-download
+
+ :download:`Download Jupyter notebook: plot_otda_linear_mapping.ipynb <plot_otda_linear_mapping.ipynb>`
+
+
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
diff --git a/docs/source/auto_examples/plot_otda_mapping.ipynb b/docs/source/auto_examples/plot_otda_mapping.ipynb
index 0374146..898466d 100644
--- a/docs/source/auto_examples/plot_otda_mapping.ipynb
+++ b/docs/source/auto_examples/plot_otda_mapping.ipynb
@@ -1,126 +1,126 @@
{
- "nbformat_minor": 0,
- "nbformat": 4,
"cells": [
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "%matplotlib inline"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Stanislas Chambon <stan.chambon@gmail.com>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Stanislas Chambon <stan.chambon@gmail.com>\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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "n_source_samples = 100\nn_target_samples = 100\ntheta = 2 * np.pi / 20\nnoise_level = 0.1\n\nXs, ys = ot.datasets.get_data_classif(\n 'gaussrot', n_source_samples, nz=noise_level)\nXs_new, _ = ot.datasets.get_data_classif(\n 'gaussrot', n_source_samples, nz=noise_level)\nXt, yt = ot.datasets.get_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"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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')"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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)"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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()"
- ],
- "outputs": [],
+ "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 2",
- "name": "python2",
- "language": "python"
- },
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"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"
- }
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.5"
}
- }
+ },
+ "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
index 167c3a1..5880adf 100644
--- a/docs/source/auto_examples/plot_otda_mapping.py
+++ b/docs/source/auto_examples/plot_otda_mapping.py
@@ -32,11 +32,11 @@ n_target_samples = 100
theta = 2 * np.pi / 20
noise_level = 0.1
-Xs, ys = ot.datasets.get_data_classif(
+Xs, ys = ot.datasets.make_data_classif(
'gaussrot', n_source_samples, nz=noise_level)
-Xs_new, _ = ot.datasets.get_data_classif(
+Xs_new, _ = ot.datasets.make_data_classif(
'gaussrot', n_source_samples, nz=noise_level)
-Xt, yt = ot.datasets.get_data_classif(
+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)
diff --git a/docs/source/auto_examples/plot_otda_mapping.rst b/docs/source/auto_examples/plot_otda_mapping.rst
index 1e3a709..1d95fc6 100644
--- a/docs/source/auto_examples/plot_otda_mapping.rst
+++ b/docs/source/auto_examples/plot_otda_mapping.rst
@@ -49,11 +49,11 @@ Generate data
theta = 2 * np.pi / 20
noise_level = 0.1
- Xs, ys = ot.datasets.get_data_classif(
+ Xs, ys = ot.datasets.make_data_classif(
'gaussrot', n_source_samples, nz=noise_level)
- Xs_new, _ = ot.datasets.get_data_classif(
+ Xs_new, _ = ot.datasets.make_data_classif(
'gaussrot', n_source_samples, nz=noise_level)
- Xt, yt = ot.datasets.get_data_classif(
+ 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)
@@ -136,26 +136,26 @@ Instantiate the different transport algorithms and fit them
It. |Loss |Delta loss
--------------------------------
- 0|4.231423e+03|0.000000e+00
- 1|4.217955e+03|-3.182835e-03
- 2|4.217580e+03|-8.885864e-05
- 3|4.217451e+03|-3.043162e-05
- 4|4.217368e+03|-1.978325e-05
- 5|4.217312e+03|-1.338471e-05
- 6|4.217307e+03|-1.000290e-06
+ 0|4.299275e+03|0.000000e+00
+ 1|4.290443e+03|-2.054271e-03
+ 2|4.290040e+03|-9.389994e-05
+ 3|4.289876e+03|-3.830707e-05
+ 4|4.289783e+03|-2.157428e-05
+ 5|4.289724e+03|-1.390941e-05
+ 6|4.289706e+03|-4.051054e-06
It. |Loss |Delta loss
--------------------------------
- 0|4.257004e+02|0.000000e+00
- 1|4.208978e+02|-1.128168e-02
- 2|4.205168e+02|-9.052112e-04
- 3|4.203566e+02|-3.810681e-04
- 4|4.202570e+02|-2.369884e-04
- 5|4.201844e+02|-1.726132e-04
- 6|4.201341e+02|-1.196461e-04
- 7|4.200941e+02|-9.525441e-05
- 8|4.200630e+02|-7.405552e-05
- 9|4.200377e+02|-6.031884e-05
- 10|4.200168e+02|-4.968324e-05
+ 0|4.326465e+02|0.000000e+00
+ 1|4.282533e+02|-1.015416e-02
+ 2|4.279473e+02|-7.145955e-04
+ 3|4.277941e+02|-3.580104e-04
+ 4|4.277069e+02|-2.039229e-04
+ 5|4.276462e+02|-1.418698e-04
+ 6|4.276011e+02|-1.054172e-04
+ 7|4.275663e+02|-8.145802e-05
+ 8|4.275405e+02|-6.028774e-05
+ 9|4.275191e+02|-5.005886e-05
+ 10|4.275019e+02|-4.021935e-05
Plot transported samples
@@ -208,11 +208,13 @@ Plot transported samples
-**Total running time of the script:** ( 0 minutes 0.970 seconds)
+**Total running time of the script:** ( 0 minutes 0.795 seconds)
-.. container:: sphx-glr-footer
+.. only :: html
+
+ .. container:: sphx-glr-footer
.. container:: sphx-glr-download
@@ -225,6 +227,9 @@ Plot transported samples
:download:`Download Jupyter notebook: plot_otda_mapping.ipynb <plot_otda_mapping.ipynb>`
-.. rst-class:: sphx-glr-signature
- `Generated by Sphinx-Gallery <http://sphinx-gallery.readthedocs.io>`_
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
diff --git a/docs/source/auto_examples/plot_otda_semi_supervised.ipynb b/docs/source/auto_examples/plot_otda_semi_supervised.ipynb
index 783bf84..e3192da 100644
--- a/docs/source/auto_examples/plot_otda_semi_supervised.ipynb
+++ b/docs/source/auto_examples/plot_otda_semi_supervised.ipynb
@@ -1,144 +1,144 @@
{
- "nbformat_minor": 0,
- "nbformat": 4,
"cells": [
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "%matplotlib inline"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Stanislas Chambon <stan.chambon@gmail.com>\n#\n# License: MIT License\n\nimport matplotlib.pylab as pl\nimport ot"
- ],
- "outputs": [],
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {
"collapsed": false
- }
- },
+ },
+ "outputs": [],
+ "source": [
+ "# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Stanislas Chambon <stan.chambon@gmail.com>\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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "source": [
- "n_samples_source = 150\nn_samples_target = 150\n\nXs, ys = ot.datasets.get_data_classif('3gauss', n_samples_source)\nXt, yt = ot.datasets.get_data_classif('3gauss2', n_samples_target)"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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)"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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()"
- ],
- "outputs": [],
+ "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": "markdown",
- "metadata": {}
- },
+ ]
+ },
{
- "execution_count": null,
- "cell_type": "code",
- "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()"
- ],
- "outputs": [],
+ "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 2",
- "name": "python2",
- "language": "python"
- },
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
"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"
- }
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.5"
}
- }
+ },
+ "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
index 7963aef..8a67720 100644
--- a/docs/source/auto_examples/plot_otda_semi_supervised.py
+++ b/docs/source/auto_examples/plot_otda_semi_supervised.py
@@ -29,8 +29,8 @@ import ot
n_samples_source = 150
n_samples_target = 150
-Xs, ys = ot.datasets.get_data_classif('3gauss', n_samples_source)
-Xt, yt = ot.datasets.get_data_classif('3gauss2', n_samples_target)
+Xs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source)
+Xt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target)
##############################################################################
diff --git a/docs/source/auto_examples/plot_otda_semi_supervised.rst b/docs/source/auto_examples/plot_otda_semi_supervised.rst
index dc05ed0..2ed7819 100644
--- a/docs/source/auto_examples/plot_otda_semi_supervised.rst
+++ b/docs/source/auto_examples/plot_otda_semi_supervised.rst
@@ -46,8 +46,8 @@ Generate data
n_samples_source = 150
n_samples_target = 150
- Xs, ys = ot.datasets.get_data_classif('3gauss', n_samples_source)
- Xt, yt = ot.datasets.get_data_classif('3gauss2', n_samples_target)
+ Xs, ys = ot.datasets.make_data_classif('3gauss', n_samples_source)
+ Xt, yt = ot.datasets.make_data_classif('3gauss2', n_samples_target)
@@ -218,11 +218,13 @@ Fig 3 : plot transported samples
-**Total running time of the script:** ( 0 minutes 0.714 seconds)
+**Total running time of the script:** ( 0 minutes 0.256 seconds)
-.. container:: sphx-glr-footer
+.. only :: html
+
+ .. container:: sphx-glr-footer
.. container:: sphx-glr-download
@@ -235,6 +237,9 @@ Fig 3 : plot transported samples
:download:`Download Jupyter notebook: plot_otda_semi_supervised.ipynb <plot_otda_semi_supervised.ipynb>`
-.. rst-class:: sphx-glr-signature
- `Generated by Sphinx-Gallery <http://sphinx-gallery.readthedocs.io>`_
+.. only:: html
+
+ .. rst-class:: sphx-glr-signature
+
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 4105d87..114245d 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -81,7 +81,7 @@ master_doc = 'index'
# General information about the project.
project = u'POT Python Optimal Transport'
-copyright = u'2016, Rémi Flamary, Nicolas Courty'
+copyright = u'2016-2018, Rémi Flamary, Nicolas Courty'
author = u'Rémi Flamary, Nicolas Courty'
# The version info for the project you're documenting, acts as replacement for
diff --git a/docs/source/readme.rst b/docs/source/readme.rst
index 725c207..5d37f64 100644
--- a/docs/source/readme.rst
+++ b/docs/source/readme.rst
@@ -14,7 +14,11 @@ It provides the following solvers:
[1].
- Entropic regularization OT solver with Sinkhorn Knopp Algorithm [2]
and stabilized version [9][10] with optional GPU implementation
- (required cudamat).
+ (requires cudamat).
+- Smooth optimal transport solvers (dual and semi-dual) for KL and
+ squared L2 regularizations [17].
+- Non regularized Wasserstein barycenters [16] with LP solver (only
+ small scale).
- Bregman projections for Wasserstein barycenter [3] and unmixing [4].
- Optimal transport for domain adaptation with group lasso
regularization [5]
@@ -29,6 +33,21 @@ It provides the following solvers:
Some demonstrations (both in Python and Jupyter Notebook format) are
available in the examples folder.
+Using and citing the toolbox
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If you use this toolbox in your research and find it useful, please cite
+POT using the following bibtex reference:
+
+::
+
+ @misc{flamary2017pot,
+ title={POT Python Optimal Transport library},
+ author={Flamary, R{'e}mi and Courty, Nicolas},
+ url={https://github.com/rflamary/POT},
+ year={2017}
+ }
+
Installation
------------
@@ -37,7 +56,7 @@ C++ compiler for using the EMD solver and relies on the following Python
modules:
- Numpy (>=1.11)
-- Scipy (>=0.17)
+- Scipy (>=1.0)
- Cython (>=0.23)
- Matplotlib (>=1.5)
@@ -212,20 +231,6 @@ languages):
- `Marco Cuturi <http://marcocuturi.net/>`__ (Sinkhorn Knopp in
Matlab/Cuda)
-Using and citing the toolbox
-----------------------------
-
-If you use this toolbox in your research and find it useful, please cite
-POT using the following bibtex reference:
-
-::
-
- @article{flamary2017pot,
- title={POT Python Optimal Transport library},
- author={Flamary, R{\'e}mi and Courty, Nicolas},
- year={2017}
- }
-
Contributions and code of conduct
---------------------------------
@@ -320,6 +325,15 @@ Journal of Optimization Theory and Applications Vol 43.
[15] Peyré, G., & Cuturi, M. (2018). `Computational Optimal
Transport <https://arxiv.org/pdf/1803.00567.pdf>`__ .
+[16] Agueh, M., & Carlier, G. (2011). `Barycenters in the Wasserstein
+space <https://hal.archives-ouvertes.fr/hal-00637399/document>`__. SIAM
+Journal on Mathematical Analysis, 43(2), 904-924.
+
+[17] Blondel, M., Seguy, V., & Rolet, A. (2018). `Smooth and Sparse
+Optimal Transport <https://arxiv.org/abs/1710.06276>`__. Proceedings of
+the Twenty-First International Conference on Artificial Intelligence and
+Statistics (AISTATS).
+
.. |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