diff options
Diffstat (limited to 'docs/source/auto_examples')
195 files changed, 4571 insertions, 1509 deletions
diff --git a/docs/source/auto_examples/auto_examples_jupyter.zip b/docs/source/auto_examples/auto_examples_jupyter.zip Binary files differindex 901195a..069a0f3 100644 --- a/docs/source/auto_examples/auto_examples_jupyter.zip +++ b/docs/source/auto_examples/auto_examples_jupyter.zip diff --git a/docs/source/auto_examples/auto_examples_python.zip b/docs/source/auto_examples/auto_examples_python.zip Binary files differindex ded2613..e04aed4 100644 --- a/docs/source/auto_examples/auto_examples_python.zip +++ b/docs/source/auto_examples/auto_examples_python.zip 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 Binary files differindex 6e74d89..2c35176 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 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 Binary files differindex 0407e44..dc58146 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_003.png Binary files differnew file mode 100644 index 0000000..1824cba --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_004.png Binary files differnew file mode 100644 index 0000000..7a9d992 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_004.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png Binary files differindex 6e74d89..2c35176 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png Binary files differindex 0407e44..dc58146 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png Binary files differnew file mode 100644 index 0000000..1824cba --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png Binary files differnew file mode 100644 index 0000000..46c9bb5 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png Binary files differindex 4421bc7..aed496a 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png Binary files differnew file mode 100644 index 0000000..91cf3e4 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png 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 Binary files differindex a5bded7..b7d6c32 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 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 Binary files differindex 1d90c2d..dbd52b1 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png Binary files differnew file mode 100644 index 0000000..31fb585 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png Binary files differnew file mode 100644 index 0000000..5a50fc4 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png 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 Binary files differindex ea6a405..dfb32cc 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 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 Binary files differindex 8bc46dc..9a6db51 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png Binary files differnew file mode 100644 index 0000000..8e8c275 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png Binary files differnew file mode 100644 index 0000000..3fadb99 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png 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 Binary files differindex 3b1a29e..b8d1b71 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 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 Binary files differindex 5a33824..f066922 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png Binary files differindex 4860d96..2d0be7d 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png Binary files differindex 6a21f35..5fc1700 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png 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 Binary files differindex 1108375..05f7c93 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png Binary files differindex 4860d96..e95653e 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png Binary files differindex 69ef5b7..1569ea7 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png Binary files differindex 0407e44..dc58146 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_003.png Binary files differnew file mode 100644 index 0000000..1e9af5a --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_UOT_1D_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png Binary files differindex ec8c51e..7b651ca 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png Binary files differnew file mode 100644 index 0000000..08cda47 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png Binary files differindex 89ab265..aef4700 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png Binary files differnew file mode 100644 index 0000000..a785125 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png 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 Binary files differindex 3500812..7165659 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 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 Binary files differindex d8db85e..82e7364 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 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 Binary files differindex d8db85e..f2a8fd3 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 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 Binary files differindex bfa0873..5d52b39 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png Binary files differindex 77e1282..8e2892d 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png Binary files differindex ca6d7f8..16304ef 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png 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 Binary files differindex 3500812..7165659 100644 --- 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 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 Binary files differindex 37fef68..c244118 100644 --- 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png Binary files differindex eb04b1a..542ed69 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png Binary files differindex a9f44ba..e44f5e7 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png Binary files differnew file mode 100644 index 0000000..beb300b --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png Binary files differindex e53928e..7463619 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png Binary files differnew file mode 100644 index 0000000..388a0d6 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png 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 Binary files differindex 03e0b0e..819177c 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_002.png b/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_002.png Binary files differnew file mode 100644 index 0000000..b518db1 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_compute_emd_002.png 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 Binary files differindex 077db3e..7412ef2 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png b/docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png Binary files differindex 14a72a3..a59b773 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_001.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_001.png Binary files differnew file mode 100644 index 0000000..300d04a --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_fgw_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_002.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_002.png Binary files differnew file mode 100644 index 0000000..5f95d4a --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_fgw_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_fgw_003.png b/docs/source/auto_examples/images/sphx_glr_plot_fgw_003.png Binary files differnew file mode 100644 index 0000000..378e4f7 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_fgw_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png b/docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png Binary files differindex d7bc78a..f6b72b5 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png 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 Binary files differindex 2e9b38e..4923bca 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 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 Binary files differindex 343fd78..1bd0a87 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 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 Binary files differindex 93e1def..e898b0b 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png Binary files differindex 0665c9b..d54a124 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_001.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_001.png Binary files differnew file mode 100644 index 0000000..1824cba --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_002.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_002.png Binary files differnew file mode 100644 index 0000000..2d9e678 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_002.png 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 Binary files differindex 4421bc7..385fca9 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 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 Binary files differindex bf7c076..e98de9b 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 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 Binary files differindex 71ef350..64695a2 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_002.png Binary files differnew file mode 100644 index 0000000..63f3b59 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_classes_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png Binary files differindex 7de991a..51c07f9 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_002.png Binary files differnew file mode 100644 index 0000000..8f579ac --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png Binary files differindex aac929b..51350f5 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png 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 Binary files differindex 114871a..e57780b 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_002.png Binary files differnew file mode 100644 index 0000000..77cbd69 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_d2_002.png 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 Binary files differindex 78ac59b..e33595c 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_001.png Binary files differnew file mode 100644 index 0000000..af64f21 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_002.png Binary files differnew file mode 100644 index 0000000..5334792 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_003.png Binary files differnew file mode 100644 index 0000000..ba8ad9d --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_004.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_004.png Binary files differnew file mode 100644 index 0000000..ea921e2 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_jcpot_004.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png Binary files differnew file mode 100644 index 0000000..66ef851 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png Binary files differnew file mode 100644 index 0000000..f9a4959 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_laplacian_002.png 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 Binary files differindex 88796df..d889c54 100644 --- 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 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 Binary files differindex 22b5d0c..4b2328d 100644 --- 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png Binary files differnew file mode 100644 index 0000000..fd662b3 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png 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 Binary files differindex 16a228a..61c4a7e 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_002.png Binary files differnew file mode 100644 index 0000000..a329e4f --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png Binary files differindex d77e68a..9999531 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png Binary files differnew file mode 100644 index 0000000..057b586 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png Binary files differindex 1199903..f82fddf 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png 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 Binary files differindex 9b5ae7a..fd16c39 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png Binary files differnew file mode 100644 index 0000000..36518f7 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png 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 Binary files differindex 26ab6f6..6679ace 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 diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png Binary files differnew file mode 100644 index 0000000..f944550 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png Binary files differnew file mode 100644 index 0000000..45542c1 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png Binary files differnew file mode 100644 index 0000000..83e0d41 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png Binary files differnew file mode 100644 index 0000000..a1ba204 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png Binary files differnew file mode 100644 index 0000000..2c35176 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png Binary files differnew file mode 100644 index 0000000..dc58146 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png Binary files differnew file mode 100644 index 0000000..21be620 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_001.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_001.png Binary files differnew file mode 100644 index 0000000..0fc47ab --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_001.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_002.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_002.png Binary files differnew file mode 100644 index 0000000..7909f19 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_002.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_003.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_003.png Binary files differnew file mode 100644 index 0000000..23a0674 --- /dev/null +++ b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png Binary files differindex 8aada91..1db9eda 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_004.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png Binary files differindex 42e5007..23a0674 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png Binary files differindex 4679eb6..c73b639 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png 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 Binary files differindex 4679eb6..c73b639 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 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 Binary files differindex ae33588..1986d18 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 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 Binary files differindex cdf1208..cf31a53 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png Binary files differindex 1d048f2..ee3710f 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png Binary files differindex 999f175..7a4e6b4 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png 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 Binary files differindex c68e95f..9568037 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png Binary files differindex 9c3244e..1b6eeaf 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png 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 Binary files differindex c68e95f..9568037 100644 --- 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 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 Binary files differindex 4531351..7501527 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png Binary files differindex af8aad2..219d52a 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png Binary files differindex 609339d..b64a0fe 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png Binary files differindex 0861d4d..b0d9597 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png Binary files differindex df25b39..2f3e81a 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png 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 Binary files differindex 6f250a4..7881fae 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png Binary files differindex cbc8e0f..f6079d6 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png 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 Binary files differindex ec78552..9e9c272 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png Binary files differindex 4d90437..51d64b7 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png 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 Binary files differindex 4f8f72f..748d62c 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png Binary files differnew file mode 100644 index 0000000..1e05241 --- /dev/null +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png Binary files differnew file mode 100644 index 0000000..db37d2b --- /dev/null +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png 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 Binary files differindex 277950e..1a92904 100644 --- 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png Binary files differindex 61a5137..81a8066 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png 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 Binary files differindex bd7c939..2c0ddb1 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 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 Binary files differindex b683392..e1e2f7c 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 diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png Binary files differnew file mode 100644 index 0000000..0f630f1 --- /dev/null +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png Binary files differnew file mode 100644 index 0000000..c73b639 --- /dev/null +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png Binary files differindex 609339d..9e308d2 100644 --- a/docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png +++ b/docs/source/auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png diff --git a/docs/source/auto_examples/index.rst b/docs/source/auto_examples/index.rst index fe6702d..9f05263 100644 --- a/docs/source/auto_examples/index.rst +++ b/docs/source/auto_examples/index.rst @@ -1,5 +1,9 @@ :orphan: + + +.. _sphx_glr_auto_examples: + POT Examples ============ @@ -13,9 +17,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_1D_thumb.png - :ref:`sphx_glr_auto_examples_plot_OT_1D.py` + :ref:`sphx_glr_auto_examples_plot_OT_1D.py` .. raw:: html @@ -33,9 +37,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_UOT_1D_thumb.png - :ref:`sphx_glr_auto_examples_plot_UOT_1D.py` + :ref:`sphx_glr_auto_examples_plot_UOT_1D.py` .. raw:: html @@ -49,13 +53,13 @@ This is a gallery of all the POT example files. .. raw:: html - <div class="sphx-glr-thumbcontainer" tooltip="Illustrates the use of the generic solver for regularized OT with user-designed regularization ..."> + <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the computation of Screenkhorn: Screening Sinkhorn Algorithm for Optim..."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_screenkhorn_1D_thumb.png - :ref:`sphx_glr_auto_examples_plot_optim_OTreg.py` + :ref:`sphx_glr_auto_examples_plot_screenkhorn_1D.py` .. raw:: html @@ -65,17 +69,17 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_optim_OTreg + /auto_examples/plot_screenkhorn_1D .. raw:: html - <div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D Wasserstein barycenters if discributions that are weighted sum of diracs."> + <div class="sphx-glr-thumbcontainer" tooltip="Illustrates the use of the generic solver for regularized OT with user-designed regularization ..."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png - :ref:`sphx_glr_auto_examples_plot_free_support_barycenter.py` + :ref:`sphx_glr_auto_examples_plot_optim_OTreg.py` .. raw:: html @@ -85,7 +89,7 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_free_support_barycenter + /auto_examples/plot_optim_OTreg .. raw:: html @@ -93,9 +97,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_1D_smooth_thumb.png - :ref:`sphx_glr_auto_examples_plot_OT_1D_smooth.py` + :ref:`sphx_glr_auto_examples_plot_OT_1D_smooth.py` .. raw:: html @@ -109,13 +113,13 @@ This is a gallery of all the POT example files. .. raw:: html - <div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Gromov-Wassertsein distance computation in POT...."> + <div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D Wasserstein barycenters if discributions that are weighted sum of diracs."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_free_support_barycenter_thumb.png - :ref:`sphx_glr_auto_examples_plot_gromov.py` + :ref:`sphx_glr_auto_examples_plot_free_support_barycenter.py` .. raw:: html @@ -125,7 +129,7 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_gromov + /auto_examples/plot_free_support_barycenter .. raw:: html @@ -133,9 +137,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png - :ref:`sphx_glr_auto_examples_plot_compute_emd.py` + :ref:`sphx_glr_auto_examples_plot_compute_emd.py` .. raw:: html @@ -149,13 +153,33 @@ This is a gallery of all the POT example files. .. raw:: html + <div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Gromov-Wassertsein distance computation in POT...."> + +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png + + :ref:`sphx_glr_auto_examples_plot_gromov.py` + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/plot_gromov + +.. raw:: html + <div class="sphx-glr-thumbcontainer" tooltip="This example is designed to illustrate how the Convolutional Wasserstein Barycenter function of..."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png - :ref:`sphx_glr_auto_examples_plot_convolutional_barycenter.py` + :ref:`sphx_glr_auto_examples_plot_convolutional_barycenter.py` .. raw:: html @@ -173,9 +197,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_linear_mapping_thumb.png - :ref:`sphx_glr_auto_examples_plot_otda_linear_mapping.py` + :ref:`sphx_glr_auto_examples_plot_otda_linear_mapping.py` .. raw:: html @@ -189,13 +213,13 @@ This is a gallery of all the POT example files. .. raw:: html - <div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the use of WDA as proposed in [11]."> + <div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D optimal transport between discributions that are weighted sum of diracs. The..."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png - :ref:`sphx_glr_auto_examples_plot_WDA.py` + :ref:`sphx_glr_auto_examples_plot_OT_2D_samples.py` .. raw:: html @@ -205,17 +229,17 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_WDA + /auto_examples/plot_OT_2D_samples .. raw:: html - <div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D optimal transport between discributions that are weighted sum of diracs. The..."> + <div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the use of WDA as proposed in [11]."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png - :ref:`sphx_glr_auto_examples_plot_OT_2D_samples.py` + :ref:`sphx_glr_auto_examples_plot_WDA.py` .. raw:: html @@ -225,7 +249,7 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_OT_2D_samples + /auto_examples/plot_WDA .. raw:: html @@ -233,9 +257,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_thumb.png - :ref:`sphx_glr_auto_examples_plot_stochastic.py` + :ref:`sphx_glr_auto_examples_plot_stochastic.py` .. raw:: html @@ -253,9 +277,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png - :ref:`sphx_glr_auto_examples_plot_otda_color_images.py` + :ref:`sphx_glr_auto_examples_plot_otda_color_images.py` .. raw:: html @@ -273,9 +297,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png - :ref:`sphx_glr_auto_examples_plot_barycenter_1D.py` + :ref:`sphx_glr_auto_examples_plot_barycenter_1D.py` .. raw:: html @@ -289,13 +313,33 @@ This is a gallery of all the POT example files. .. raw:: html + <div class="sphx-glr-thumbcontainer" tooltip="This example introduces a domain adaptation in a 2D setting and OTDA approach with Laplacian re..."> + +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_laplacian_thumb.png + + :ref:`sphx_glr_auto_examples_plot_otda_laplacian.py` + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/plot_otda_laplacian + +.. raw:: html + <div class="sphx-glr-thumbcontainer" tooltip="OT for domain adaptation with image color adaptation [6] with mapping estimation [8]."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png - :ref:`sphx_glr_auto_examples_plot_otda_mapping_colors_images.py` + :ref:`sphx_glr_auto_examples_plot_otda_mapping_colors_images.py` .. raw:: html @@ -313,9 +357,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_UOT_barycenter_1D_thumb.png - :ref:`sphx_glr_auto_examples_plot_UOT_barycenter_1D.py` + :ref:`sphx_glr_auto_examples_plot_UOT_barycenter_1D.py` .. raw:: html @@ -333,9 +377,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_thumb.png - :ref:`sphx_glr_auto_examples_plot_otda_mapping.py` + :ref:`sphx_glr_auto_examples_plot_otda_mapping.py` .. raw:: html @@ -349,13 +393,13 @@ This is a gallery of all the POT example files. .. raw:: html - <div class="sphx-glr-thumbcontainer" tooltip="This example introduces a semi supervised domain adaptation in a 2D setting. It explicits the p..."> + <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the computation of FGW for 1D measures[18]."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png - :ref:`sphx_glr_auto_examples_plot_otda_semi_supervised.py` + :ref:`sphx_glr_auto_examples_plot_fgw.py` .. raw:: html @@ -365,17 +409,17 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_otda_semi_supervised + /auto_examples/plot_fgw .. raw:: html - <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the computation of FGW for 1D measures[18]."> + <div class="sphx-glr-thumbcontainer" tooltip="This example introduces a semi supervised domain adaptation in a 2D setting. It explicits the p..."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_fgw_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_semi_supervised_thumb.png - :ref:`sphx_glr_auto_examples_plot_fgw.py` + :ref:`sphx_glr_auto_examples_plot_otda_semi_supervised.py` .. raw:: html @@ -385,7 +429,7 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_fgw + /auto_examples/plot_otda_semi_supervised .. raw:: html @@ -393,9 +437,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_classes_thumb.png - :ref:`sphx_glr_auto_examples_plot_otda_classes.py` + :ref:`sphx_glr_auto_examples_plot_otda_classes.py` .. raw:: html @@ -409,13 +453,33 @@ This is a gallery of all the POT example files. .. raw:: html + <div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Partial (Gromov-)Wassertsein distance computati..."> + +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_partial_wass_and_gromov_thumb.png + + :ref:`sphx_glr_auto_examples_plot_partial_wass_and_gromov.py` + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/plot_partial_wass_and_gromov + +.. raw:: html + <div class="sphx-glr-thumbcontainer" tooltip="This example introduces a domain adaptation in a 2D setting. It explicits the problem of domain..."> .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_d2_thumb.png - :ref:`sphx_glr_auto_examples_plot_otda_d2.py` + :ref:`sphx_glr_auto_examples_plot_otda_d2.py` .. raw:: html @@ -433,9 +497,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_L1_vs_L2_thumb.png - :ref:`sphx_glr_auto_examples_plot_OT_L1_vs_L2.py` + :ref:`sphx_glr_auto_examples_plot_OT_L1_vs_L2.py` .. raw:: html @@ -449,13 +513,33 @@ This is a gallery of all the POT example files. .. raw:: html + <div class="sphx-glr-thumbcontainer" tooltip="This example introduces a target shift problem with two 2D source and 1 target domain."> + +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_jcpot_thumb.png + + :ref:`sphx_glr_auto_examples_plot_otda_jcpot.py` + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/plot_otda_jcpot + +.. 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 + .. 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` + :ref:`sphx_glr_auto_examples_plot_barycenter_lp_vs_entropic.py` .. raw:: html @@ -473,9 +557,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_fgw_thumb.png - :ref:`sphx_glr_auto_examples_plot_barycenter_fgw.py` + :ref:`sphx_glr_auto_examples_plot_barycenter_fgw.py` .. raw:: html @@ -493,9 +577,9 @@ This is a gallery of all the POT example files. .. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_barycenter_thumb.png - :ref:`sphx_glr_auto_examples_plot_gromov_barycenter.py` + :ref:`sphx_glr_auto_examples_plot_gromov_barycenter.py` .. raw:: html @@ -508,22 +592,23 @@ This is a gallery of all the POT example files. /auto_examples/plot_gromov_barycenter .. raw:: html - <div style='clear:both'></div> + <div class="sphx-glr-clear"></div> .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-gallery - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download all examples in Python source code: auto_examples_python.zip <//home/rflamary/PYTHON/POT/docs/source/auto_examples/auto_examples_python.zip>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download all examples in Jupyter notebooks: auto_examples_jupyter.zip <//home/rflamary/PYTHON/POT/docs/source/auto_examples/auto_examples_jupyter.zip>` @@ -532,4 +617,4 @@ This is a gallery of all the POT example files. .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_OT_1D.ipynb b/docs/source/auto_examples/plot_OT_1D.ipynb index bd0439e..f679a30 100644 --- a/docs/source/auto_examples/plot_OT_1D.ipynb +++ b/docs/source/auto_examples/plot_OT_1D.ipynb @@ -44,7 +44,7 @@ }, "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()" + "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" ] }, { @@ -62,7 +62,18 @@ }, "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')" + "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" ] }, { @@ -80,7 +91,7 @@ }, "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')" + "G0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" ] }, { @@ -98,7 +109,7 @@ }, "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()" + "lambd = 1e-3\nGs = ot.sinkhorn(a, b, M, lambd, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn')\n\npl.show()" ] } ], @@ -118,7 +129,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_OT_1D.rst b/docs/source/auto_examples/plot_OT_1D.rst index b97d67c..ec21845 100644 --- a/docs/source/auto_examples/plot_OT_1D.rst +++ b/docs/source/auto_examples/plot_OT_1D.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_OT_1D.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_OT_1D.py: + .. _sphx_glr_auto_examples_plot_OT_1D.py: ==================== @@ -12,8 +18,7 @@ and their visualization. - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -32,17 +37,14 @@ and their visualization. + Generate data ------------- - -.. code-block:: python +.. code-block:: default - - #%% parameters - n = 100 # nb bins # bin positions @@ -63,55 +65,60 @@ Generate data + Plot distributions and loss matrix ---------------------------------- +.. code-block:: default -.. code-block:: python - - - #%% plot the distributions pl.figure(1, figsize=(6.4, 3)) pl.plot(x, a, 'b', label='Source distribution') pl.plot(x, b, 'r', label='Target distribution') pl.legend() - #%% plot distributions and loss matrix - pl.figure(2, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_001.png + :class: sphx-glr-single-img -.. rst-class:: sphx-glr-horizontal +.. rst-class:: sphx-glr-script-out + Out: - * + .. code-block:: none - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_001.png - :scale: 47 - * + <matplotlib.legend.Legend object at 0x7f4c75f9fcc0> - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_002.png - :scale: 47 +.. code-block:: default + + + pl.figure(2, figsize=(5, 5)) + ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') + -Solve EMD ---------- +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_002.png + :class: sphx-glr-single-img -.. code-block:: python - #%% EMD + +Solve EMD +--------- + + +.. code-block:: default + G0 = ot.emd(a, b, M) @@ -121,8 +128,9 @@ Solve EMD -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_005.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_003.png + :class: sphx-glr-single-img + @@ -131,12 +139,8 @@ Solve Sinkhorn -------------- +.. code-block:: default -.. code-block:: python - - - - #%% Sinkhorn lambd = 1e-3 Gs = ot.sinkhorn(a, b, M, lambd, verbose=True) @@ -148,46 +152,71 @@ Solve Sinkhorn -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_007.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_004.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: + Out: + .. code-block:: none + + It. |Err + ------------------- + 0|2.861463e-01| + 10|1.860154e-01| + 20|8.144529e-02| + 30|3.130143e-02| + 40|1.178815e-02| + 50|4.426078e-03| + 60|1.661047e-03| + 70|6.233110e-04| + 80|2.338932e-04| + 90|8.776627e-05| + 100|3.293340e-05| + 110|1.235791e-05| + 120|4.637176e-06| + 130|1.740051e-06| + 140|6.529356e-07| + 150|2.450071e-07| + 160|9.193632e-08| + 170|3.449812e-08| + 180|1.294505e-08| + 190|4.857493e-09| It. |Err ------------------- - 0|8.187970e-02| - 10|3.460174e-02| - 20|6.633335e-03| - 30|9.797798e-04| - 40|1.389606e-04| - 50|1.959016e-05| - 60|2.759079e-06| - 70|3.885166e-07| - 80|5.470605e-08| - 90|7.702918e-09| - 100|1.084609e-09| - 110|1.527180e-10| + 200|1.822723e-09| + 210|6.839572e-10| + /home/rflamary/PYTHON/POT/examples/plot_OT_1D.py:84: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + -**Total running time of the script:** ( 0 minutes 0.561 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.665 seconds) + + +.. _sphx_glr_download_auto_examples_plot_OT_1D.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_OT_1D.py <plot_OT_1D.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_OT_1D.ipynb <plot_OT_1D.ipynb>` @@ -196,4 +225,4 @@ Solve Sinkhorn .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_OT_1D_smooth.ipynb b/docs/source/auto_examples/plot_OT_1D_smooth.ipynb index d523f6a..493e6bb 100644 --- a/docs/source/auto_examples/plot_OT_1D_smooth.ipynb +++ b/docs/source/auto_examples/plot_OT_1D_smooth.ipynb @@ -44,7 +44,7 @@ }, "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()" + "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" ] }, { @@ -62,7 +62,18 @@ }, "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')" + "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" ] }, { @@ -80,7 +91,7 @@ }, "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')" + "G0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" ] }, { @@ -98,7 +109,7 @@ }, "outputs": [], "source": [ - "#%% Sinkhorn\n\nlambd = 2e-3\nGs = ot.sinkhorn(a, b, M, lambd, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn')\n\npl.show()" + "lambd = 2e-3\nGs = ot.sinkhorn(a, b, M, lambd, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn')\n\npl.show()" ] }, { @@ -116,7 +127,18 @@ }, "outputs": [], "source": [ - "#%% Smooth OT with KL regularization\n\nlambd = 2e-3\nGsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='kl')\n\npl.figure(5, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT KL reg.')\n\npl.show()\n\n\n#%% Smooth OT with KL regularization\n\nlambd = 1e-1\nGsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='l2')\n\npl.figure(6, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT l2 reg.')\n\npl.show()" + "lambd = 2e-3\nGsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='kl')\n\npl.figure(5, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT KL reg.')\n\npl.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "lambd = 1e-1\nGsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='l2')\n\npl.figure(6, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gsm, 'OT matrix Smooth OT l2 reg.')\n\npl.show()" ] } ], @@ -136,7 +158,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_OT_1D_smooth.rst b/docs/source/auto_examples/plot_OT_1D_smooth.rst index 5a0ebd3..de42689 100644 --- a/docs/source/auto_examples/plot_OT_1D_smooth.rst +++ b/docs/source/auto_examples/plot_OT_1D_smooth.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_OT_1D_smooth.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_OT_1D_smooth.py: + .. _sphx_glr_auto_examples_plot_OT_1D_smooth.py: =========================== @@ -12,8 +18,7 @@ and their visualization. - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -32,16 +37,13 @@ and their visualization. + Generate data ------------- +.. code-block:: default -.. code-block:: python - - - - #%% parameters n = 100 # nb bins @@ -63,55 +65,60 @@ Generate data + Plot distributions and loss matrix ---------------------------------- +.. code-block:: default -.. code-block:: python - - - #%% plot the distributions pl.figure(1, figsize=(6.4, 3)) pl.plot(x, a, 'b', label='Source distribution') pl.plot(x, b, 'r', label='Target distribution') pl.legend() - #%% plot distributions and loss matrix - pl.figure(2, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png + :class: sphx-glr-single-img -.. rst-class:: sphx-glr-horizontal +.. rst-class:: sphx-glr-script-out + Out: - * + .. code-block:: none - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_001.png - :scale: 47 - * + <matplotlib.legend.Legend object at 0x7f4c738a51d0> - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png - :scale: 47 +.. code-block:: default -Solve EMD ---------- + + pl.figure(2, figsize=(5, 5)) + ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') + + + + +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_002.png + :class: sphx-glr-single-img -.. code-block:: python +Solve EMD +--------- + + +.. code-block:: default - #%% EMD G0 = ot.emd(a, b, M) @@ -121,8 +128,9 @@ Solve EMD -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_003.png + :class: sphx-glr-single-img + @@ -131,13 +139,9 @@ Solve Sinkhorn -------------- - -.. code-block:: python +.. code-block:: default - - #%% Sinkhorn - lambd = 2e-3 Gs = ot.sinkhorn(a, b, M, lambd, verbose=True) @@ -149,34 +153,42 @@ Solve Sinkhorn -.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_007.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_004.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none It. |Err ------------------- - 0|7.958844e-02| - 10|5.921715e-03| - 20|1.238266e-04| - 30|2.469780e-06| - 40|4.919966e-08| - 50|9.800197e-10| - + 0|2.821142e-01| + 10|7.695268e-02| + 20|1.112774e-02| + 30|1.571553e-03| + 40|2.218100e-04| + 50|3.130527e-05| + 60|4.418267e-06| + 70|6.235716e-07| + 80|8.800770e-08| + 90|1.242095e-08| + 100|1.753030e-09| + 110|2.474136e-10| + /home/rflamary/PYTHON/POT/examples/plot_OT_1D_smooth.py:84: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -Solve Smooth OT --------------- -.. code-block:: python +Solve Smooth OT +-------------- +.. code-block:: default - #%% Smooth OT with KL regularization lambd = 2e-3 Gsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='kl') @@ -187,7 +199,28 @@ Solve Smooth OT pl.show() - #%% Smooth OT with KL regularization + + + +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_005.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_OT_1D_smooth.py:99: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + + +.. code-block:: default + lambd = 1e-1 Gsm = ot.smooth.smooth_ot_dual(a, b, M, lambd, reg_type='l2') @@ -199,38 +232,45 @@ Solve Smooth OT -.. rst-class:: sphx-glr-horizontal +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_006.png + :class: sphx-glr-single-img - * +.. rst-class:: sphx-glr-script-out + + Out: - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_009.png - :scale: 47 + .. code-block:: none - * + /home/rflamary/PYTHON/POT/examples/plot_OT_1D_smooth.py:110: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_smooth_010.png - :scale: 47 -**Total running time of the script:** ( 0 minutes 1.053 seconds) +.. rst-class:: sphx-glr-timing + **Total running time of the script:** ( 0 minutes 0.732 seconds) + + +.. _sphx_glr_download_auto_examples_plot_OT_1D_smooth.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_OT_1D_smooth.py <plot_OT_1D_smooth.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_OT_1D_smooth.ipynb <plot_OT_1D_smooth.ipynb>` @@ -239,4 +279,4 @@ Solve Smooth OT .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_OT_2D_samples.ipynb b/docs/source/auto_examples/plot_OT_2D_samples.ipynb index dad138b..ff7abde 100644 --- a/docs/source/auto_examples/plot_OT_2D_samples.ipynb +++ b/docs/source/auto_examples/plot_OT_2D_samples.ipynb @@ -44,7 +44,7 @@ }, "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()" + "n = 50 # nb samples\n\nmu_s = np.array([0, 0])\ncov_s = np.array([[1, 0], [0, 1]])\n\nmu_t = np.array([4, 4])\ncov_t = np.array([[1, -.8], [-.8, 1]])\n\nxs = ot.datasets.make_2D_samples_gauss(n, mu_s, cov_s)\nxt = ot.datasets.make_2D_samples_gauss(n, mu_t, cov_t)\n\na, b = np.ones((n,)) / n, np.ones((n,)) / n # uniform distribution on samples\n\n# loss matrix\nM = ot.dist(xs, xt)\nM /= M.max()" ] }, { @@ -62,7 +62,7 @@ }, "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')" + "pl.figure(1)\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.legend(loc=0)\npl.title('Source and target distributions')\n\npl.figure(2)\npl.imshow(M, interpolation='nearest')\npl.title('Cost matrix M')" ] }, { @@ -80,7 +80,7 @@ }, "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')" + "G0 = ot.emd(a, b, M)\n\npl.figure(3)\npl.imshow(G0, interpolation='nearest')\npl.title('OT matrix G0')\n\npl.figure(4)\not.plot.plot2D_samples_mat(xs, xt, G0, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.legend(loc=0)\npl.title('OT matrix with samples')" ] }, { @@ -98,7 +98,7 @@ }, "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()" + "# 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()" ] }, { @@ -116,7 +116,7 @@ }, "outputs": [], "source": [ - "#%% sinkhorn\n\n# reg term\nlambd = 1e-3\n\nGes = ot.bregman.empirical_sinkhorn(xs, xt, lambd)\n\npl.figure(7)\npl.imshow(Ges, interpolation='nearest')\npl.title('OT matrix empirical sinkhorn')\n\npl.figure(8)\not.plot.plot2D_samples_mat(xs, xt, Ges, color=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.legend(loc=0)\npl.title('OT matrix Sinkhorn from samples')\n\npl.show()" + "# reg term\nlambd = 1e-3\n\nGes = ot.bregman.empirical_sinkhorn(xs, xt, lambd)\n\npl.figure(7)\npl.imshow(Ges, interpolation='nearest')\npl.title('OT matrix empirical sinkhorn')\n\npl.figure(8)\not.plot.plot2D_samples_mat(xs, xt, Ges, color=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.legend(loc=0)\npl.title('OT matrix Sinkhorn from samples')\n\npl.show()" ] } ], @@ -136,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_OT_2D_samples.rst b/docs/source/auto_examples/plot_OT_2D_samples.rst index 1f1d713..460bb95 100644 --- a/docs/source/auto_examples/plot_OT_2D_samples.rst +++ b/docs/source/auto_examples/plot_OT_2D_samples.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_OT_2D_samples.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_OT_2D_samples.py: + .. _sphx_glr_auto_examples_plot_OT_2D_samples.py: ==================================================== @@ -12,8 +18,7 @@ sum of diracs. The OT matrix is plotted with the samples. - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -32,15 +37,13 @@ sum of diracs. The OT matrix is plotted with the samples. + Generate data ------------- +.. code-block:: default -.. code-block:: python - - - #%% parameters and data generation n = 50 # nb samples @@ -65,15 +68,13 @@ Generate data + Plot data --------- +.. code-block:: default -.. code-block:: python - - - #%% plot samples pl.figure(1) pl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') @@ -94,25 +95,31 @@ Plot data * .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png - :scale: 47 + :class: sphx-glr-multi-img * .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png - :scale: 47 + :class: sphx-glr-multi-img +.. rst-class:: sphx-glr-script-out + Out: -Compute EMD ------------ + .. code-block:: none + + + Text(0.5, 1.0, 'Cost matrix M') -.. code-block:: python +Compute EMD +----------- + +.. code-block:: default - #%% EMD G0 = ot.emd(a, b, M) @@ -136,26 +143,32 @@ Compute EMD * - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png + :class: sphx-glr-multi-img * - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png + :class: sphx-glr-multi-img +.. rst-class:: sphx-glr-script-out + Out: -Compute Sinkhorn ----------------- + .. code-block:: none + Text(0.5, 1.0, 'OT matrix with samples') -.. code-block:: python - #%% sinkhorn +Compute Sinkhorn +---------------- + + +.. code-block:: default + # reg term lambd = 1e-3 @@ -184,26 +197,33 @@ Compute Sinkhorn * - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_009.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png + :class: sphx-glr-multi-img * - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_010.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png + :class: sphx-glr-multi-img +.. rst-class:: sphx-glr-script-out + Out: -Emprirical Sinkhorn ----------------- + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_OT_2D_samples.py:103: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -.. code-block:: python + +Emprirical Sinkhorn +---------------- - #%% sinkhorn +.. code-block:: default + # reg term lambd = 1e-3 @@ -230,38 +250,55 @@ Emprirical Sinkhorn * - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_013.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_007.png + :class: sphx-glr-multi-img * - .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_014.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_2D_samples_008.png + :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none + /home/rflamary/PYTHON/POT/ot/bregman.py:363: RuntimeWarning: divide by zero encountered in true_divide + v = np.divide(b, KtransposeU) Warning: numerical errors at iteration 0 + /home/rflamary/PYTHON/POT/ot/plot.py:90: RuntimeWarning: invalid value encountered in double_scalars + if G[i, j] / mx > thr: + /home/rflamary/PYTHON/POT/examples/plot_OT_2D_samples.py:128: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + -**Total running time of the script:** ( 0 minutes 2.616 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 2.154 seconds) + + +.. _sphx_glr_download_auto_examples_plot_OT_2D_samples.py: + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_OT_2D_samples.py <plot_OT_2D_samples.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_OT_2D_samples.ipynb <plot_OT_2D_samples.ipynb>` @@ -270,4 +307,4 @@ Emprirical Sinkhorn .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.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 125d720..12a09f0 100644 --- a/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb +++ b/docs/source/auto_examples/plot_OT_L1_vs_L2.ipynb @@ -62,7 +62,7 @@ }, "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()" + "G1 = ot.emd(a, b, M1)\nG2 = ot.emd(a, b, M2)\nGp = ot.emd(a, b, Mp)\n\n# OT matrices\npl.figure(3, figsize=(7, 3))\n\npl.subplot(1, 3, 1)\not.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT Euclidean')\n\npl.subplot(1, 3, 2)\not.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT squared Euclidean')\n\npl.subplot(1, 3, 3)\not.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT sqrt Euclidean')\npl.tight_layout()\n\npl.show()" ] }, { @@ -98,7 +98,7 @@ }, "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()" + "G1 = ot.emd(a, b, M1)\nG2 = ot.emd(a, b, M2)\nGp = ot.emd(a, b, Mp)\n\n# OT matrices\npl.figure(6, figsize=(7, 3))\n\npl.subplot(1, 3, 1)\not.plot.plot2D_samples_mat(xs, xt, G1, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT Euclidean')\n\npl.subplot(1, 3, 2)\not.plot.plot2D_samples_mat(xs, xt, G2, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT squared Euclidean')\n\npl.subplot(1, 3, 3)\not.plot.plot2D_samples_mat(xs, xt, Gp, c=[.5, .5, 1])\npl.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\npl.plot(xt[:, 0], xt[:, 1], 'xr', label='Target samples')\npl.axis('equal')\n# pl.legend(loc=0)\npl.title('OT sqrt Euclidean')\npl.tight_layout()\n\npl.show()" ] } ], @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, 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 5db4b55..16b20f9 100644 --- a/docs/source/auto_examples/plot_OT_L1_vs_L2.rst +++ b/docs/source/auto_examples/plot_OT_L1_vs_L2.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_OT_L1_vs_L2.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_OT_L1_vs_L2.py: + .. _sphx_glr_auto_examples_plot_OT_L1_vs_L2.py: ========================================== @@ -15,8 +21,7 @@ https://arxiv.org/pdf/1706.07650.pdf - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -34,12 +39,12 @@ https://arxiv.org/pdf/1706.07650.pdf + Dataset 1 : uniform sampling ---------------------------- - -.. code-block:: python +.. code-block:: default n = 20 # nb samples @@ -98,12 +103,13 @@ Dataset 1 : uniform sampling * .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_001.png - :scale: 47 + :class: sphx-glr-multi-img * .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_002.png - :scale: 47 + :class: sphx-glr-multi-img + @@ -112,12 +118,8 @@ Dataset 1 : Plot OT Matrices ---------------------------- +.. code-block:: default -.. code-block:: python - - - - #%% EMD G1 = ot.emd(a, b, M1) G2 = ot.emd(a, b, M2) Gp = ot.emd(a, b, Mp) @@ -156,8 +158,18 @@ Dataset 1 : Plot OT Matrices -.. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_OT_L1_vs_L2.py:113: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -166,8 +178,7 @@ Dataset 2 : Partial circle -------------------------- - -.. code-block:: python +.. code-block:: default n = 50 # nb samples @@ -228,13 +239,14 @@ Dataset 2 : Partial circle * - .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_007.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_004.png + :class: sphx-glr-multi-img * - .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_008.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_005.png + :class: sphx-glr-multi-img + @@ -243,12 +255,8 @@ Dataset 2 : Plot OT Matrices ----------------------------- +.. code-block:: default -.. code-block:: python - - - - #%% EMD G1 = ot.emd(a, b, M1) G2 = ot.emd(a, b, M2) Gp = ot.emd(a, b, Mp) @@ -285,28 +293,45 @@ Dataset 2 : Plot OT Matrices -.. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_011.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_OT_L1_vs_L2_006.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + Out: + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_OT_L1_vs_L2.py:208: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 0 minutes 0.958 seconds) + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.002 seconds) + + +.. _sphx_glr_download_auto_examples_plot_OT_L1_vs_L2.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_OT_L1_vs_L2.py <plot_OT_L1_vs_L2.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_OT_L1_vs_L2.ipynb <plot_OT_L1_vs_L2.ipynb>` @@ -315,4 +340,4 @@ Dataset 2 : Plot OT Matrices .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_UOT_1D.ipynb b/docs/source/auto_examples/plot_UOT_1D.ipynb index c695306..640e398 100644 --- a/docs/source/auto_examples/plot_UOT_1D.ipynb +++ b/docs/source/auto_examples/plot_UOT_1D.ipynb @@ -44,7 +44,7 @@ }, "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# make distributions unbalanced\nb *= 5.\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" + "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# make distributions unbalanced\nb *= 5.\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" ] }, { @@ -62,7 +62,7 @@ }, "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')" + "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()\n\n# plot distributions and loss matrix\n\npl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" ] }, { @@ -100,7 +100,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_UOT_1D.rst b/docs/source/auto_examples/plot_UOT_1D.rst index 8e618b4..f43b0c1 100644 --- a/docs/source/auto_examples/plot_UOT_1D.rst +++ b/docs/source/auto_examples/plot_UOT_1D.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_UOT_1D.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_UOT_1D.py: + .. _sphx_glr_auto_examples_plot_UOT_1D.py: =============================== @@ -11,8 +17,7 @@ This example illustrates the computation of Unbalanced Optimal transport using a Kullback-Leibler relaxation. - -.. code-block:: python +.. code-block:: default # Author: Hicham Janati <hicham.janati@inria.fr> @@ -31,17 +36,14 @@ using a Kullback-Leibler relaxation. + Generate data ------------- - -.. code-block:: python +.. code-block:: default - - #%% parameters - n = 100 # nb bins # bin positions @@ -65,15 +67,13 @@ Generate data + Plot distributions and loss matrix ---------------------------------- +.. code-block:: default -.. code-block:: python - - - #%% plot the distributions pl.figure(1, figsize=(6.4, 3)) pl.plot(x, a, 'b', label='Source distribution') @@ -95,12 +95,13 @@ Plot distributions and loss matrix * .. image:: /auto_examples/images/sphx_glr_plot_UOT_1D_001.png - :scale: 47 + :class: sphx-glr-multi-img * .. image:: /auto_examples/images/sphx_glr_plot_UOT_1D_002.png - :scale: 47 + :class: sphx-glr-multi-img + @@ -109,8 +110,7 @@ Solve Unbalanced Sinkhorn -------------- - -.. code-block:: python +.. code-block:: default @@ -127,41 +127,45 @@ Solve Unbalanced Sinkhorn -.. image:: /auto_examples/images/sphx_glr_plot_UOT_1D_006.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_UOT_1D_003.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_UOT_1D.py:76: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + - It. |Err - ------------------- - 0|1.838786e+00| - 10|1.242379e-01| - 20|2.581314e-03| - 30|5.674552e-05| - 40|1.252959e-06| - 50|2.768136e-08| - 60|6.116090e-10| -**Total running time of the script:** ( 0 minutes 0.259 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.274 seconds) + + +.. _sphx_glr_download_auto_examples_plot_UOT_1D.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_UOT_1D.py <plot_UOT_1D.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_UOT_1D.ipynb <plot_UOT_1D.ipynb>` @@ -170,4 +174,4 @@ Solve Unbalanced Sinkhorn .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb b/docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb index e59cdc2..549a78b 100644 --- a/docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb +++ b/docs/source/auto_examples/plot_UOT_barycenter_1D.ipynb @@ -80,7 +80,7 @@ }, "outputs": [], "source": [ - "# non weighted barycenter computation\n\nweight = 0.5 # 0<=weight<=1\nweights = np.array([1 - weight, weight])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\nalpha = 1.\n\nbary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights)\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()" + "# non weighted barycenter computation\n\nweight = 0.5 # 0<=weight<=1\nweights = np.array([1 - weight, weight])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\nalpha = 1.\n\nbary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights)\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" ] }, { @@ -98,7 +98,7 @@ }, "outputs": [], "source": [ - "# barycenter interpolation\n\nn_weight = 11\nweight_list = np.linspace(0, 1, n_weight)\n\n\nB_l2 = np.zeros((n, n_weight))\n\nB_wass = np.copy(B_l2)\n\nfor i in range(0, n_weight):\n weight = weight_list[i]\n weights = np.array([1 - weight, weight])\n B_l2[:, i] = A.dot(weights)\n B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights)\n\n\n# plot interpolation\n\npl.figure(3)\n\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = weight_list\nfor i, z in enumerate(zs):\n ys = B_l2[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel(r'$\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with l2')\npl.tight_layout()\n\npl.figure(4)\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = weight_list\nfor i, z in enumerate(zs):\n ys = B_wass[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel(r'$\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with Wasserstein')\npl.tight_layout()\n\npl.show()" + "# barycenter interpolation\n\nn_weight = 11\nweight_list = np.linspace(0, 1, n_weight)\n\n\nB_l2 = np.zeros((n, n_weight))\n\nB_wass = np.copy(B_l2)\n\nfor i in range(0, n_weight):\n weight = weight_list[i]\n weights = np.array([1 - weight, weight])\n B_l2[:, i] = A.dot(weights)\n B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights)\n\n\n# plot interpolation\n\npl.figure(3)\n\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = weight_list\nfor i, z in enumerate(zs):\n ys = B_l2[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel(r'$\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with l2')\npl.tight_layout()\n\npl.figure(4)\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = weight_list\nfor i, z in enumerate(zs):\n ys = B_wass[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel(r'$\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with Wasserstein')\npl.tight_layout()\n\npl.show()" ] } ], @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_UOT_barycenter_1D.py b/docs/source/auto_examples/plot_UOT_barycenter_1D.py index c8d9d3b..acb5892 100644 --- a/docs/source/auto_examples/plot_UOT_barycenter_1D.py +++ b/docs/source/auto_examples/plot_UOT_barycenter_1D.py @@ -77,7 +77,7 @@ bary_l2 = A.dot(weights) reg = 1e-3 alpha = 1. -bary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights) +bary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) pl.figure(2) pl.clf() @@ -111,7 +111,7 @@ for i in range(0, n_weight): weight = weight_list[i] weights = np.array([1 - weight, weight]) B_l2[:, i] = A.dot(weights) - B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights) + B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) # plot interpolation diff --git a/docs/source/auto_examples/plot_UOT_barycenter_1D.rst b/docs/source/auto_examples/plot_UOT_barycenter_1D.rst index ac17587..2688d2e 100644 --- a/docs/source/auto_examples/plot_UOT_barycenter_1D.rst +++ b/docs/source/auto_examples/plot_UOT_barycenter_1D.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_UOT_barycenter_1D.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_UOT_barycenter_1D.py: + .. _sphx_glr_auto_examples_plot_UOT_barycenter_1D.py: =========================================================== @@ -15,8 +21,7 @@ as proposed in [10] for Unbalanced inputs. - -.. code-block:: python +.. code-block:: default # Author: Hicham Janati <hicham.janati@inria.fr> @@ -36,12 +41,12 @@ as proposed in [10] for Unbalanced inputs. + Generate data ------------- - -.. code-block:: python +.. code-block:: default # parameters @@ -72,12 +77,12 @@ Generate data + Plot data --------- - -.. code-block:: python +.. code-block:: default # plot the distributions @@ -92,7 +97,8 @@ Plot data .. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_001.png - :align: center + :class: sphx-glr-single-img + @@ -101,8 +107,7 @@ Barycenter computation ---------------------- - -.. code-block:: python +.. code-block:: default # non weighted barycenter computation @@ -117,7 +122,7 @@ Barycenter computation reg = 1e-3 alpha = 1. - bary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights) + bary_wass = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) pl.figure(2) pl.clf() @@ -136,8 +141,9 @@ Barycenter computation -.. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_002.png + :class: sphx-glr-single-img + @@ -146,8 +152,7 @@ Barycentric interpolation ------------------------- - -.. code-block:: python +.. code-block:: default # barycenter interpolation @@ -164,7 +169,7 @@ Barycentric interpolation weight = weight_list[i] weights = np.array([1 - weight, weight]) B_l2[:, i] = A.dot(weights) - B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights) + B_wass[:, i] = ot.unbalanced.barycenter_unbalanced(A, M, reg, alpha, weights=weights) # plot interpolation @@ -223,33 +228,66 @@ Barycentric interpolation * - .. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_005.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_003.png + :class: sphx-glr-multi-img * - .. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_006.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_UOT_barycenter_1D_004.png + :class: sphx-glr-multi-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + /home/rflamary/PYTHON/POT/ot/unbalanced.py:895: RuntimeWarning: overflow encountered in true_divide + u = (A / Kv) ** fi + /home/rflamary/PYTHON/POT/ot/unbalanced.py:900: RuntimeWarning: invalid value encountered in true_divide + v = (Q / Ktu) ** fi + /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 595 + warnings.warn('Numerical errors at iteration %s' % i) + /home/rflamary/PYTHON/POT/ot/unbalanced.py:900: RuntimeWarning: overflow encountered in true_divide + v = (Q / Ktu) ** fi + /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 974 + warnings.warn('Numerical errors at iteration %s' % i) + /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 615 + warnings.warn('Numerical errors at iteration %s' % i) + /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 455 + warnings.warn('Numerical errors at iteration %s' % i) + /home/rflamary/PYTHON/POT/ot/unbalanced.py:907: UserWarning: Numerical errors at iteration 361 + warnings.warn('Numerical errors at iteration %s' % i) + /home/rflamary/PYTHON/POT/examples/plot_UOT_barycenter_1D.py:164: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 0 minutes 0.344 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.567 seconds) + + +.. _sphx_glr_download_auto_examples_plot_UOT_barycenter_1D.py: + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_UOT_barycenter_1D.py <plot_UOT_barycenter_1D.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_UOT_barycenter_1D.ipynb <plot_UOT_barycenter_1D.ipynb>` @@ -258,4 +296,4 @@ Barycentric interpolation .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_barycenter_1D.ipynb b/docs/source/auto_examples/plot_barycenter_1D.ipynb index fc60e1f..387c41a 100644 --- a/docs/source/auto_examples/plot_barycenter_1D.ipynb +++ b/docs/source/auto_examples/plot_barycenter_1D.ipynb @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.make_1D_gauss(n, m=60, s=8)\n\n# 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 = 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()" ] }, { @@ -62,7 +62,7 @@ }, "outputs": [], "source": [ - "#%% plot the distributions\n\npl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" + "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" ] }, { @@ -80,7 +80,7 @@ }, "outputs": [], "source": [ - "#%% 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()" + "alpha = 0.2 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" ] }, { @@ -98,7 +98,18 @@ }, "outputs": [], "source": [ - "#%% 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()" + "n_alpha = 11\nalpha_list = np.linspace(0, 1, n_alpha)\n\n\nB_l2 = np.zeros((n, n_alpha))\n\nB_wass = np.copy(B_l2)\n\nfor i in range(0, n_alpha):\n alpha = alpha_list[i]\n weights = np.array([1 - alpha, alpha])\n B_l2[:, i] = A.dot(weights)\n B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(3)\n\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_l2[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with l2')\npl.tight_layout()\n\npl.figure(4)\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_wass[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with Wasserstein')\npl.tight_layout()\n\npl.show()" ] } ], @@ -118,7 +129,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_barycenter_1D.rst b/docs/source/auto_examples/plot_barycenter_1D.rst index 66ac042..a65ac3d 100644 --- a/docs/source/auto_examples/plot_barycenter_1D.rst +++ b/docs/source/auto_examples/plot_barycenter_1D.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_barycenter_1D.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_barycenter_1D.py: + .. _sphx_glr_auto_examples_plot_barycenter_1D.py: ============================== @@ -17,8 +23,7 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138. - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -38,16 +43,14 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138. + Generate data ------------- - -.. code-block:: python +.. code-block:: default - #%% parameters - n = 100 # nb bins # bin positions @@ -71,15 +74,13 @@ Generate data + Plot data --------- +.. code-block:: default -.. code-block:: python - - - #%% plot the distributions pl.figure(1, figsize=(6.4, 3)) for i in range(n_distributions): @@ -91,7 +92,8 @@ Plot data .. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_001.png - :align: center + :class: sphx-glr-single-img + @@ -100,12 +102,9 @@ Barycenter computation ---------------------- - -.. code-block:: python +.. code-block:: default - #%% barycenter computation - alpha = 0.2 # 0<=alpha<=1 weights = np.array([1 - alpha, alpha]) @@ -133,8 +132,9 @@ Barycenter computation -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_002.png + :class: sphx-glr-single-img + @@ -143,11 +143,8 @@ Barycentric interpolation ------------------------- +.. code-block:: default -.. code-block:: python - - - #%% barycenter interpolation n_alpha = 11 alpha_list = np.linspace(0, 1, n_alpha) @@ -163,7 +160,16 @@ Barycentric interpolation B_l2[:, i] = A.dot(weights) B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights) - #%% plot interpolation + + + + + + + + +.. code-block:: default + pl.figure(3) @@ -219,33 +225,50 @@ Barycentric interpolation * - .. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_005.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_003.png + :class: sphx-glr-multi-img * - .. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_006.png - :scale: 47 + .. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_004.png + :class: sphx-glr-multi-img + +.. rst-class:: sphx-glr-script-out + Out: + .. code-block:: none -**Total running time of the script:** ( 0 minutes 0.413 seconds) + /home/rflamary/PYTHON/POT/examples/plot_barycenter_1D.py:160: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.769 seconds) + + +.. _sphx_glr_download_auto_examples_plot_barycenter_1D.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_barycenter_1D.py <plot_barycenter_1D.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_barycenter_1D.ipynb <plot_barycenter_1D.ipynb>` @@ -254,4 +277,4 @@ Barycentric interpolation .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_barycenter_fgw.ipynb b/docs/source/auto_examples/plot_barycenter_fgw.ipynb index 28229b2..4e4704c 100644 --- a/docs/source/auto_examples/plot_barycenter_fgw.ipynb +++ b/docs/source/auto_examples/plot_barycenter_fgw.ipynb @@ -26,7 +26,29 @@ }, "outputs": [], "source": [ - "# Author: Titouan Vayer <titouan.vayer@irisa.fr>\n#\n# License: MIT License\n\n#%% load libraries\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport networkx as nx\nimport math\nfrom scipy.sparse.csgraph import shortest_path\nimport matplotlib.colors as mcol\nfrom matplotlib import cm\nfrom ot.gromov import fgw_barycenters\n#%% Graph functions\n\n\ndef find_thresh(C, inf=0.5, sup=3, step=10):\n \"\"\" Trick to find the adequate thresholds from where value of the C matrix are considered close enough to say that nodes are connected\n Tthe threshold is found by a linesearch between values \"inf\" and \"sup\" with \"step\" thresholds tested.\n The optimal threshold is the one which minimizes the reconstruction error between the shortest_path matrix coming from the thresholded adjency matrix\n and the original matrix.\n Parameters\n ----------\n C : ndarray, shape (n_nodes,n_nodes)\n The structure matrix to threshold\n inf : float\n The beginning of the linesearch\n sup : float\n The end of the linesearch\n step : integer\n Number of thresholds tested\n \"\"\"\n dist = []\n search = np.linspace(inf, sup, step)\n for thresh in search:\n Cprime = sp_to_adjency(C, 0, thresh)\n SC = shortest_path(Cprime, method='D')\n SC[SC == float('inf')] = 100\n dist.append(np.linalg.norm(SC - C))\n return search[np.argmin(dist)], dist\n\n\ndef sp_to_adjency(C, threshinf=0.2, threshsup=1.8):\n \"\"\" Thresholds the structure matrix in order to compute an adjency matrix.\n All values between threshinf and threshsup are considered representing connected nodes and set to 1. Else are set to 0\n Parameters\n ----------\n C : ndarray, shape (n_nodes,n_nodes)\n The structure matrix to threshold\n threshinf : float\n The minimum value of distance from which the new value is set to 1\n threshsup : float\n The maximum value of distance from which the new value is set to 1\n Returns\n -------\n C : ndarray, shape (n_nodes,n_nodes)\n The threshold matrix. Each element is in {0,1}\n \"\"\"\n H = np.zeros_like(C)\n np.fill_diagonal(H, np.diagonal(C))\n C = C - H\n C = np.minimum(np.maximum(C, threshinf), threshsup)\n C[C == threshsup] = 0\n C[C != 0] = 1\n\n return C\n\n\ndef build_noisy_circular_graph(N=20, mu=0, sigma=0.3, with_noise=False, structure_noise=False, p=None):\n \"\"\" Create a noisy circular graph\n \"\"\"\n g = nx.Graph()\n g.add_nodes_from(list(range(N)))\n for i in range(N):\n noise = float(np.random.normal(mu, sigma, 1))\n if with_noise:\n g.add_node(i, attr_name=math.sin((2 * i * math.pi / N)) + noise)\n else:\n g.add_node(i, attr_name=math.sin(2 * i * math.pi / N))\n g.add_edge(i, i + 1)\n if structure_noise:\n randomint = np.random.randint(0, p)\n if randomint == 0:\n if i <= N - 3:\n g.add_edge(i, i + 2)\n if i == N - 2:\n g.add_edge(i, 0)\n if i == N - 1:\n g.add_edge(i, 1)\n g.add_edge(N, 0)\n noise = float(np.random.normal(mu, sigma, 1))\n if with_noise:\n g.add_node(N, attr_name=math.sin((2 * N * math.pi / N)) + noise)\n else:\n g.add_node(N, attr_name=math.sin(2 * N * math.pi / N))\n return g\n\n\ndef graph_colors(nx_graph, vmin=0, vmax=7):\n cnorm = mcol.Normalize(vmin=vmin, vmax=vmax)\n cpick = cm.ScalarMappable(norm=cnorm, cmap='viridis')\n cpick.set_array([])\n val_map = {}\n for k, v in nx.get_node_attributes(nx_graph, 'attr_name').items():\n val_map[k] = cpick.to_rgba(v)\n colors = []\n for node in nx_graph.nodes():\n colors.append(val_map[node])\n return colors" + "# Author: Titouan Vayer <titouan.vayer@irisa.fr>\n#\n# License: MIT License" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\nimport matplotlib.pyplot as plt\nimport networkx as nx\nimport math\nfrom scipy.sparse.csgraph import shortest_path\nimport matplotlib.colors as mcol\nfrom matplotlib import cm\nfrom ot.gromov import fgw_barycenters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def find_thresh(C, inf=0.5, sup=3, step=10):\n \"\"\" Trick to find the adequate thresholds from where value of the C matrix are considered close enough to say that nodes are connected\n Tthe threshold is found by a linesearch between values \"inf\" and \"sup\" with \"step\" thresholds tested.\n The optimal threshold is the one which minimizes the reconstruction error between the shortest_path matrix coming from the thresholded adjency matrix\n and the original matrix.\n Parameters\n ----------\n C : ndarray, shape (n_nodes,n_nodes)\n The structure matrix to threshold\n inf : float\n The beginning of the linesearch\n sup : float\n The end of the linesearch\n step : integer\n Number of thresholds tested\n \"\"\"\n dist = []\n search = np.linspace(inf, sup, step)\n for thresh in search:\n Cprime = sp_to_adjency(C, 0, thresh)\n SC = shortest_path(Cprime, method='D')\n SC[SC == float('inf')] = 100\n dist.append(np.linalg.norm(SC - C))\n return search[np.argmin(dist)], dist\n\n\ndef sp_to_adjency(C, threshinf=0.2, threshsup=1.8):\n \"\"\" Thresholds the structure matrix in order to compute an adjency matrix.\n All values between threshinf and threshsup are considered representing connected nodes and set to 1. Else are set to 0\n Parameters\n ----------\n C : ndarray, shape (n_nodes,n_nodes)\n The structure matrix to threshold\n threshinf : float\n The minimum value of distance from which the new value is set to 1\n threshsup : float\n The maximum value of distance from which the new value is set to 1\n Returns\n -------\n C : ndarray, shape (n_nodes,n_nodes)\n The threshold matrix. Each element is in {0,1}\n \"\"\"\n H = np.zeros_like(C)\n np.fill_diagonal(H, np.diagonal(C))\n C = C - H\n C = np.minimum(np.maximum(C, threshinf), threshsup)\n C[C == threshsup] = 0\n C[C != 0] = 1\n\n return C\n\n\ndef build_noisy_circular_graph(N=20, mu=0, sigma=0.3, with_noise=False, structure_noise=False, p=None):\n \"\"\" Create a noisy circular graph\n \"\"\"\n g = nx.Graph()\n g.add_nodes_from(list(range(N)))\n for i in range(N):\n noise = float(np.random.normal(mu, sigma, 1))\n if with_noise:\n g.add_node(i, attr_name=math.sin((2 * i * math.pi / N)) + noise)\n else:\n g.add_node(i, attr_name=math.sin(2 * i * math.pi / N))\n g.add_edge(i, i + 1)\n if structure_noise:\n randomint = np.random.randint(0, p)\n if randomint == 0:\n if i <= N - 3:\n g.add_edge(i, i + 2)\n if i == N - 2:\n g.add_edge(i, 0)\n if i == N - 1:\n g.add_edge(i, 1)\n g.add_edge(N, 0)\n noise = float(np.random.normal(mu, sigma, 1))\n if with_noise:\n g.add_node(N, attr_name=math.sin((2 * N * math.pi / N)) + noise)\n else:\n g.add_node(N, attr_name=math.sin(2 * N * math.pi / N))\n return g\n\n\ndef graph_colors(nx_graph, vmin=0, vmax=7):\n cnorm = mcol.Normalize(vmin=vmin, vmax=vmax)\n cpick = cm.ScalarMappable(norm=cnorm, cmap='viridis')\n cpick.set_array([])\n val_map = {}\n for k, v in nx.get_node_attributes(nx_graph, 'attr_name').items():\n val_map[k] = cpick.to_rgba(v)\n colors = []\n for node in nx_graph.nodes():\n colors.append(val_map[node])\n return colors" ] }, { @@ -37,6 +59,13 @@ ] }, { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We build a dataset of noisy circular graphs.\nNoise is added on the structures by random connections and on the features by gaussian noise.\n\n" + ] + }, + { "cell_type": "code", "execution_count": null, "metadata": { @@ -44,7 +73,7 @@ }, "outputs": [], "source": [ - "#%% circular dataset\n# We build a dataset of noisy circular graphs.\n# Noise is added on the structures by random connections and on the features by gaussian noise.\n\n\nnp.random.seed(30)\nX0 = []\nfor k in range(9):\n X0.append(build_noisy_circular_graph(np.random.randint(15, 25), with_noise=True, structure_noise=True, p=3))" + "np.random.seed(30)\nX0 = []\nfor k in range(9):\n X0.append(build_noisy_circular_graph(np.random.randint(15, 25), with_noise=True, structure_noise=True, p=3))" ] }, { @@ -62,7 +91,7 @@ }, "outputs": [], "source": [ - "#%% Plot graphs\n\nplt.figure(figsize=(8, 10))\nfor i in range(len(X0)):\n plt.subplot(3, 3, i + 1)\n g = X0[i]\n pos = nx.kamada_kawai_layout(g)\n nx.draw(g, pos=pos, node_color=graph_colors(g, vmin=-1, vmax=1), with_labels=False, node_size=100)\nplt.suptitle('Dataset of noisy graphs. Color indicates the label', fontsize=20)\nplt.show()" + "plt.figure(figsize=(8, 10))\nfor i in range(len(X0)):\n plt.subplot(3, 3, i + 1)\n g = X0[i]\n pos = nx.kamada_kawai_layout(g)\n nx.draw(g, pos=pos, node_color=graph_colors(g, vmin=-1, vmax=1), with_labels=False, node_size=100)\nplt.suptitle('Dataset of noisy graphs. Color indicates the label', fontsize=20)\nplt.show()" ] }, { @@ -73,6 +102,13 @@ ] }, { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Features distances are the euclidean distances\n\n" + ] + }, + { "cell_type": "code", "execution_count": null, "metadata": { @@ -80,7 +116,7 @@ }, "outputs": [], "source": [ - "#%% We compute the barycenter using FGW. Structure matrices are computed using the shortest_path distance in the graph\n# Features distances are the euclidean distances\nCs = [shortest_path(nx.adjacency_matrix(x)) for x in X0]\nps = [np.ones(len(x.nodes())) / len(x.nodes()) for x in X0]\nYs = [np.array([v for (k, v) in nx.get_node_attributes(x, 'attr_name').items()]).reshape(-1, 1) for x in X0]\nlambdas = np.array([np.ones(len(Ys)) / len(Ys)]).ravel()\nsizebary = 15 # we choose a barycenter with 15 nodes\n\nA, C, log = fgw_barycenters(sizebary, Ys, Cs, ps, lambdas, alpha=0.95, log=True)" + "Cs = [shortest_path(nx.adjacency_matrix(x)) for x in X0]\nps = [np.ones(len(x.nodes())) / len(x.nodes()) for x in X0]\nYs = [np.array([v for (k, v) in nx.get_node_attributes(x, 'attr_name').items()]).reshape(-1, 1) for x in X0]\nlambdas = np.array([np.ones(len(Ys)) / len(Ys)]).ravel()\nsizebary = 15 # we choose a barycenter with 15 nodes\n\nA, C, log = fgw_barycenters(sizebary, Ys, Cs, ps, lambdas, alpha=0.95, log=True)" ] }, { @@ -98,7 +134,18 @@ }, "outputs": [], "source": [ - "#%% Create the barycenter\nbary = nx.from_numpy_matrix(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0]))\nfor i, v in enumerate(A.ravel()):\n bary.add_node(i, attr_name=v)\n\n#%%\npos = nx.kamada_kawai_layout(bary)\nnx.draw(bary, pos=pos, node_color=graph_colors(bary, vmin=-1, vmax=1), with_labels=False)\nplt.suptitle('Barycenter', fontsize=20)\nplt.show()" + "bary = nx.from_numpy_matrix(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0]))\nfor i, v in enumerate(A.ravel()):\n bary.add_node(i, attr_name=v)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pos = nx.kamada_kawai_layout(bary)\nnx.draw(bary, pos=pos, node_color=graph_colors(bary, vmin=-1, vmax=1), with_labels=False)\nplt.suptitle('Barycenter', fontsize=20)\nplt.show()" ] } ], @@ -118,7 +165,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_barycenter_fgw.rst b/docs/source/auto_examples/plot_barycenter_fgw.rst index 2c44a65..ad4c275 100644 --- a/docs/source/auto_examples/plot_barycenter_fgw.rst +++ b/docs/source/auto_examples/plot_barycenter_fgw.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_barycenter_fgw.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_barycenter_fgw.py: + .. _sphx_glr_auto_examples_plot_barycenter_fgw.py: ================================= @@ -18,15 +24,23 @@ Requires networkx >=2 - -.. code-block:: python +.. code-block:: default # Author: Titouan Vayer <titouan.vayer@irisa.fr> # # License: MIT License - #%% load libraries + + + + + + + + +.. code-block:: default + import numpy as np import matplotlib.pyplot as plt import networkx as nx @@ -35,7 +49,16 @@ Requires networkx >=2 import matplotlib.colors as mcol from matplotlib import cm from ot.gromov import fgw_barycenters - #%% Graph functions + + + + + + + + +.. code-block:: default + def find_thresh(C, inf=0.5, sup=3, step=10): @@ -138,17 +161,16 @@ Requires networkx >=2 + Generate data ------------- +We build a dataset of noisy circular graphs. +Noise is added on the structures by random connections and on the features by gaussian noise. -.. code-block:: python - +.. code-block:: default - #%% circular dataset - # We build a dataset of noisy circular graphs. - # Noise is added on the structures by random connections and on the features by gaussian noise. np.random.seed(30) @@ -162,15 +184,13 @@ Generate data + Plot data --------- +.. code-block:: default -.. code-block:: python - - - #%% Plot graphs plt.figure(figsize=(8, 10)) for i in range(len(X0)): @@ -185,7 +205,17 @@ Plot data .. image:: /auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png - :align: center + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_barycenter_fgw.py:155: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + plt.show() @@ -193,13 +223,11 @@ Plot data Barycenter computation ---------------------- +Features distances are the euclidean distances -.. code-block:: python +.. code-block:: default - - #%% We compute the barycenter using FGW. Structure matrices are computed using the shortest_path distance in the graph - # Features distances are the euclidean distances Cs = [shortest_path(nx.adjacency_matrix(x)) for x in X0] ps = [np.ones(len(x.nodes())) / len(x.nodes()) for x in X0] Ys = [np.array([v for (k, v) in nx.get_node_attributes(x, 'attr_name').items()]).reshape(-1, 1) for x in X0] @@ -214,20 +242,27 @@ Barycenter computation + Plot Barycenter ------------------------- +.. code-block:: default -.. code-block:: python - - - #%% Create the barycenter bary = nx.from_numpy_matrix(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0])) for i, v in enumerate(A.ravel()): bary.add_node(i, attr_name=v) - #%% + + + + + + + + +.. code-block:: default + pos = nx.kamada_kawai_layout(bary) nx.draw(bary, pos=pos, node_color=graph_colors(bary, vmin=-1, vmax=1), with_labels=False) plt.suptitle('Barycenter', fontsize=20) @@ -236,27 +271,44 @@ Plot Barycenter .. image:: /auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png - :align: center + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_barycenter_fgw.py:184: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + plt.show() -**Total running time of the script:** ( 0 minutes 2.065 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.949 seconds) + + +.. _sphx_glr_download_auto_examples_plot_barycenter_fgw.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_barycenter_fgw.py <plot_barycenter_fgw.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_barycenter_fgw.ipynb <plot_barycenter_fgw.ipynb>` @@ -265,4 +317,4 @@ Plot Barycenter .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb index 2199162..b976aae 100644 --- a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb +++ b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.ipynb @@ -44,7 +44,69 @@ }, "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]])" + "problems = []\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\n# Gaussian distributions\na1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.make_1D_gauss(n, m=60, s=8)\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "alpha = 0.5 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\not.tic()\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\not.toc()\n\n\not.tic()\nbary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True)\not.toc()\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\npl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()\n\nproblems.append([A, [bary_l2, bary_wass, bary_wass2]])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Stair Data\n----------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "a1 = 1.0 * (x > 10) * (x < 50)\na2 = 1.0 * (x > 60) * (x < 80)\n\na1 /= a1.sum()\na2 /= a2.sum()\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "alpha = 0.5 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\not.tic()\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\not.toc()\n\n\not.tic()\nbary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True)\not.toc()\n\n\nproblems.append([A, [bary_l2, bary_wass, bary_wass2]])\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\npl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" ] }, { @@ -62,7 +124,29 @@ }, "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()" + "a1 = np.zeros(n)\na2 = np.zeros(n)\n\na1[10] = .25\na1[20] = .5\na1[30] = .25\na2[80] = 1\n\n\na1 /= a1.sum()\na2 /= a2.sum()\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "alpha = 0.5 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\not.tic()\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\not.toc()\n\n\not.tic()\nbary_wass2 = ot.lp.barycenter(A, M, weights, solver='interior-point', verbose=True)\not.toc()\n\n\nproblems.append([A, [bary_l2, bary_wass, bary_wass2]])\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\npl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()" ] }, { @@ -80,7 +164,7 @@ }, "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(())" + "nbm = len(problems)\nnbm2 = (nbm // 2)\n\n\npl.figure(2, (20, 6))\npl.clf()\n\nfor i in range(nbm):\n\n A = problems[i][0]\n bary_l2 = problems[i][1][0]\n bary_wass = problems[i][1][1]\n bary_wass2 = problems[i][1][2]\n\n pl.subplot(2, nbm, 1 + i)\n for j in range(n_distributions):\n pl.plot(x, A[:, j])\n if i == nbm2:\n pl.title('Distributions')\n pl.xticks(())\n pl.yticks(())\n\n pl.subplot(2, nbm, 1 + i + nbm)\n\n pl.plot(x, bary_l2, 'r', label='L2 (Euclidean)')\n pl.plot(x, bary_wass, 'g', label='Reg Wasserstein')\n pl.plot(x, bary_wass2, 'b', label='LP Wasserstein')\n if i == nbm - 1:\n pl.legend()\n if i == nbm2:\n pl.title('Barycenters')\n\n pl.xticks(())\n pl.yticks(())" ] } ], @@ -100,7 +184,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py index b82765e..d7c72d0 100644 --- a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py +++ b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.py @@ -102,7 +102,7 @@ pl.tight_layout() problems.append([A, [bary_l2, bary_wass, bary_wass2]]) ############################################################################## -# Dirac Data +# Stair Data # ---------- #%% parameters @@ -168,6 +168,11 @@ pl.legend() pl.title('Barycenters') pl.tight_layout() + +############################################################################## +# Dirac Data +# ---------- + #%% parameters a1 = np.zeros(n) diff --git a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst index bd1c710..5e83fbf 100644 --- a/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst +++ b/docs/source/auto_examples/plot_barycenter_lp_vs_entropic.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_barycenter_lp_vs_entropic.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_barycenter_lp_vs_entropic.py: + .. _sphx_glr_auto_examples_plot_barycenter_lp_vs_entropic.py: ================================================================================= @@ -20,8 +26,7 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138. - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -43,15 +48,13 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138. + Gaussian Data ------------- +.. code-block:: default -.. code-block:: python - - - #%% parameters problems = [] @@ -74,7 +77,16 @@ Gaussian Data M /= M.max() - #%% plot the distributions + + + + + + + + +.. code-block:: default + pl.figure(1, figsize=(6.4, 3)) for i in range(n_distributions): @@ -82,7 +94,19 @@ Gaussian Data pl.title('Distributions') pl.tight_layout() - #%% barycenter computation + + + +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_001.png + :class: sphx-glr-single-img + + + + + + +.. code-block:: default + alpha = 0.5 # 0<=alpha<=1 weights = np.array([1 - alpha, alpha]) @@ -121,62 +145,55 @@ Gaussian Data -.. 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 +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_002.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none - Elapsed time : 0.010712385177612305 s + Elapsed time : 0.0049059391021728516 s Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective 1.0 1.0 1.0 - 1.0 1700.336700337 - 0.006776453137632 0.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 + 0.006776453137632 0.006776453137632 0.006776453137632 0.9932238647293 0.006776453137632 125.6700527543 + 0.004018712867873 0.004018712867873 0.004018712867873 0.4301142633001 0.004018712867873 12.26594150092 + 0.001172775061627 0.001172775061627 0.001172775061627 0.7599932455027 0.001172775061627 0.3378536968898 + 0.0004375137005386 0.0004375137005386 0.0004375137005386 0.6422331807989 0.0004375137005386 0.1468420566359 + 0.0002326690467339 0.0002326690467339 0.0002326690467339 0.5016999460898 0.0002326690467339 0.09381703231428 + 7.430121674299e-05 7.4301216743e-05 7.430121674299e-05 0.7035962305811 7.430121674299e-05 0.05777870257169 + 5.321227838943e-05 5.321227838945e-05 5.321227838944e-05 0.3087841864307 5.321227838944e-05 0.05266249477219 + 1.990900379216e-05 1.99090037922e-05 1.990900379216e-05 0.6520472013271 1.990900379216e-05 0.04526054405523 + 6.305442046834e-06 6.305442046856e-06 6.305442046837e-06 0.7073953304085 6.305442046837e-06 0.04237597591384 + 2.290148391591e-06 2.290148391631e-06 2.290148391602e-06 0.6941812711476 2.29014839161e-06 0.04152284932101 + 1.182864875578e-06 1.182864875548e-06 1.182864875555e-06 0.5084552046229 1.182864875567e-06 0.04129461872829 + 3.626786386894e-07 3.626786386985e-07 3.626786386845e-07 0.7101651569095 3.626786385995e-07 0.0411303244893 + 1.539754244475e-07 1.539754247164e-07 1.539754247197e-07 0.6279322077522 1.539754251915e-07 0.04108867636377 + 5.193221608537e-08 5.19322169648e-08 5.193221696942e-08 0.6843453280956 5.193221892276e-08 0.04106859618454 + 1.888205219929e-08 1.88820500654e-08 1.888205006369e-08 0.6673443828803 1.888205852187e-08 0.04106214175236 + 5.676837529301e-09 5.676842740457e-09 5.676842761502e-09 0.7281712198286 5.676877044229e-09 0.04105958648535 + 3.501170987746e-09 3.501167688027e-09 3.501167721804e-09 0.4140142115019 3.501183058995e-09 0.04105916265728 + 1.110582426269e-09 1.110580273241e-09 1.110580239523e-09 0.6999003212726 1.110624310022e-09 0.04105870073273 + 5.768753963318e-10 5.769422203363e-10 5.769421938248e-10 0.5002521235315 5.767522037401e-10 0.04105859764872 + 1.534102102874e-10 1.535920569433e-10 1.535921107494e-10 0.7516900610544 1.535251083958e-10 0.04105851678411 + 6.717475002202e-11 6.735435784522e-11 6.735430717133e-11 0.5944268235824 6.732253215483e-11 0.04105850033323 + 1.751321118837e-11 1.74043080851e-11 1.740429001123e-11 0.7566075167358 1.736956306927e-11 0.0410584908946 Optimization terminated successfully. - Elapsed time : 2.883899211883545 s + Current function value: 0.041058 + Iterations: 22 + Elapsed time : 2.149055242538452 s -Dirac Data ----------- +Stair Data +---------- -.. code-block:: python +.. code-block:: default - #%% parameters a1 = 1.0 * (x > 10) * (x < 50) a2 = 1.0 * (x > 60) * (x < 80) @@ -193,7 +210,16 @@ Dirac Data M /= M.max() - #%% plot the distributions + + + + + + + + +.. code-block:: default + pl.figure(1, figsize=(6.4, 3)) for i in range(n_distributions): @@ -202,7 +228,19 @@ Dirac Data pl.tight_layout() - #%% barycenter computation + + + +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_003.png + :class: sphx-glr-single-img + + + + + + +.. code-block:: default + alpha = 0.5 # 0<=alpha<=1 weights = np.array([1 - alpha, alpha]) @@ -239,7 +277,50 @@ Dirac Data pl.title('Barycenters') pl.tight_layout() - #%% parameters + + + + +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_004.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + Elapsed time : 0.008316993713378906 s + Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective + 1.0 1.0 1.0 - 1.0 1700.336700337 + 0.006776466288938 0.006776466288938 0.006776466288938 0.9932238515788 0.006776466288938 125.66492558 + 0.004036918865472 0.004036918865472 0.004036918865472 0.4272973099325 0.004036918865472 12.347161701 + 0.001219232687076 0.001219232687076 0.001219232687076 0.7496986855957 0.001219232687076 0.3243835647418 + 0.0003837422984467 0.0003837422984467 0.0003837422984467 0.6926882608271 0.0003837422984467 0.1361719397498 + 0.0001070128410194 0.0001070128410194 0.0001070128410194 0.7643889137854 0.0001070128410194 0.07581952832542 + 0.0001001275033713 0.0001001275033714 0.0001001275033713 0.07058704838615 0.0001001275033713 0.07347394936346 + 4.550897507807e-05 4.550897507807e-05 4.550897507807e-05 0.576117248486 4.550897507807e-05 0.05555077655034 + 8.557124125834e-06 8.557124125853e-06 8.557124125835e-06 0.853592544106 8.557124125835e-06 0.0443981466023 + 3.611995628666e-06 3.611995628643e-06 3.611995628672e-06 0.6002277331398 3.611995628673e-06 0.0428300776216 + 7.590393750111e-07 7.590393750273e-07 7.590393750129e-07 0.8221486533655 7.590393750133e-07 0.04192322976247 + 8.299929287077e-08 8.299929283415e-08 8.299929287126e-08 0.901746793884 8.299929287181e-08 0.04170825633295 + 3.117560207452e-10 3.117560192413e-10 3.117560199213e-10 0.9970399692253 3.117560200234e-10 0.04168179329766 + 1.559774508975e-14 1.559825507727e-14 1.559755309294e-14 0.9999499686993 1.559748033629e-14 0.04168169240444 + Optimization terminated successfully. + Current function value: 0.041682 + Iterations: 13 + Elapsed time : 2.0333712100982666 s + + + + +Dirac Data +---------- + + +.. code-block:: default + a1 = np.zeros(n) a2 = np.zeros(n) @@ -262,7 +343,16 @@ Dirac Data M /= M.max() - #%% plot the distributions + + + + + + + + +.. code-block:: default + pl.figure(1, figsize=(6.4, 3)) for i in range(n_distributions): @@ -271,7 +361,19 @@ Dirac Data pl.tight_layout() - #%% barycenter computation + + + +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_005.png + :class: sphx-glr-single-img + + + + + + +.. code-block:: default + alpha = 0.5 # 0<=alpha<=1 weights = np.array([1 - alpha, alpha]) @@ -312,70 +414,45 @@ Dirac Data -.. 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 +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: + 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 + .. code-block:: none + + Elapsed time : 0.001787424087524414 s Primal Feasibility Dual Feasibility Duality Gap Step Path Parameter Objective 1.0 1.0 1.0 - 1.0 1700.336700337 - 0.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 + 0.00677467552072 0.006774675520719 0.006774675520719 0.9932256422636 0.006774675520719 125.6956034741 + 0.002048208707556 0.002048208707555 0.002048208707555 0.734309536815 0.002048208707555 5.213991622102 + 0.0002697365474791 0.0002697365474791 0.0002697365474791 0.8839403501183 0.0002697365474791 0.5059383903908 + 6.832109993919e-05 6.832109993918e-05 6.832109993918e-05 0.7601171075982 6.832109993918e-05 0.2339657807271 + 2.437682932221e-05 2.437682932221e-05 2.437682932221e-05 0.6663448297463 2.437682932221e-05 0.1471256246325 + 1.134983216308e-05 1.134983216308e-05 1.134983216308e-05 0.5553643816417 1.134983216308e-05 0.1181584941171 + 3.342312725863e-06 3.34231272585e-06 3.342312725863e-06 0.7238133571629 3.342312725863e-06 0.1006387519746 + 7.078561231536e-07 7.078561231537e-07 7.078561231535e-07 0.803314255252 7.078561231535e-07 0.09474734646268 + 1.966870949422e-07 1.966870952674e-07 1.966870952717e-07 0.7525479180433 1.966870953014e-07 0.09354342735758 + 4.199895266495e-10 4.199895367352e-10 4.19989526535e-10 0.9984019849265 4.199895265747e-10 0.09310367785861 + 2.101053559204e-14 2.100331212975e-14 2.101054034304e-14 0.9999499736903 2.101053604307e-14 0.09310274466458 Optimization terminated successfully. - Elapsed time : 2.690450668334961 s + Current function value: 0.093103 + Iterations: 11 + Elapsed time : 2.1853578090667725 s -Final figure ------------- +Final figure +------------ -.. code-block:: python +.. code-block:: default - #%% plot nbm = len(problems) nbm2 = (nbm // 2) @@ -414,28 +491,36 @@ Final figure -.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_006.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_barycenter_lp_vs_entropic_007.png + :class: sphx-glr-single-img + + -**Total running time of the script:** ( 0 minutes 8.892 seconds) +.. rst-class:: sphx-glr-timing + **Total running time of the script:** ( 0 minutes 7.697 seconds) + + +.. _sphx_glr_download_auto_examples_plot_barycenter_lp_vs_entropic.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_barycenter_lp_vs_entropic.py <plot_barycenter_lp_vs_entropic.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_barycenter_lp_vs_entropic.ipynb <plot_barycenter_lp_vs_entropic.ipynb>` @@ -444,4 +529,4 @@ Final figure .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_compute_emd.ipynb b/docs/source/auto_examples/plot_compute_emd.ipynb index 562eff8..24a2fff 100644 --- a/docs/source/auto_examples/plot_compute_emd.ipynb +++ b/docs/source/auto_examples/plot_compute_emd.ipynb @@ -44,7 +44,7 @@ }, "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()" + "n = 100 # nb bins\nn_target = 50 # nb target distributions\n\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\nlst_m = np.linspace(20, 90, n_target)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\n\nB = np.zeros((n, n_target))\n\nfor i, m in enumerate(lst_m):\n B[:, i] = gauss(n, m=m, s=5)\n\n# loss matrix and normalization\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'euclidean')\nM /= M.max()\nM2 = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)), 'sqeuclidean')\nM2 /= M2.max()" ] }, { @@ -62,7 +62,7 @@ }, "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()" + "pl.figure(1)\npl.subplot(2, 1, 1)\npl.plot(x, a, 'b', label='Source distribution')\npl.title('Source distribution')\npl.subplot(2, 1, 2)\npl.plot(x, B, label='Target distributions')\npl.title('Target distributions')\npl.tight_layout()" ] }, { @@ -80,7 +80,7 @@ }, "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()" + "d_emd = ot.emd2(a, B, M) # direct computation of EMD\nd_emd2 = ot.emd2(a, B, M2) # direct computation of EMD with loss M2\n\n\npl.figure(2)\npl.plot(d_emd, label='Euclidean EMD')\npl.plot(d_emd2, label='Squared Euclidean EMD')\npl.title('EMD distances')\npl.legend()" ] }, { @@ -98,7 +98,7 @@ }, "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()" + "reg = 1e-2\nd_sinkhorn = ot.sinkhorn2(a, B, M, reg)\nd_sinkhorn2 = ot.sinkhorn2(a, B, M2, reg)\n\npl.figure(2)\npl.clf()\npl.plot(d_emd, label='Euclidean EMD')\npl.plot(d_emd2, label='Squared Euclidean EMD')\npl.plot(d_sinkhorn, '+', label='Euclidean Sinkhorn')\npl.plot(d_sinkhorn2, '+', label='Squared Euclidean Sinkhorn')\npl.title('EMD distances')\npl.legend()\n\npl.show()" ] } ], @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_compute_emd.rst b/docs/source/auto_examples/plot_compute_emd.rst index 27bca2c..e4cc143 100644 --- a/docs/source/auto_examples/plot_compute_emd.rst +++ b/docs/source/auto_examples/plot_compute_emd.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_compute_emd.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_compute_emd.py: + .. _sphx_glr_auto_examples_plot_compute_emd.py: ================= @@ -13,8 +19,7 @@ ground metrics and plot their values for diffeent distributions. - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -33,15 +38,13 @@ ground metrics and plot their values for diffeent distributions. + Generate data ------------- +.. code-block:: default -.. code-block:: python - - - #%% parameters n = 100 # nb bins n_target = 50 # nb target distributions @@ -72,16 +75,14 @@ Generate data + Plot data --------- - -.. code-block:: python +.. code-block:: default - #%% plot the distributions - pl.figure(1) pl.subplot(2, 1, 1) pl.plot(x, a, 'b', label='Source distribution') @@ -96,7 +97,8 @@ Plot data .. image:: /auto_examples/images/sphx_glr_plot_compute_emd_001.png - :align: center + :class: sphx-glr-single-img + @@ -105,11 +107,8 @@ Compute EMD for the different losses ------------------------------------ +.. code-block:: default -.. code-block:: python - - - #%% Compute and plot distributions and loss matrix d_emd = ot.emd2(a, B, M) # direct computation of EMD d_emd2 = ot.emd2(a, B, M2) # direct computation of EMD with loss M2 @@ -124,21 +123,27 @@ Compute EMD for the different losses -.. image:: /auto_examples/images/sphx_glr_plot_compute_emd_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_compute_emd_002.png + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + Out: -Compute Sinkhorn for the different losses ------------------------------------------ + .. code-block:: none + <matplotlib.legend.Legend object at 0x7f4c7389f438> -.. code-block:: python - #%% +Compute Sinkhorn for the different losses +----------------------------------------- + + +.. code-block:: default + reg = 1e-2 d_sinkhorn = ot.sinkhorn2(a, B, M, reg) d_sinkhorn2 = ot.sinkhorn2(a, B, M2, reg) @@ -156,28 +161,45 @@ Compute Sinkhorn for the different losses -.. image:: /auto_examples/images/sphx_glr_plot_compute_emd_004.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_compute_emd_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + Out: + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_compute_emd.py:102: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 0 minutes 0.446 seconds) + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.436 seconds) + + +.. _sphx_glr_download_auto_examples_plot_compute_emd.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_compute_emd.py <plot_compute_emd.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_compute_emd.ipynb <plot_compute_emd.ipynb>` @@ -186,4 +208,4 @@ Compute Sinkhorn for the different losses .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_convolutional_barycenter.ipynb b/docs/source/auto_examples/plot_convolutional_barycenter.ipynb index 4981ba3..f94a32e 100644 --- a/docs/source/auto_examples/plot_convolutional_barycenter.ipynb +++ b/docs/source/auto_examples/plot_convolutional_barycenter.ipynb @@ -82,7 +82,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_convolutional_barycenter.rst b/docs/source/auto_examples/plot_convolutional_barycenter.rst index a28db2f..9c9a596 100644 --- a/docs/source/auto_examples/plot_convolutional_barycenter.rst +++ b/docs/source/auto_examples/plot_convolutional_barycenter.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_convolutional_barycenter.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_convolutional_barycenter.py: + .. _sphx_glr_auto_examples_plot_convolutional_barycenter.py: ============================================ @@ -11,8 +17,7 @@ This example is designed to illustrate how the Convolutional Wasserstein Barycen function of POT works. - -.. code-block:: python +.. code-block:: default # Author: Nicolas Courty <ncourty@irisa.fr> @@ -30,14 +35,14 @@ function of POT works. + Data preparation ---------------- The four distributions are constructed from 4 simple images - -.. code-block:: python +.. code-block:: default @@ -73,13 +78,13 @@ The four distributions are constructed from 4 simple images + Barycenter computation and visualization ---------------------------------------- - -.. code-block:: python +.. code-block:: default pl.figure(figsize=(10, 10)) @@ -119,27 +124,44 @@ Barycenter computation and visualization .. image:: /auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png - :align: center + :class: sphx-glr-single-img + +.. rst-class:: sphx-glr-script-out + Out: + .. code-block:: none -**Total running time of the script:** ( 1 minutes 11.608 seconds) + /home/rflamary/PYTHON/POT/examples/plot_convolutional_barycenter.py:92: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 34.615 seconds) + + +.. _sphx_glr_download_auto_examples_plot_convolutional_barycenter.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_convolutional_barycenter.py <plot_convolutional_barycenter.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_convolutional_barycenter.ipynb <plot_convolutional_barycenter.ipynb>` @@ -148,4 +170,4 @@ Barycenter computation and visualization .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_fgw.ipynb b/docs/source/auto_examples/plot_fgw.ipynb index 1b150bd..20c0a3f 100644 --- a/docs/source/auto_examples/plot_fgw.ipynb +++ b/docs/source/auto_examples/plot_fgw.ipynb @@ -37,6 +37,13 @@ ] }, { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We create two 1D random measures\n\n" + ] + }, + { "cell_type": "code", "execution_count": null, "metadata": { @@ -44,7 +51,7 @@ }, "outputs": [], "source": [ - "#%% parameters\n# We create two 1D random measures\nn = 20 # number of points in the first distribution\nn2 = 30 # number of points in the second distribution\nsig = 1 # std of first distribution\nsig2 = 0.1 # std of second distribution\n\nnp.random.seed(0)\n\nphi = np.arange(n)[:, None]\nxs = phi + sig * np.random.randn(n, 1)\nys = np.vstack((np.ones((n // 2, 1)), 0 * np.ones((n // 2, 1)))) + sig2 * np.random.randn(n, 1)\n\nphi2 = np.arange(n2)[:, None]\nxt = phi2 + sig * np.random.randn(n2, 1)\nyt = np.vstack((np.ones((n2 // 2, 1)), 0 * np.ones((n2 // 2, 1)))) + sig2 * np.random.randn(n2, 1)\nyt = yt[::-1, :]\n\np = ot.unif(n)\nq = ot.unif(n2)" + "n = 20 # number of points in the first distribution\nn2 = 30 # number of points in the second distribution\nsig = 1 # std of first distribution\nsig2 = 0.1 # std of second distribution\n\nnp.random.seed(0)\n\nphi = np.arange(n)[:, None]\nxs = phi + sig * np.random.randn(n, 1)\nys = np.vstack((np.ones((n // 2, 1)), 0 * np.ones((n // 2, 1)))) + sig2 * np.random.randn(n, 1)\n\nphi2 = np.arange(n2)[:, None]\nxt = phi2 + sig * np.random.randn(n2, 1)\nyt = np.vstack((np.ones((n2 // 2, 1)), 0 * np.ones((n2 // 2, 1)))) + sig2 * np.random.randn(n2, 1)\nyt = yt[::-1, :]\n\np = ot.unif(n)\nq = ot.unif(n2)" ] }, { @@ -62,7 +69,7 @@ }, "outputs": [], "source": [ - "#%% plot the distributions\n\npl.close(10)\npl.figure(10, (7, 7))\n\npl.subplot(2, 1, 1)\n\npl.scatter(ys, xs, c=phi, s=70)\npl.ylabel('Feature value a', fontsize=20)\npl.title('$\\mu=\\sum_i \\delta_{x_i,a_i}$', fontsize=25, usetex=True, y=1)\npl.xticks(())\npl.yticks(())\npl.subplot(2, 1, 2)\npl.scatter(yt, xt, c=phi2, s=70)\npl.xlabel('coordinates x/y', fontsize=25)\npl.ylabel('Feature value b', fontsize=20)\npl.title('$\\\\nu=\\sum_j \\delta_{y_j,b_j}$', fontsize=25, usetex=True, y=1)\npl.yticks(())\npl.tight_layout()\npl.show()" + "pl.close(10)\npl.figure(10, (7, 7))\n\npl.subplot(2, 1, 1)\n\npl.scatter(ys, xs, c=phi, s=70)\npl.ylabel('Feature value a', fontsize=20)\npl.title('$\\mu=\\sum_i \\delta_{x_i,a_i}$', fontsize=25, usetex=True, y=1)\npl.xticks(())\npl.yticks(())\npl.subplot(2, 1, 2)\npl.scatter(yt, xt, c=phi2, s=70)\npl.xlabel('coordinates x/y', fontsize=25)\npl.ylabel('Feature value b', fontsize=20)\npl.title('$\\\\nu=\\sum_j \\delta_{y_j,b_j}$', fontsize=25, usetex=True, y=1)\npl.yticks(())\npl.tight_layout()\npl.show()" ] }, { @@ -80,7 +87,7 @@ }, "outputs": [], "source": [ - "#%% Structure matrices and across-features distance matrix\nC1 = ot.dist(xs)\nC2 = ot.dist(xt)\nM = ot.dist(ys, yt)\nw1 = ot.unif(C1.shape[0])\nw2 = ot.unif(C2.shape[0])\nGot = ot.emd([], [], M)" + "C1 = ot.dist(xs)\nC2 = ot.dist(xt)\nM = ot.dist(ys, yt)\nw1 = ot.unif(C1.shape[0])\nw2 = ot.unif(C2.shape[0])\nGot = ot.emd([], [], M)" ] }, { @@ -98,7 +105,7 @@ }, "outputs": [], "source": [ - "#%%\ncmap = 'Reds'\npl.close(10)\npl.figure(10, (5, 5))\nfs = 15\nl_x = [0, 5, 10, 15]\nl_y = [0, 5, 10, 15, 20, 25]\ngs = pl.GridSpec(5, 5)\n\nax1 = pl.subplot(gs[3:, :2])\n\npl.imshow(C1, cmap=cmap, interpolation='nearest')\npl.title(\"$C_1$\", fontsize=fs)\npl.xlabel(\"$k$\", fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\npl.xticks(l_x)\npl.yticks(l_x)\n\nax2 = pl.subplot(gs[:3, 2:])\n\npl.imshow(C2, cmap=cmap, interpolation='nearest')\npl.title(\"$C_2$\", fontsize=fs)\npl.ylabel(\"$l$\", fontsize=fs)\n#pl.ylabel(\"$l$\",fontsize=fs)\npl.xticks(())\npl.yticks(l_y)\nax2.set_aspect('auto')\n\nax3 = pl.subplot(gs[3:, 2:], sharex=ax2, sharey=ax1)\npl.imshow(M, cmap=cmap, interpolation='nearest')\npl.yticks(l_x)\npl.xticks(l_y)\npl.ylabel(\"$i$\", fontsize=fs)\npl.title(\"$M_{AB}$\", fontsize=fs)\npl.xlabel(\"$j$\", fontsize=fs)\npl.tight_layout()\nax3.set_aspect('auto')\npl.show()" + "cmap = 'Reds'\npl.close(10)\npl.figure(10, (5, 5))\nfs = 15\nl_x = [0, 5, 10, 15]\nl_y = [0, 5, 10, 15, 20, 25]\ngs = pl.GridSpec(5, 5)\n\nax1 = pl.subplot(gs[3:, :2])\n\npl.imshow(C1, cmap=cmap, interpolation='nearest')\npl.title(\"$C_1$\", fontsize=fs)\npl.xlabel(\"$k$\", fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\npl.xticks(l_x)\npl.yticks(l_x)\n\nax2 = pl.subplot(gs[:3, 2:])\n\npl.imshow(C2, cmap=cmap, interpolation='nearest')\npl.title(\"$C_2$\", fontsize=fs)\npl.ylabel(\"$l$\", fontsize=fs)\n#pl.ylabel(\"$l$\",fontsize=fs)\npl.xticks(())\npl.yticks(l_y)\nax2.set_aspect('auto')\n\nax3 = pl.subplot(gs[3:, 2:], sharex=ax2, sharey=ax1)\npl.imshow(M, cmap=cmap, interpolation='nearest')\npl.yticks(l_x)\npl.xticks(l_y)\npl.ylabel(\"$i$\", fontsize=fs)\npl.title(\"$M_{AB}$\", fontsize=fs)\npl.xlabel(\"$j$\", fontsize=fs)\npl.tight_layout()\nax3.set_aspect('auto')\npl.show()" ] }, { @@ -116,7 +123,7 @@ }, "outputs": [], "source": [ - "#%% Computing FGW and GW\nalpha = 1e-3\n\not.tic()\nGwg, logw = fused_gromov_wasserstein(M, C1, C2, p, q, loss_fun='square_loss', alpha=alpha, verbose=True, log=True)\not.toc()\n\n#%reload_ext WGW\nGg, log = gromov_wasserstein(C1, C2, p, q, loss_fun='square_loss', verbose=True, log=True)" + "alpha = 1e-3\n\not.tic()\nGwg, logw = fused_gromov_wasserstein(M, C1, C2, p, q, loss_fun='square_loss', alpha=alpha, verbose=True, log=True)\not.toc()\n\n#%reload_ext WGW\nGg, log = gromov_wasserstein(C1, C2, p, q, loss_fun='square_loss', verbose=True, log=True)" ] }, { @@ -134,7 +141,7 @@ }, "outputs": [], "source": [ - "#%% visu OT matrix\ncmap = 'Blues'\nfs = 15\npl.figure(2, (13, 5))\npl.clf()\npl.subplot(1, 3, 1)\npl.imshow(Got, cmap=cmap, interpolation='nearest')\n#pl.xlabel(\"$y$\",fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\npl.xticks(())\n\npl.title('Wasserstein ($M$ only)')\n\npl.subplot(1, 3, 2)\npl.imshow(Gg, cmap=cmap, interpolation='nearest')\npl.title('Gromov ($C_1,C_2$ only)')\npl.xticks(())\npl.subplot(1, 3, 3)\npl.imshow(Gwg, cmap=cmap, interpolation='nearest')\npl.title('FGW ($M+C_1,C_2$)')\n\npl.xlabel(\"$j$\", fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\n\npl.tight_layout()\npl.show()" + "cmap = 'Blues'\nfs = 15\npl.figure(2, (13, 5))\npl.clf()\npl.subplot(1, 3, 1)\npl.imshow(Got, cmap=cmap, interpolation='nearest')\n#pl.xlabel(\"$y$\",fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\npl.xticks(())\n\npl.title('Wasserstein ($M$ only)')\n\npl.subplot(1, 3, 2)\npl.imshow(Gg, cmap=cmap, interpolation='nearest')\npl.title('Gromov ($C_1,C_2$ only)')\npl.xticks(())\npl.subplot(1, 3, 3)\npl.imshow(Gwg, cmap=cmap, interpolation='nearest')\npl.title('FGW ($M+C_1,C_2$)')\n\npl.xlabel(\"$j$\", fontsize=fs)\npl.ylabel(\"$i$\", fontsize=fs)\n\npl.tight_layout()\npl.show()" ] } ], @@ -154,7 +161,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_fgw.rst b/docs/source/auto_examples/plot_fgw.rst index aec725d..1c81d10 100644 --- a/docs/source/auto_examples/plot_fgw.rst +++ b/docs/source/auto_examples/plot_fgw.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_fgw.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_fgw.py: + .. _sphx_glr_auto_examples_plot_fgw.py: ============================== @@ -16,8 +22,7 @@ This example illustrates the computation of FGW for 1D measures[18]. - -.. code-block:: python +.. code-block:: default # Author: Titouan Vayer <titouan.vayer@irisa.fr> @@ -35,16 +40,15 @@ This example illustrates the computation of FGW for 1D measures[18]. + Generate data --------- +We create two 1D random measures -.. code-block:: python - +.. code-block:: default - #%% parameters - # We create two 1D random measures n = 20 # number of points in the first distribution n2 = 30 # number of points in the second distribution sig = 1 # std of first distribution @@ -70,15 +74,13 @@ Generate data + Plot data --------- +.. code-block:: default -.. code-block:: python - - - #%% plot the distributions pl.close(10) pl.figure(10, (7, 7)) @@ -102,21 +104,28 @@ Plot data -.. image:: /auto_examples/images/sphx_glr_plot_fgw_010.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_fgw_001.png + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + Out: -Create structure matrices and across-feature distance matrix ---------- + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_fgw.py:73: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -.. code-block:: python - #%% Structure matrices and across-features distance matrix +Create structure matrices and across-feature distance matrix +--------- + + +.. code-block:: default + C1 = ot.dist(xs) C2 = ot.dist(xt) M = ot.dist(ys, yt) @@ -130,15 +139,13 @@ Create structure matrices and across-feature distance matrix + Plot matrices --------- +.. code-block:: default -.. code-block:: python - - - #%% cmap = 'Reds' pl.close(10) pl.figure(10, (5, 5)) @@ -180,21 +187,28 @@ Plot matrices -.. image:: /auto_examples/images/sphx_glr_plot_fgw_011.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_fgw_002.png + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_fgw.py:128: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -Compute FGW/GW ---------- -.. code-block:: python +Compute FGW/GW +--------- + +.. code-block:: default - #%% Computing FGW and GW alpha = 1e-3 ot.tic() @@ -210,15 +224,17 @@ Compute FGW/GW .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none It. |Loss |Relative loss|Absolute loss ------------------------------------------------ - 0|4.734462e+01|0.000000e+00|0.000000e+00 - 1|2.508258e+01|8.875498e-01|2.226204e+01 - 2|2.189329e+01|1.456747e-01|3.189297e+00 - 3|2.189329e+01|0.000000e+00|0.000000e+00 - Elapsed time : 0.0016989707946777344 s + 0|4.734412e+01|0.000000e+00|0.000000e+00 + 1|2.508254e+01|8.875326e-01|2.226158e+01 + 2|2.189327e+01|1.456740e-01|3.189279e+00 + 3|2.189327e+01|0.000000e+00|0.000000e+00 + Elapsed time : 0.0023026466369628906 s It. |Loss |Relative loss|Absolute loss ------------------------------------------------ 0|4.683978e+04|0.000000e+00|0.000000e+00 @@ -227,15 +243,14 @@ Compute FGW/GW 3|2.182948e+04|0.000000e+00|0.000000e+00 -Visualize transport matrices ---------- +Visualize transport matrices +--------- -.. code-block:: python +.. code-block:: default - #%% visu OT matrix cmap = 'Blues' fs = 15 pl.figure(2, (13, 5)) @@ -264,28 +279,45 @@ Visualize transport matrices -.. image:: /auto_examples/images/sphx_glr_plot_fgw_004.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_fgw_003.png + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_fgw.py:173: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + -**Total running time of the script:** ( 0 minutes 1.468 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.184 seconds) + + +.. _sphx_glr_download_auto_examples_plot_fgw.py: + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_fgw.py <plot_fgw.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_fgw.ipynb <plot_fgw.ipynb>` @@ -294,4 +326,4 @@ Visualize transport matrices .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_free_support_barycenter.ipynb b/docs/source/auto_examples/plot_free_support_barycenter.ipynb index 05a81c8..25ce60f 100644 --- a/docs/source/auto_examples/plot_free_support_barycenter.ipynb +++ b/docs/source/auto_examples/plot_free_support_barycenter.ipynb @@ -80,7 +80,7 @@ }, "outputs": [], "source": [ - "pl.figure(1)\nfor (x_i, b_i) in zip(measures_locations, measures_weights):\n color = np.random.randint(low=1, high=10 * N)\n pl.scatter(x_i[:, 0], x_i[:, 1], s=b * 1000, label='input measure')\npl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter')\npl.title('Data measures and their barycenter')\npl.legend(loc=0)\npl.show()" + "pl.figure(1)\nfor (x_i, b_i) in zip(measures_locations, measures_weights):\n color = np.random.randint(low=1, high=10 * N)\n pl.scatter(x_i[:, 0], x_i[:, 1], s=b_i * 1000, label='input measure')\npl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter')\npl.title('Data measures and their barycenter')\npl.legend(loc=0)\npl.show()" ] } ], @@ -100,7 +100,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_free_support_barycenter.py b/docs/source/auto_examples/plot_free_support_barycenter.py index b6efc59..64b89e4 100644 --- a/docs/source/auto_examples/plot_free_support_barycenter.py +++ b/docs/source/auto_examples/plot_free_support_barycenter.py @@ -62,7 +62,7 @@ X = ot.lp.free_support_barycenter(measures_locations, measures_weights, X_init, pl.figure(1) for (x_i, b_i) in zip(measures_locations, measures_weights): color = np.random.randint(low=1, high=10 * N) - pl.scatter(x_i[:, 0], x_i[:, 1], s=b * 1000, label='input measure') + pl.scatter(x_i[:, 0], x_i[:, 1], s=b_i * 1000, label='input measure') pl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter') pl.title('Data measures and their barycenter') pl.legend(loc=0) diff --git a/docs/source/auto_examples/plot_free_support_barycenter.rst b/docs/source/auto_examples/plot_free_support_barycenter.rst index d1b3b80..f349604 100644 --- a/docs/source/auto_examples/plot_free_support_barycenter.rst +++ b/docs/source/auto_examples/plot_free_support_barycenter.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_free_support_barycenter.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_free_support_barycenter.py: + .. _sphx_glr_auto_examples_plot_free_support_barycenter.py: ==================================================== @@ -12,8 +18,7 @@ sum of diracs. - -.. code-block:: python +.. code-block:: default # Author: Vivien Seguy <vivien.seguy@iip.ist.i.kyoto-u.ac.jp> @@ -31,13 +36,13 @@ sum of diracs. + Generate data ------------- %% parameters and data generation - -.. code-block:: python +.. code-block:: default N = 3 d = 2 @@ -67,12 +72,12 @@ Generate data + Compute free support barycenter ------------- - -.. code-block:: python +.. code-block:: default k = 10 # number of Diracs of the barycenter @@ -88,18 +93,18 @@ Compute free support barycenter + Plot data --------- - -.. code-block:: python +.. code-block:: default pl.figure(1) for (x_i, b_i) in zip(measures_locations, measures_weights): color = np.random.randint(low=1, high=10 * N) - pl.scatter(x_i[:, 0], x_i[:, 1], s=b * 1000, label='input measure') + pl.scatter(x_i[:, 0], x_i[:, 1], s=b_i * 1000, label='input measure') pl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter') pl.title('Data measures and their barycenter') pl.legend(loc=0) @@ -108,27 +113,44 @@ Plot data .. image:: /auto_examples/images/sphx_glr_plot_free_support_barycenter_001.png - :align: center + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + Out: -**Total running time of the script:** ( 0 minutes 0.129 seconds) + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_free_support_barycenter.py:69: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.080 seconds) + + +.. _sphx_glr_download_auto_examples_plot_free_support_barycenter.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_free_support_barycenter.py <plot_free_support_barycenter.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_free_support_barycenter.ipynb <plot_free_support_barycenter.ipynb>` @@ -137,4 +159,4 @@ Plot data .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_gromov.ipynb b/docs/source/auto_examples/plot_gromov.ipynb index dc1f179..e5a88e7 100644 --- a/docs/source/auto_examples/plot_gromov.ipynb +++ b/docs/source/auto_examples/plot_gromov.ipynb @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_gromov.rst b/docs/source/auto_examples/plot_gromov.rst index 3ed4e11..13d0d09 100644 --- a/docs/source/auto_examples/plot_gromov.rst +++ b/docs/source/auto_examples/plot_gromov.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_gromov.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_gromov.py: + .. _sphx_glr_auto_examples_plot_gromov.py: ========================== @@ -11,8 +17,7 @@ This example is designed to show how to use the Gromov-Wassertsein distance computation in POT. - -.. code-block:: python +.. code-block:: default # Author: Erwan Vautier <erwan.vautier@gmail.com> @@ -32,6 +37,7 @@ computation in POT. + Sample two Gaussian distributions (2D and 3D) --------------------------------------------- @@ -40,8 +46,7 @@ do not belong to the same metric space. For demonstration purpose, we sample two Gaussian distributions in 2- and 3-dimensional spaces. - -.. code-block:: python +.. code-block:: default @@ -64,12 +69,12 @@ two Gaussian distributions in 2- and 3-dimensional spaces. + Plotting the distributions -------------------------- - -.. code-block:: python +.. code-block:: default @@ -84,7 +89,17 @@ Plotting the distributions .. image:: /auto_examples/images/sphx_glr_plot_gromov_001.png - :align: center + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_gromov.py:56: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -93,8 +108,7 @@ Compute distance kernels, normalize them and then display --------------------------------------------------------- - -.. code-block:: python +.. code-block:: default @@ -115,7 +129,17 @@ Compute distance kernels, normalize them and then display .. image:: /auto_examples/images/sphx_glr_plot_gromov_002.png - :align: center + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_gromov.py:75: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -124,8 +148,7 @@ Compute Gromov-Wasserstein plans and distance --------------------------------------------- - -.. code-block:: python +.. code-block:: default p = ot.unif(n_samples) @@ -157,52 +180,60 @@ Compute Gromov-Wasserstein plans and distance .. image:: /auto_examples/images/sphx_glr_plot_gromov_003.png - :align: center + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: - - It. |Loss |Delta loss - -------------------------------- - 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 + Out: + + .. code-block:: none + + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 0|8.019265e-02|0.000000e+00|0.000000e+00 + 1|3.734805e-02|1.147171e+00|4.284460e-02 + 2|2.923853e-02|2.773572e-01|8.109516e-03 + 3|2.478957e-02|1.794691e-01|4.448961e-03 + 4|2.444720e-02|1.400444e-02|3.423693e-04 + 5|2.444720e-02|0.000000e+00|0.000000e+00 It. |Err ------------------- - 0|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 + 0|8.259147e-02| + 10|6.113732e-04| + 20|1.650651e-08| + 30|5.671192e-12| + Gromov-Wasserstein distances: 0.024447198979060496 + Entropic Gromov-Wasserstein distances: 0.02488439679981518 + /home/rflamary/PYTHON/POT/examples/plot_gromov.py:106: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + -**Total running time of the script:** ( 0 minutes 1.916 seconds) +.. rst-class:: sphx-glr-timing + **Total running time of the script:** ( 0 minutes 0.999 seconds) + + +.. _sphx_glr_download_auto_examples_plot_gromov.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_gromov.py <plot_gromov.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_gromov.ipynb <plot_gromov.ipynb>` @@ -211,4 +242,4 @@ Compute Gromov-Wasserstein plans and distance .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_gromov_barycenter.ipynb b/docs/source/auto_examples/plot_gromov_barycenter.ipynb index 4c2f28f..17ba374 100644 --- a/docs/source/auto_examples/plot_gromov_barycenter.ipynb +++ b/docs/source/auto_examples/plot_gromov_barycenter.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# Gromov-Wasserstein Barycenter example\n\n\nThis example is designed to show how to use the Gromov-Wasserstein distance\ncomputation in POT.\n\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "# Author: Erwan Vautier <erwan.vautier@gmail.com>\n# Nicolas Courty <ncourty@irisa.fr>\n#\n# License: MIT License\n\n\nimport numpy as np\nimport scipy as sp\n\nimport scipy.ndimage as spi\nimport matplotlib.pylab as pl\nfrom sklearn import manifold\nfrom sklearn.decomposition import PCA\n\nimport ot" - ], - "cell_type": "code" + "# Author: Erwan Vautier <erwan.vautier@gmail.com>\n# Nicolas Courty <ncourty@irisa.fr>\n#\n# License: MIT License\n\n\nimport numpy as np\nimport scipy as sp\n\nimport matplotlib.pylab as pl\nfrom sklearn import manifold\nfrom sklearn.decomposition import PCA\n\nimport ot" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Smacof MDS\n----------\n\nThis function allows to find an embedding of points given a dissimilarity matrix\nthat will be given by the output of the algorithm\n\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false @@ -44,35 +45,35 @@ "outputs": [], "source": [ "def smacof_mds(C, dim, max_iter=3000, eps=1e-9):\n \"\"\"\n Returns an interpolated point cloud following the dissimilarity matrix C\n using SMACOF multidimensional scaling (MDS) in specific dimensionned\n target space\n\n Parameters\n ----------\n C : ndarray, shape (ns, ns)\n dissimilarity matrix\n dim : int\n dimension of the targeted space\n max_iter : int\n Maximum number of iterations of the SMACOF algorithm for a single run\n eps : float\n relative tolerance w.r.t stress to declare converge\n\n Returns\n -------\n npos : ndarray, shape (R, dim)\n Embedded coordinates of the interpolated point cloud (defined with\n one isometry)\n \"\"\"\n\n rng = np.random.RandomState(seed=3)\n\n mds = manifold.MDS(\n dim,\n max_iter=max_iter,\n eps=1e-9,\n dissimilarity='precomputed',\n n_init=1)\n pos = mds.fit(C).embedding_\n\n nmds = manifold.MDS(\n 2,\n max_iter=max_iter,\n eps=1e-9,\n dissimilarity=\"precomputed\",\n random_state=rng,\n n_init=1)\n npos = nmds.fit_transform(C, init=pos)\n\n return npos" - ], - "cell_type": "code" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Data preparation\n----------------\n\nThe four distributions are constructed from 4 simple images\n\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "def im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\nsquare = spi.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256\ncross = spi.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256\ntriangle = spi.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256\nstar = spi.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256\n\nshapes = [square, cross, triangle, star]\n\nS = 4\nxs = [[] for i in range(S)]\n\n\nfor nb in range(4):\n for i in range(8):\n for j in range(8):\n if shapes[nb][i, j] < 0.95:\n xs[nb].append([j, 8 - i])\n\nxs = np.array([np.array(xs[0]), np.array(xs[1]),\n np.array(xs[2]), np.array(xs[3])])" - ], - "cell_type": "code" + "def im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\nsquare = pl.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256\ncross = pl.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256\ntriangle = pl.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256\nstar = pl.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256\n\nshapes = [square, cross, triangle, star]\n\nS = 4\nxs = [[] for i in range(S)]\n\n\nfor nb in range(4):\n for i in range(8):\n for j in range(8):\n if shapes[nb][i, j] < 0.95:\n xs[nb].append([j, 8 - i])\n\nxs = np.array([np.array(xs[0]), np.array(xs[1]),\n np.array(xs[2]), np.array(xs[3])])" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Barycenter computation\n----------------------\n\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false @@ -80,17 +81,17 @@ "outputs": [], "source": [ "ns = [len(xs[s]) for s in range(S)]\nn_samples = 30\n\n\"\"\"Compute all distances matrices for the four shapes\"\"\"\nCs = [sp.spatial.distance.cdist(xs[s], xs[s]) for s in range(S)]\nCs = [cs / cs.max() for cs in Cs]\n\nps = [ot.unif(ns[s]) for s in range(S)]\np = ot.unif(n_samples)\n\n\nlambdast = [[float(i) / 3, float(3 - i) / 3] for i in [1, 2]]\n\nCt01 = [0 for i in range(2)]\nfor i in range(2):\n Ct01[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[1]],\n [ps[0], ps[1]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)\n\nCt02 = [0 for i in range(2)]\nfor i in range(2):\n Ct02[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[0], Cs[2]],\n [ps[0], ps[2]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)\n\nCt13 = [0 for i in range(2)]\nfor i in range(2):\n Ct13[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[1], Cs[3]],\n [ps[1], ps[3]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)\n\nCt23 = [0 for i in range(2)]\nfor i in range(2):\n Ct23[i] = ot.gromov.gromov_barycenters(n_samples, [Cs[2], Cs[3]],\n [ps[2], ps[3]\n ], p, lambdast[i], 'square_loss', # 5e-4,\n max_iter=100, tol=1e-3)" - ], - "cell_type": "code" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Visualization\n-------------\n\nThe PCA helps in getting consistency between the rotations\n\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false @@ -98,29 +99,28 @@ "outputs": [], "source": [ "clf = PCA(n_components=2)\nnpos = [0, 0, 0, 0]\nnpos = [smacof_mds(Cs[s], 2) for s in range(S)]\n\nnpost01 = [0, 0]\nnpost01 = [smacof_mds(Ct01[s], 2) for s in range(2)]\nnpost01 = [clf.fit_transform(npost01[s]) for s in range(2)]\n\nnpost02 = [0, 0]\nnpost02 = [smacof_mds(Ct02[s], 2) for s in range(2)]\nnpost02 = [clf.fit_transform(npost02[s]) for s in range(2)]\n\nnpost13 = [0, 0]\nnpost13 = [smacof_mds(Ct13[s], 2) for s in range(2)]\nnpost13 = [clf.fit_transform(npost13[s]) for s in range(2)]\n\nnpost23 = [0, 0]\nnpost23 = [smacof_mds(Ct23[s], 2) for s in range(2)]\nnpost23 = [clf.fit_transform(npost23[s]) for s in range(2)]\n\n\nfig = pl.figure(figsize=(10, 10))\n\nax1 = pl.subplot2grid((4, 4), (0, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax1.scatter(npos[0][:, 0], npos[0][:, 1], color='r')\n\nax2 = pl.subplot2grid((4, 4), (0, 1))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax2.scatter(npost01[1][:, 0], npost01[1][:, 1], color='b')\n\nax3 = pl.subplot2grid((4, 4), (0, 2))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax3.scatter(npost01[0][:, 0], npost01[0][:, 1], color='b')\n\nax4 = pl.subplot2grid((4, 4), (0, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax4.scatter(npos[1][:, 0], npos[1][:, 1], color='r')\n\nax5 = pl.subplot2grid((4, 4), (1, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax5.scatter(npost02[1][:, 0], npost02[1][:, 1], color='b')\n\nax6 = pl.subplot2grid((4, 4), (1, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax6.scatter(npost13[1][:, 0], npost13[1][:, 1], color='b')\n\nax7 = pl.subplot2grid((4, 4), (2, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax7.scatter(npost02[0][:, 0], npost02[0][:, 1], color='b')\n\nax8 = pl.subplot2grid((4, 4), (2, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax8.scatter(npost13[0][:, 0], npost13[0][:, 1], color='b')\n\nax9 = pl.subplot2grid((4, 4), (3, 0))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax9.scatter(npos[2][:, 0], npos[2][:, 1], color='r')\n\nax10 = pl.subplot2grid((4, 4), (3, 1))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax10.scatter(npost23[1][:, 0], npost23[1][:, 1], color='b')\n\nax11 = pl.subplot2grid((4, 4), (3, 2))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax11.scatter(npost23[0][:, 0], npost23[0][:, 1], color='b')\n\nax12 = pl.subplot2grid((4, 4), (3, 3))\npl.xlim((-1, 1))\npl.ylim((-1, 1))\nax12.scatter(npos[3][:, 0], npos[3][:, 1], color='r')" - ], - "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.9" } }, - "nbformat_minor": 0, - "nbformat": 4 + "nbformat": 4, + "nbformat_minor": 0 }
\ No newline at end of file diff --git a/docs/source/auto_examples/plot_gromov_barycenter.py b/docs/source/auto_examples/plot_gromov_barycenter.py index 58fc51a..101c6c5 100644 --- a/docs/source/auto_examples/plot_gromov_barycenter.py +++ b/docs/source/auto_examples/plot_gromov_barycenter.py @@ -17,7 +17,6 @@ computation in POT. import numpy as np
import scipy as sp
-import scipy.ndimage as spi
import matplotlib.pylab as pl
from sklearn import manifold
from sklearn.decomposition import PCA
@@ -90,10 +89,10 @@ def im2mat(I): return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))
-square = spi.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256
-cross = spi.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256
-triangle = spi.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256
-star = spi.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256
+square = pl.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256
+cross = pl.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256
+triangle = pl.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256
+star = pl.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256
shapes = [square, cross, triangle, star]
diff --git a/docs/source/auto_examples/plot_gromov_barycenter.rst b/docs/source/auto_examples/plot_gromov_barycenter.rst index 531ee22..995cca7 100644 --- a/docs/source/auto_examples/plot_gromov_barycenter.rst +++ b/docs/source/auto_examples/plot_gromov_barycenter.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_gromov_barycenter.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_gromov_barycenter.py: + .. _sphx_glr_auto_examples_plot_gromov_barycenter.py: ===================================== @@ -11,8 +17,7 @@ This example is designed to show how to use the Gromov-Wasserstein distance computation in POT. - -.. code-block:: python +.. code-block:: default # Author: Erwan Vautier <erwan.vautier@gmail.com> @@ -24,7 +29,6 @@ computation in POT. import numpy as np import scipy as sp - import scipy.ndimage as spi import matplotlib.pylab as pl from sklearn import manifold from sklearn.decomposition import PCA @@ -37,6 +41,7 @@ computation in POT. + Smacof MDS ---------- @@ -44,8 +49,7 @@ This function allows to find an embedding of points given a dissimilarity matrix that will be given by the output of the algorithm - -.. code-block:: python +.. code-block:: default @@ -101,14 +105,14 @@ that will be given by the output of the algorithm + Data preparation ---------------- The four distributions are constructed from 4 simple images - -.. code-block:: python +.. code-block:: default @@ -117,10 +121,10 @@ The four distributions are constructed from 4 simple images return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) - square = spi.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256 - cross = spi.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256 - triangle = spi.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256 - star = spi.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256 + square = pl.imread('../data/square.png').astype(np.float64)[:, :, 2] / 256 + cross = pl.imread('../data/cross.png').astype(np.float64)[:, :, 2] / 256 + triangle = pl.imread('../data/triangle.png').astype(np.float64)[:, :, 2] / 256 + star = pl.imread('../data/star.png').astype(np.float64)[:, :, 2] / 256 shapes = [square, cross, triangle, star] @@ -143,12 +147,12 @@ The four distributions are constructed from 4 simple images + Barycenter computation ---------------------- - -.. code-block:: python +.. code-block:: default @@ -200,14 +204,14 @@ Barycenter computation + Visualization ------------- The PCA helps in getting consistency between the rotations - -.. code-block:: python +.. code-block:: default @@ -297,27 +301,43 @@ The PCA helps in getting consistency between the rotations .. image:: /auto_examples/images/sphx_glr_plot_gromov_barycenter_001.png - :align: center + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + <matplotlib.collections.PathCollection object at 0x7ff28e5d6080> -**Total running time of the script:** ( 0 minutes 5.906 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.747 seconds) + + +.. _sphx_glr_download_auto_examples_plot_gromov_barycenter.py: + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_gromov_barycenter.py <plot_gromov_barycenter.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_gromov_barycenter.ipynb <plot_gromov_barycenter.ipynb>` @@ -326,4 +346,4 @@ The PCA helps in getting consistency between the rotations .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_optim_OTreg.ipynb b/docs/source/auto_examples/plot_optim_OTreg.ipynb index 107c299..01e0689 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.ipynb +++ b/docs/source/auto_examples/plot_optim_OTreg.ipynb @@ -44,7 +44,7 @@ }, "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.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()" + "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\nb = ot.datasets.make_1D_gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" ] }, { @@ -62,7 +62,7 @@ }, "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')" + "G0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" ] }, { @@ -80,7 +80,7 @@ }, "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')" + "def f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg = 1e-1\n\nGl2 = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(3)\not.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg')" ] }, { @@ -98,7 +98,7 @@ }, "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')" + "def f(G):\n return np.sum(G * np.log(G))\n\n\ndef df(G):\n return np.log(G) + 1.\n\n\nreg = 1e-3\n\nGe = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg')" ] }, { @@ -116,7 +116,7 @@ }, "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()" + "def f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg1 = 1e-3\nreg2 = 1e-1\n\nGel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True)\n\npl.figure(5, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg')\npl.show()" ] } ], @@ -136,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_optim_OTreg.rst b/docs/source/auto_examples/plot_optim_OTreg.rst index 844cba0..cd5bcf5 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.rst +++ b/docs/source/auto_examples/plot_optim_OTreg.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_optim_OTreg.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_optim_OTreg.py: + .. _sphx_glr_auto_examples_plot_optim_OTreg.py: ================================== @@ -28,8 +34,7 @@ arXiv preprint arXiv:1510.06567. - -.. code-block:: python +.. code-block:: default import numpy as np @@ -43,15 +48,13 @@ arXiv preprint arXiv:1510.06567. + Generate data ------------- +.. code-block:: default -.. code-block:: python - - - #%% parameters n = 100 # nb bins @@ -72,16 +75,14 @@ Generate data + Solve EMD --------- - -.. code-block:: python +.. code-block:: default - #%% EMD - G0 = ot.emd(a, b, M) pl.figure(3, figsize=(5, 5)) @@ -90,8 +91,9 @@ Solve EMD -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_001.png + :class: sphx-glr-single-img + @@ -100,12 +102,9 @@ Solve EMD with Frobenius norm regularization -------------------------------------------- - -.. code-block:: python +.. code-block:: default - #%% Example with Frobenius norm regularization - def f(G): return 0.5 * np.sum(G**2) @@ -125,248 +124,249 @@ Solve EMD with Frobenius norm regularization -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_004.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_002.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: - - It. |Loss |Delta loss - -------------------------------- - 0|1.760578e-01|0.000000e+00 - 1|1.669467e-01|-5.457501e-02 - 2|1.665639e-01|-2.298130e-03 - 3|1.664378e-01|-7.572776e-04 - 4|1.664077e-01|-1.811855e-04 - 5|1.663912e-01|-9.936787e-05 - 6|1.663852e-01|-3.555826e-05 - 7|1.663814e-01|-2.305693e-05 - 8|1.663785e-01|-1.760450e-05 - 9|1.663767e-01|-1.078011e-05 - 10|1.663751e-01|-9.525192e-06 - 11|1.663737e-01|-8.396466e-06 - 12|1.663727e-01|-6.086938e-06 - 13|1.663720e-01|-4.042609e-06 - 14|1.663713e-01|-4.160914e-06 - 15|1.663707e-01|-3.823502e-06 - 16|1.663702e-01|-3.022440e-06 - 17|1.663697e-01|-3.181249e-06 - 18|1.663692e-01|-2.698532e-06 - 19|1.663687e-01|-3.258253e-06 - It. |Loss |Delta loss - -------------------------------- - 20|1.663682e-01|-2.741118e-06 - 21|1.663678e-01|-2.624135e-06 - 22|1.663673e-01|-2.645179e-06 - 23|1.663670e-01|-1.957237e-06 - 24|1.663666e-01|-2.261541e-06 - 25|1.663663e-01|-1.851305e-06 - 26|1.663660e-01|-1.942296e-06 - 27|1.663657e-01|-2.092896e-06 - 28|1.663653e-01|-1.924361e-06 - 29|1.663651e-01|-1.625455e-06 - 30|1.663648e-01|-1.641123e-06 - 31|1.663645e-01|-1.566666e-06 - 32|1.663643e-01|-1.338514e-06 - 33|1.663641e-01|-1.222711e-06 - 34|1.663639e-01|-1.221805e-06 - 35|1.663637e-01|-1.440781e-06 - 36|1.663634e-01|-1.520091e-06 - 37|1.663632e-01|-1.288193e-06 - 38|1.663630e-01|-1.123055e-06 - 39|1.663628e-01|-1.024487e-06 - It. |Loss |Delta loss - -------------------------------- - 40|1.663627e-01|-1.079606e-06 - 41|1.663625e-01|-1.172093e-06 - 42|1.663623e-01|-1.047880e-06 - 43|1.663621e-01|-1.010577e-06 - 44|1.663619e-01|-1.064438e-06 - 45|1.663618e-01|-9.882375e-07 - 46|1.663616e-01|-8.532647e-07 - 47|1.663615e-01|-9.930189e-07 - 48|1.663613e-01|-8.728955e-07 - 49|1.663612e-01|-9.524214e-07 - 50|1.663610e-01|-9.088418e-07 - 51|1.663609e-01|-7.639430e-07 - 52|1.663608e-01|-6.662611e-07 - 53|1.663607e-01|-7.133700e-07 - 54|1.663605e-01|-7.648141e-07 - 55|1.663604e-01|-6.557516e-07 - 56|1.663603e-01|-7.304213e-07 - 57|1.663602e-01|-6.353809e-07 - 58|1.663601e-01|-7.968279e-07 - 59|1.663600e-01|-6.367159e-07 - It. |Loss |Delta loss - -------------------------------- - 60|1.663599e-01|-5.610790e-07 - 61|1.663598e-01|-5.787466e-07 - 62|1.663596e-01|-6.937777e-07 - 63|1.663596e-01|-5.599432e-07 - 64|1.663595e-01|-5.813048e-07 - 65|1.663594e-01|-5.724600e-07 - 66|1.663593e-01|-6.081892e-07 - 67|1.663592e-01|-5.948732e-07 - 68|1.663591e-01|-4.941833e-07 - 69|1.663590e-01|-5.213739e-07 - 70|1.663589e-01|-5.127355e-07 - 71|1.663588e-01|-4.349251e-07 - 72|1.663588e-01|-5.007084e-07 - 73|1.663587e-01|-4.880265e-07 - 74|1.663586e-01|-4.931950e-07 - 75|1.663585e-01|-4.981309e-07 - 76|1.663584e-01|-3.952959e-07 - 77|1.663584e-01|-4.544857e-07 - 78|1.663583e-01|-4.237579e-07 - 79|1.663582e-01|-4.382386e-07 - It. |Loss |Delta loss - -------------------------------- - 80|1.663582e-01|-3.646051e-07 - 81|1.663581e-01|-4.197994e-07 - 82|1.663580e-01|-4.072764e-07 - 83|1.663580e-01|-3.994645e-07 - 84|1.663579e-01|-4.842721e-07 - 85|1.663578e-01|-3.276486e-07 - 86|1.663578e-01|-3.737346e-07 - 87|1.663577e-01|-4.282043e-07 - 88|1.663576e-01|-4.020937e-07 - 89|1.663576e-01|-3.431951e-07 - 90|1.663575e-01|-3.052335e-07 - 91|1.663575e-01|-3.500538e-07 - 92|1.663574e-01|-3.063176e-07 - 93|1.663573e-01|-3.576367e-07 - 94|1.663573e-01|-3.224681e-07 - 95|1.663572e-01|-3.673221e-07 - 96|1.663572e-01|-3.635561e-07 - 97|1.663571e-01|-3.527236e-07 - 98|1.663571e-01|-2.788548e-07 - 99|1.663570e-01|-2.727141e-07 - It. |Loss |Delta loss - -------------------------------- - 100|1.663570e-01|-3.127278e-07 - 101|1.663569e-01|-2.637504e-07 - 102|1.663569e-01|-2.922750e-07 - 103|1.663568e-01|-3.076454e-07 - 104|1.663568e-01|-2.911509e-07 - 105|1.663567e-01|-2.403398e-07 - 106|1.663567e-01|-2.439790e-07 - 107|1.663567e-01|-2.634542e-07 - 108|1.663566e-01|-2.452203e-07 - 109|1.663566e-01|-2.852991e-07 - 110|1.663565e-01|-2.165490e-07 - 111|1.663565e-01|-2.450250e-07 - 112|1.663564e-01|-2.685294e-07 - 113|1.663564e-01|-2.821800e-07 - 114|1.663564e-01|-2.237390e-07 - 115|1.663563e-01|-1.992842e-07 - 116|1.663563e-01|-2.166739e-07 - 117|1.663563e-01|-2.086064e-07 - 118|1.663562e-01|-2.435945e-07 - 119|1.663562e-01|-2.292497e-07 - It. |Loss |Delta loss - -------------------------------- - 120|1.663561e-01|-2.366209e-07 - 121|1.663561e-01|-2.138746e-07 - 122|1.663561e-01|-2.009637e-07 - 123|1.663560e-01|-2.386258e-07 - 124|1.663560e-01|-1.927442e-07 - 125|1.663560e-01|-2.081681e-07 - 126|1.663559e-01|-1.759123e-07 - 127|1.663559e-01|-1.890771e-07 - 128|1.663559e-01|-1.971315e-07 - 129|1.663558e-01|-2.101983e-07 - 130|1.663558e-01|-2.035645e-07 - 131|1.663558e-01|-1.984492e-07 - 132|1.663557e-01|-1.849064e-07 - 133|1.663557e-01|-1.795703e-07 - 134|1.663557e-01|-1.624087e-07 - 135|1.663557e-01|-1.689557e-07 - 136|1.663556e-01|-1.644308e-07 - 137|1.663556e-01|-1.618007e-07 - 138|1.663556e-01|-1.483013e-07 - 139|1.663555e-01|-1.708771e-07 - It. |Loss |Delta loss - -------------------------------- - 140|1.663555e-01|-2.013847e-07 - 141|1.663555e-01|-1.721217e-07 - 142|1.663554e-01|-2.027911e-07 - 143|1.663554e-01|-1.764565e-07 - 144|1.663554e-01|-1.677151e-07 - 145|1.663554e-01|-1.351982e-07 - 146|1.663553e-01|-1.423360e-07 - 147|1.663553e-01|-1.541112e-07 - 148|1.663553e-01|-1.491601e-07 - 149|1.663553e-01|-1.466407e-07 - 150|1.663552e-01|-1.801524e-07 - 151|1.663552e-01|-1.714107e-07 - 152|1.663552e-01|-1.491257e-07 - 153|1.663552e-01|-1.513799e-07 - 154|1.663551e-01|-1.354539e-07 - 155|1.663551e-01|-1.233818e-07 - 156|1.663551e-01|-1.576219e-07 - 157|1.663551e-01|-1.452791e-07 - 158|1.663550e-01|-1.262867e-07 - 159|1.663550e-01|-1.316379e-07 - It. |Loss |Delta loss - -------------------------------- - 160|1.663550e-01|-1.295447e-07 - 161|1.663550e-01|-1.283286e-07 - 162|1.663550e-01|-1.569222e-07 - 163|1.663549e-01|-1.172942e-07 - 164|1.663549e-01|-1.399809e-07 - 165|1.663549e-01|-1.229432e-07 - 166|1.663549e-01|-1.326191e-07 - 167|1.663548e-01|-1.209694e-07 - 168|1.663548e-01|-1.372136e-07 - 169|1.663548e-01|-1.338395e-07 - 170|1.663548e-01|-1.416497e-07 - 171|1.663548e-01|-1.298576e-07 - 172|1.663547e-01|-1.190590e-07 - 173|1.663547e-01|-1.167083e-07 - 174|1.663547e-01|-1.069425e-07 - 175|1.663547e-01|-1.217780e-07 - 176|1.663547e-01|-1.140754e-07 - 177|1.663546e-01|-1.160707e-07 - 178|1.663546e-01|-1.101798e-07 - 179|1.663546e-01|-1.114904e-07 - It. |Loss |Delta loss - -------------------------------- - 180|1.663546e-01|-1.064022e-07 - 181|1.663546e-01|-9.258231e-08 - 182|1.663546e-01|-1.213120e-07 - 183|1.663545e-01|-1.164296e-07 - 184|1.663545e-01|-1.188762e-07 - 185|1.663545e-01|-9.394153e-08 - 186|1.663545e-01|-1.028656e-07 - 187|1.663545e-01|-1.115348e-07 - 188|1.663544e-01|-9.768310e-08 - 189|1.663544e-01|-1.021806e-07 - 190|1.663544e-01|-1.086303e-07 - 191|1.663544e-01|-9.879008e-08 - 192|1.663544e-01|-1.050210e-07 - 193|1.663544e-01|-1.002463e-07 - 194|1.663543e-01|-1.062747e-07 - 195|1.663543e-01|-9.348538e-08 - 196|1.663543e-01|-7.992512e-08 - 197|1.663543e-01|-9.558020e-08 - 198|1.663543e-01|-9.993772e-08 - 199|1.663543e-01|-8.588499e-08 - It. |Loss |Delta loss - -------------------------------- - 200|1.663543e-01|-8.737134e-08 + Out: + + .. code-block:: none + + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 0|1.760578e-01|0.000000e+00|0.000000e+00 + 1|1.669467e-01|5.457501e-02|9.111116e-03 + 2|1.665639e-01|2.298130e-03|3.827855e-04 + 3|1.664378e-01|7.572776e-04|1.260396e-04 + 4|1.664077e-01|1.811855e-04|3.015066e-05 + 5|1.663912e-01|9.936787e-05|1.653393e-05 + 6|1.663852e-01|3.555826e-05|5.916369e-06 + 7|1.663814e-01|2.305693e-05|3.836245e-06 + 8|1.663785e-01|1.760450e-05|2.929009e-06 + 9|1.663767e-01|1.078011e-05|1.793559e-06 + 10|1.663751e-01|9.525192e-06|1.584755e-06 + 11|1.663737e-01|8.396466e-06|1.396951e-06 + 12|1.663727e-01|6.086938e-06|1.012700e-06 + 13|1.663720e-01|4.042609e-06|6.725769e-07 + 14|1.663713e-01|4.160914e-06|6.922568e-07 + 15|1.663707e-01|3.823502e-06|6.361187e-07 + 16|1.663702e-01|3.022440e-06|5.028438e-07 + 17|1.663697e-01|3.181249e-06|5.292634e-07 + 18|1.663692e-01|2.698532e-06|4.489527e-07 + 19|1.663687e-01|3.258253e-06|5.420712e-07 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 20|1.663682e-01|2.741118e-06|4.560349e-07 + 21|1.663678e-01|2.624135e-06|4.365715e-07 + 22|1.663673e-01|2.645179e-06|4.400714e-07 + 23|1.663670e-01|1.957237e-06|3.256196e-07 + 24|1.663666e-01|2.261541e-06|3.762450e-07 + 25|1.663663e-01|1.851305e-06|3.079948e-07 + 26|1.663660e-01|1.942296e-06|3.231320e-07 + 27|1.663657e-01|2.092896e-06|3.481860e-07 + 28|1.663653e-01|1.924361e-06|3.201470e-07 + 29|1.663651e-01|1.625455e-06|2.704189e-07 + 30|1.663648e-01|1.641123e-06|2.730250e-07 + 31|1.663645e-01|1.566666e-06|2.606377e-07 + 32|1.663643e-01|1.338514e-06|2.226810e-07 + 33|1.663641e-01|1.222711e-06|2.034152e-07 + 34|1.663639e-01|1.221805e-06|2.032642e-07 + 35|1.663637e-01|1.440781e-06|2.396935e-07 + 36|1.663634e-01|1.520091e-06|2.528875e-07 + 37|1.663632e-01|1.288193e-06|2.143080e-07 + 38|1.663630e-01|1.123055e-06|1.868347e-07 + 39|1.663628e-01|1.024487e-06|1.704365e-07 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 40|1.663627e-01|1.079606e-06|1.796061e-07 + 41|1.663625e-01|1.172093e-06|1.949922e-07 + 42|1.663623e-01|1.047880e-06|1.743277e-07 + 43|1.663621e-01|1.010577e-06|1.681217e-07 + 44|1.663619e-01|1.064438e-06|1.770820e-07 + 45|1.663618e-01|9.882375e-07|1.644049e-07 + 46|1.663616e-01|8.532647e-07|1.419505e-07 + 47|1.663615e-01|9.930189e-07|1.652001e-07 + 48|1.663613e-01|8.728955e-07|1.452161e-07 + 49|1.663612e-01|9.524214e-07|1.584459e-07 + 50|1.663610e-01|9.088418e-07|1.511958e-07 + 51|1.663609e-01|7.639430e-07|1.270902e-07 + 52|1.663608e-01|6.662611e-07|1.108397e-07 + 53|1.663607e-01|7.133700e-07|1.186767e-07 + 54|1.663605e-01|7.648141e-07|1.272349e-07 + 55|1.663604e-01|6.557516e-07|1.090911e-07 + 56|1.663603e-01|7.304213e-07|1.215131e-07 + 57|1.663602e-01|6.353809e-07|1.057021e-07 + 58|1.663601e-01|7.968279e-07|1.325603e-07 + 59|1.663600e-01|6.367159e-07|1.059240e-07 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 60|1.663599e-01|5.610790e-07|9.334102e-08 + 61|1.663598e-01|5.787466e-07|9.628015e-08 + 62|1.663596e-01|6.937777e-07|1.154166e-07 + 63|1.663596e-01|5.599432e-07|9.315190e-08 + 64|1.663595e-01|5.813048e-07|9.670555e-08 + 65|1.663594e-01|5.724600e-07|9.523409e-08 + 66|1.663593e-01|6.081892e-07|1.011779e-07 + 67|1.663592e-01|5.948732e-07|9.896260e-08 + 68|1.663591e-01|4.941833e-07|8.221188e-08 + 69|1.663590e-01|5.213739e-07|8.673523e-08 + 70|1.663589e-01|5.127355e-07|8.529811e-08 + 71|1.663588e-01|4.349251e-07|7.235363e-08 + 72|1.663588e-01|5.007084e-07|8.329722e-08 + 73|1.663587e-01|4.880265e-07|8.118744e-08 + 74|1.663586e-01|4.931950e-07|8.204723e-08 + 75|1.663585e-01|4.981309e-07|8.286832e-08 + 76|1.663584e-01|3.952959e-07|6.576082e-08 + 77|1.663584e-01|4.544857e-07|7.560750e-08 + 78|1.663583e-01|4.237579e-07|7.049564e-08 + 79|1.663582e-01|4.382386e-07|7.290460e-08 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 80|1.663582e-01|3.646051e-07|6.065503e-08 + 81|1.663581e-01|4.197994e-07|6.983702e-08 + 82|1.663580e-01|4.072764e-07|6.775370e-08 + 83|1.663580e-01|3.994645e-07|6.645410e-08 + 84|1.663579e-01|4.842721e-07|8.056248e-08 + 85|1.663578e-01|3.276486e-07|5.450691e-08 + 86|1.663578e-01|3.737346e-07|6.217366e-08 + 87|1.663577e-01|4.282043e-07|7.123508e-08 + 88|1.663576e-01|4.020937e-07|6.689135e-08 + 89|1.663576e-01|3.431951e-07|5.709310e-08 + 90|1.663575e-01|3.052335e-07|5.077789e-08 + 91|1.663575e-01|3.500538e-07|5.823407e-08 + 92|1.663574e-01|3.063176e-07|5.095821e-08 + 93|1.663573e-01|3.576367e-07|5.949549e-08 + 94|1.663573e-01|3.224681e-07|5.364492e-08 + 95|1.663572e-01|3.673221e-07|6.110670e-08 + 96|1.663572e-01|3.635561e-07|6.048017e-08 + 97|1.663571e-01|3.527236e-07|5.867807e-08 + 98|1.663571e-01|2.788548e-07|4.638946e-08 + 99|1.663570e-01|2.727141e-07|4.536791e-08 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 100|1.663570e-01|3.127278e-07|5.202445e-08 + 101|1.663569e-01|2.637504e-07|4.387670e-08 + 102|1.663569e-01|2.922750e-07|4.862195e-08 + 103|1.663568e-01|3.076454e-07|5.117891e-08 + 104|1.663568e-01|2.911509e-07|4.843492e-08 + 105|1.663567e-01|2.403398e-07|3.998215e-08 + 106|1.663567e-01|2.439790e-07|4.058755e-08 + 107|1.663567e-01|2.634542e-07|4.382735e-08 + 108|1.663566e-01|2.452203e-07|4.079401e-08 + 109|1.663566e-01|2.852991e-07|4.746137e-08 + 110|1.663565e-01|2.165490e-07|3.602434e-08 + 111|1.663565e-01|2.450250e-07|4.076149e-08 + 112|1.663564e-01|2.685294e-07|4.467159e-08 + 113|1.663564e-01|2.821800e-07|4.694245e-08 + 114|1.663564e-01|2.237390e-07|3.722040e-08 + 115|1.663563e-01|1.992842e-07|3.315219e-08 + 116|1.663563e-01|2.166739e-07|3.604506e-08 + 117|1.663563e-01|2.086064e-07|3.470297e-08 + 118|1.663562e-01|2.435945e-07|4.052346e-08 + 119|1.663562e-01|2.292497e-07|3.813711e-08 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 120|1.663561e-01|2.366209e-07|3.936334e-08 + 121|1.663561e-01|2.138746e-07|3.557935e-08 + 122|1.663561e-01|2.009637e-07|3.343153e-08 + 123|1.663560e-01|2.386258e-07|3.969683e-08 + 124|1.663560e-01|1.927442e-07|3.206415e-08 + 125|1.663560e-01|2.081681e-07|3.463000e-08 + 126|1.663559e-01|1.759123e-07|2.926406e-08 + 127|1.663559e-01|1.890771e-07|3.145409e-08 + 128|1.663559e-01|1.971315e-07|3.279398e-08 + 129|1.663558e-01|2.101983e-07|3.496771e-08 + 130|1.663558e-01|2.035645e-07|3.386414e-08 + 131|1.663558e-01|1.984492e-07|3.301317e-08 + 132|1.663557e-01|1.849064e-07|3.076024e-08 + 133|1.663557e-01|1.795703e-07|2.987255e-08 + 134|1.663557e-01|1.624087e-07|2.701762e-08 + 135|1.663557e-01|1.689557e-07|2.810673e-08 + 136|1.663556e-01|1.644308e-07|2.735399e-08 + 137|1.663556e-01|1.618007e-07|2.691644e-08 + 138|1.663556e-01|1.483013e-07|2.467075e-08 + 139|1.663555e-01|1.708771e-07|2.842636e-08 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 140|1.663555e-01|2.013847e-07|3.350146e-08 + 141|1.663555e-01|1.721217e-07|2.863339e-08 + 142|1.663554e-01|2.027911e-07|3.373540e-08 + 143|1.663554e-01|1.764565e-07|2.935449e-08 + 144|1.663554e-01|1.677151e-07|2.790030e-08 + 145|1.663554e-01|1.351982e-07|2.249094e-08 + 146|1.663553e-01|1.423360e-07|2.367836e-08 + 147|1.663553e-01|1.541112e-07|2.563722e-08 + 148|1.663553e-01|1.491601e-07|2.481358e-08 + 149|1.663553e-01|1.466407e-07|2.439446e-08 + 150|1.663552e-01|1.801524e-07|2.996929e-08 + 151|1.663552e-01|1.714107e-07|2.851507e-08 + 152|1.663552e-01|1.491257e-07|2.480784e-08 + 153|1.663552e-01|1.513799e-07|2.518282e-08 + 154|1.663551e-01|1.354539e-07|2.253345e-08 + 155|1.663551e-01|1.233818e-07|2.052519e-08 + 156|1.663551e-01|1.576219e-07|2.622121e-08 + 157|1.663551e-01|1.452791e-07|2.416792e-08 + 158|1.663550e-01|1.262867e-07|2.100843e-08 + 159|1.663550e-01|1.316379e-07|2.189863e-08 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 160|1.663550e-01|1.295447e-07|2.155041e-08 + 161|1.663550e-01|1.283286e-07|2.134810e-08 + 162|1.663550e-01|1.569222e-07|2.610479e-08 + 163|1.663549e-01|1.172942e-07|1.951247e-08 + 164|1.663549e-01|1.399809e-07|2.328651e-08 + 165|1.663549e-01|1.229432e-07|2.045221e-08 + 166|1.663549e-01|1.326191e-07|2.206184e-08 + 167|1.663548e-01|1.209694e-07|2.012384e-08 + 168|1.663548e-01|1.372136e-07|2.282614e-08 + 169|1.663548e-01|1.338395e-07|2.226484e-08 + 170|1.663548e-01|1.416497e-07|2.356410e-08 + 171|1.663548e-01|1.298576e-07|2.160242e-08 + 172|1.663547e-01|1.190590e-07|1.980603e-08 + 173|1.663547e-01|1.167083e-07|1.941497e-08 + 174|1.663547e-01|1.069425e-07|1.779038e-08 + 175|1.663547e-01|1.217780e-07|2.025834e-08 + 176|1.663547e-01|1.140754e-07|1.897697e-08 + 177|1.663546e-01|1.160707e-07|1.930890e-08 + 178|1.663546e-01|1.101798e-07|1.832892e-08 + 179|1.663546e-01|1.114904e-07|1.854694e-08 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 180|1.663546e-01|1.064022e-07|1.770049e-08 + 181|1.663546e-01|9.258231e-08|1.540149e-08 + 182|1.663546e-01|1.213120e-07|2.018080e-08 + 183|1.663545e-01|1.164296e-07|1.936859e-08 + 184|1.663545e-01|1.188762e-07|1.977559e-08 + 185|1.663545e-01|9.394153e-08|1.562760e-08 + 186|1.663545e-01|1.028656e-07|1.711216e-08 + 187|1.663545e-01|1.115348e-07|1.855431e-08 + 188|1.663544e-01|9.768310e-08|1.625002e-08 + 189|1.663544e-01|1.021806e-07|1.699820e-08 + 190|1.663544e-01|1.086303e-07|1.807113e-08 + 191|1.663544e-01|9.879008e-08|1.643416e-08 + 192|1.663544e-01|1.050210e-07|1.747071e-08 + 193|1.663544e-01|1.002463e-07|1.667641e-08 + 194|1.663543e-01|1.062747e-07|1.767925e-08 + 195|1.663543e-01|9.348538e-08|1.555170e-08 + 196|1.663543e-01|7.992512e-08|1.329589e-08 + 197|1.663543e-01|9.558020e-08|1.590018e-08 + 198|1.663543e-01|9.993772e-08|1.662507e-08 + 199|1.663543e-01|8.588499e-08|1.428734e-08 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 200|1.663543e-01|8.737134e-08|1.453459e-08 -Solve EMD with entropic regularization --------------------------------------- +Solve EMD with entropic regularization +-------------------------------------- -.. code-block:: python +.. code-block:: default - #%% Example with entropic regularization def f(G): @@ -387,217 +387,128 @@ Solve EMD with entropic regularization -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_006.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_003.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: - - It. |Loss |Delta loss - -------------------------------- - 0|1.692289e-01|0.000000e+00 - 1|1.617643e-01|-4.614437e-02 - 2|1.612639e-01|-3.102965e-03 - 3|1.611291e-01|-8.371098e-04 - 4|1.610468e-01|-5.110558e-04 - 5|1.610198e-01|-1.672927e-04 - 6|1.610130e-01|-4.232417e-05 - 7|1.610090e-01|-2.513455e-05 - 8|1.610002e-01|-5.443507e-05 - 9|1.609996e-01|-3.657071e-06 - 10|1.609948e-01|-2.998735e-05 - 11|1.609695e-01|-1.569217e-04 - 12|1.609533e-01|-1.010779e-04 - 13|1.609520e-01|-8.043897e-06 - 14|1.609465e-01|-3.415246e-05 - 15|1.609386e-01|-4.898605e-05 - 16|1.609324e-01|-3.837052e-05 - 17|1.609298e-01|-1.617826e-05 - 18|1.609184e-01|-7.080015e-05 - 19|1.609083e-01|-6.273206e-05 - It. |Loss |Delta loss - -------------------------------- - 20|1.608988e-01|-5.940805e-05 - 21|1.608853e-01|-8.380030e-05 - 22|1.608844e-01|-5.185045e-06 - 23|1.608824e-01|-1.279113e-05 - 24|1.608819e-01|-3.156821e-06 - 25|1.608783e-01|-2.205746e-05 - 26|1.608764e-01|-1.189894e-05 - 27|1.608755e-01|-5.474607e-06 - 28|1.608737e-01|-1.144227e-05 - 29|1.608676e-01|-3.775335e-05 - 30|1.608638e-01|-2.348020e-05 - 31|1.608627e-01|-6.863136e-06 - 32|1.608529e-01|-6.110230e-05 - 33|1.608487e-01|-2.641106e-05 - 34|1.608409e-01|-4.823638e-05 - 35|1.608373e-01|-2.256641e-05 - 36|1.608338e-01|-2.132444e-05 - 37|1.608310e-01|-1.786649e-05 - 38|1.608260e-01|-3.103848e-05 - 39|1.608206e-01|-3.321265e-05 - It. |Loss |Delta loss - -------------------------------- - 40|1.608201e-01|-3.054747e-06 - 41|1.608195e-01|-4.198335e-06 - 42|1.608193e-01|-8.458736e-07 - 43|1.608159e-01|-2.153759e-05 - 44|1.608115e-01|-2.738314e-05 - 45|1.608108e-01|-3.960032e-06 - 46|1.608081e-01|-1.675447e-05 - 47|1.608072e-01|-5.976340e-06 - 48|1.608046e-01|-1.604130e-05 - 49|1.608020e-01|-1.617036e-05 - 50|1.608014e-01|-3.957795e-06 - 51|1.608011e-01|-1.292411e-06 - 52|1.607998e-01|-8.431795e-06 - 53|1.607964e-01|-2.127054e-05 - 54|1.607947e-01|-1.021878e-05 - 55|1.607947e-01|-3.560621e-07 - 56|1.607900e-01|-2.929781e-05 - 57|1.607890e-01|-5.740229e-06 - 58|1.607858e-01|-2.039550e-05 - 59|1.607836e-01|-1.319545e-05 - It. |Loss |Delta loss - -------------------------------- - 60|1.607826e-01|-6.378947e-06 - 61|1.607808e-01|-1.145102e-05 - 62|1.607776e-01|-1.941743e-05 - 63|1.607743e-01|-2.087422e-05 - 64|1.607741e-01|-1.310249e-06 - 65|1.607738e-01|-1.682752e-06 - 66|1.607691e-01|-2.913936e-05 - 67|1.607671e-01|-1.288855e-05 - 68|1.607654e-01|-1.002448e-05 - 69|1.607641e-01|-8.209492e-06 - 70|1.607632e-01|-5.588467e-06 - 71|1.607619e-01|-8.050388e-06 - 72|1.607618e-01|-9.417493e-07 - 73|1.607598e-01|-1.210509e-05 - 74|1.607591e-01|-4.392914e-06 - 75|1.607579e-01|-7.759587e-06 - 76|1.607574e-01|-2.760280e-06 - 77|1.607556e-01|-1.146469e-05 - 78|1.607550e-01|-3.689456e-06 - 79|1.607550e-01|-4.065631e-08 - It. |Loss |Delta loss - -------------------------------- - 80|1.607539e-01|-6.555681e-06 - 81|1.607528e-01|-7.177470e-06 - 82|1.607527e-01|-5.306068e-07 - 83|1.607514e-01|-7.816045e-06 - 84|1.607511e-01|-2.301970e-06 - 85|1.607504e-01|-4.281072e-06 - 86|1.607503e-01|-7.821886e-07 - 87|1.607480e-01|-1.403013e-05 - 88|1.607480e-01|-1.169298e-08 - 89|1.607473e-01|-4.235982e-06 - 90|1.607470e-01|-1.717105e-06 - 91|1.607470e-01|-6.148402e-09 - 92|1.607462e-01|-5.396481e-06 - 93|1.607461e-01|-5.194954e-07 - 94|1.607450e-01|-6.525707e-06 - 95|1.607442e-01|-5.332060e-06 - 96|1.607439e-01|-1.682093e-06 - 97|1.607437e-01|-1.594796e-06 - 98|1.607435e-01|-7.923812e-07 - 99|1.607420e-01|-9.738552e-06 - It. |Loss |Delta loss - -------------------------------- - 100|1.607419e-01|-1.022448e-07 - 101|1.607419e-01|-4.865999e-07 - 102|1.607418e-01|-7.092012e-07 - 103|1.607408e-01|-5.861815e-06 - 104|1.607402e-01|-3.953266e-06 - 105|1.607395e-01|-3.969572e-06 - 106|1.607390e-01|-3.612075e-06 - 107|1.607377e-01|-7.683735e-06 - 108|1.607365e-01|-7.777599e-06 - 109|1.607364e-01|-2.335096e-07 - 110|1.607364e-01|-4.562036e-07 - 111|1.607360e-01|-2.089538e-06 - 112|1.607356e-01|-2.755355e-06 - 113|1.607349e-01|-4.501960e-06 - 114|1.607347e-01|-1.160544e-06 - 115|1.607346e-01|-6.289450e-07 - 116|1.607345e-01|-2.092146e-07 - 117|1.607336e-01|-5.990866e-06 - 118|1.607330e-01|-3.348498e-06 - 119|1.607328e-01|-1.256222e-06 - It. |Loss |Delta loss - -------------------------------- - 120|1.607320e-01|-5.418353e-06 - 121|1.607318e-01|-8.296189e-07 - 122|1.607311e-01|-4.381608e-06 - 123|1.607310e-01|-8.913901e-07 - 124|1.607309e-01|-3.808821e-07 - 125|1.607302e-01|-4.608994e-06 - 126|1.607294e-01|-5.063777e-06 - 127|1.607290e-01|-2.532835e-06 - 128|1.607285e-01|-2.870049e-06 - 129|1.607284e-01|-4.892812e-07 - 130|1.607281e-01|-1.760452e-06 - 131|1.607279e-01|-1.727139e-06 - 132|1.607275e-01|-2.220706e-06 - 133|1.607271e-01|-2.516930e-06 - 134|1.607269e-01|-1.201434e-06 - 135|1.607269e-01|-2.183459e-09 - 136|1.607262e-01|-4.223011e-06 - 137|1.607258e-01|-2.530202e-06 - 138|1.607258e-01|-1.857260e-07 - 139|1.607256e-01|-1.401957e-06 - It. |Loss |Delta loss - -------------------------------- - 140|1.607250e-01|-3.242751e-06 - 141|1.607247e-01|-2.308071e-06 - 142|1.607247e-01|-4.730700e-08 - 143|1.607246e-01|-4.240229e-07 - 144|1.607242e-01|-2.484810e-06 - 145|1.607238e-01|-2.539206e-06 - 146|1.607234e-01|-2.535574e-06 - 147|1.607231e-01|-1.954802e-06 - 148|1.607228e-01|-1.765447e-06 - 149|1.607228e-01|-1.620007e-08 - 150|1.607222e-01|-3.615783e-06 - 151|1.607222e-01|-8.668516e-08 - 152|1.607215e-01|-4.000673e-06 - 153|1.607213e-01|-1.774103e-06 - 154|1.607213e-01|-6.328834e-09 - 155|1.607209e-01|-2.418783e-06 - 156|1.607208e-01|-2.848492e-07 - 157|1.607207e-01|-8.836043e-07 - 158|1.607205e-01|-1.192836e-06 - 159|1.607202e-01|-1.638022e-06 - It. |Loss |Delta loss - -------------------------------- - 160|1.607202e-01|-3.670914e-08 - 161|1.607197e-01|-3.153709e-06 - 162|1.607197e-01|-2.419565e-09 - 163|1.607194e-01|-2.136882e-06 - 164|1.607194e-01|-1.173754e-09 - 165|1.607192e-01|-8.169238e-07 - 166|1.607191e-01|-9.218755e-07 - 167|1.607189e-01|-9.459255e-07 - 168|1.607187e-01|-1.294835e-06 - 169|1.607186e-01|-5.797668e-07 - 170|1.607186e-01|-4.706272e-08 - 171|1.607183e-01|-1.753383e-06 - 172|1.607183e-01|-1.681573e-07 - 173|1.607183e-01|-2.563971e-10 + Out: + + .. code-block:: none + + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 0|1.692289e-01|0.000000e+00|0.000000e+00 + 1|1.617643e-01|4.614437e-02|7.464513e-03 + 2|1.612639e-01|3.102965e-03|5.003963e-04 + 3|1.611291e-01|8.371098e-04|1.348827e-04 + 4|1.610468e-01|5.110558e-04|8.230389e-05 + 5|1.610198e-01|1.672927e-04|2.693743e-05 + 6|1.610130e-01|4.232417e-05|6.814742e-06 + 7|1.610090e-01|2.513455e-05|4.046887e-06 + 8|1.610002e-01|5.443507e-05|8.764057e-06 + 9|1.609996e-01|3.657071e-06|5.887869e-07 + 10|1.609948e-01|2.998735e-05|4.827807e-06 + 11|1.609695e-01|1.569217e-04|2.525962e-05 + 12|1.609533e-01|1.010779e-04|1.626881e-05 + 13|1.609520e-01|8.043897e-06|1.294681e-06 + 14|1.609465e-01|3.415246e-05|5.496718e-06 + 15|1.609386e-01|4.898605e-05|7.883745e-06 + 16|1.609324e-01|3.837052e-05|6.175060e-06 + 17|1.609298e-01|1.617826e-05|2.603564e-06 + 18|1.609184e-01|7.080015e-05|1.139305e-05 + 19|1.609083e-01|6.273206e-05|1.009411e-05 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 20|1.608988e-01|5.940805e-05|9.558681e-06 + 21|1.608853e-01|8.380030e-05|1.348223e-05 + 22|1.608844e-01|5.185045e-06|8.341930e-07 + 23|1.608824e-01|1.279113e-05|2.057868e-06 + 24|1.608819e-01|3.156821e-06|5.078753e-07 + 25|1.608783e-01|2.205746e-05|3.548567e-06 + 26|1.608764e-01|1.189894e-05|1.914259e-06 + 27|1.608755e-01|5.474607e-06|8.807303e-07 + 28|1.608737e-01|1.144227e-05|1.840760e-06 + 29|1.608676e-01|3.775335e-05|6.073291e-06 + 30|1.608638e-01|2.348020e-05|3.777116e-06 + 31|1.608627e-01|6.863136e-06|1.104023e-06 + 32|1.608529e-01|6.110230e-05|9.828482e-06 + 33|1.608487e-01|2.641106e-05|4.248184e-06 + 34|1.608409e-01|4.823638e-05|7.758383e-06 + 35|1.608373e-01|2.256641e-05|3.629519e-06 + 36|1.608338e-01|2.132444e-05|3.429691e-06 + 37|1.608310e-01|1.786649e-05|2.873484e-06 + 38|1.608260e-01|3.103848e-05|4.991794e-06 + 39|1.608206e-01|3.321265e-05|5.341279e-06 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 40|1.608201e-01|3.054747e-06|4.912648e-07 + 41|1.608195e-01|4.198335e-06|6.751739e-07 + 42|1.608193e-01|8.458736e-07|1.360328e-07 + 43|1.608159e-01|2.153759e-05|3.463587e-06 + 44|1.608115e-01|2.738314e-05|4.403523e-06 + 45|1.608108e-01|3.960032e-06|6.368161e-07 + 46|1.608081e-01|1.675447e-05|2.694254e-06 + 47|1.608072e-01|5.976340e-06|9.610383e-07 + 48|1.608046e-01|1.604130e-05|2.579515e-06 + 49|1.608020e-01|1.617036e-05|2.600226e-06 + 50|1.608014e-01|3.957795e-06|6.364188e-07 + 51|1.608011e-01|1.292411e-06|2.078211e-07 + 52|1.607998e-01|8.431795e-06|1.355831e-06 + 53|1.607964e-01|2.127054e-05|3.420225e-06 + 54|1.607947e-01|1.021878e-05|1.643126e-06 + 55|1.607947e-01|3.560621e-07|5.725288e-08 + 56|1.607900e-01|2.929781e-05|4.710793e-06 + 57|1.607890e-01|5.740229e-06|9.229659e-07 + 58|1.607858e-01|2.039550e-05|3.279306e-06 + 59|1.607836e-01|1.319545e-05|2.121612e-06 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 60|1.607826e-01|6.378947e-06|1.025624e-06 + 61|1.607808e-01|1.145102e-05|1.841105e-06 + 62|1.607776e-01|1.941743e-05|3.121889e-06 + 63|1.607743e-01|2.087422e-05|3.356037e-06 + 64|1.607741e-01|1.310249e-06|2.106541e-07 + 65|1.607738e-01|1.682752e-06|2.705425e-07 + 66|1.607691e-01|2.913936e-05|4.684709e-06 + 67|1.607671e-01|1.288855e-05|2.072055e-06 + 68|1.607654e-01|1.002448e-05|1.611590e-06 + 69|1.607641e-01|8.209492e-06|1.319792e-06 + 70|1.607632e-01|5.588467e-06|8.984199e-07 + 71|1.607619e-01|8.050388e-06|1.294196e-06 + 72|1.607618e-01|9.417493e-07|1.513973e-07 + 73|1.607598e-01|1.210509e-05|1.946012e-06 + 74|1.607591e-01|4.392914e-06|7.062009e-07 + 75|1.607579e-01|7.759587e-06|1.247415e-06 + 76|1.607574e-01|2.760280e-06|4.437356e-07 + 77|1.607556e-01|1.146469e-05|1.843012e-06 + 78|1.607550e-01|3.689456e-06|5.930984e-07 + 79|1.607550e-01|4.065631e-08|6.535705e-09 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 80|1.607539e-01|6.555681e-06|1.053852e-06 + 81|1.607528e-01|7.177470e-06|1.153798e-06 + 82|1.607527e-01|5.306068e-07|8.529648e-08 + 83|1.607514e-01|7.816045e-06|1.256440e-06 + 84|1.607511e-01|2.301970e-06|3.700442e-07 + 85|1.607504e-01|4.281072e-06|6.881840e-07 + 86|1.607503e-01|7.821886e-07|1.257370e-07 + 87|1.607480e-01|1.403013e-05|2.255315e-06 + 88|1.607480e-01|1.169298e-08|1.879624e-09 + 89|1.607473e-01|4.235982e-06|6.809227e-07 + 90|1.607470e-01|1.717105e-06|2.760195e-07 + 91|1.607470e-01|6.148402e-09|9.883374e-10 -Solve EMD with Frobenius norm + entropic regularization -------------------------------------------------------- +Solve EMD with Frobenius norm + entropic regularization +------------------------------------------------------- -.. code-block:: python +.. code-block:: default - #%% Example with Frobenius norm + entropic regularization with gcg def f(G): @@ -619,39 +530,58 @@ Solve EMD with Frobenius norm + entropic regularization -.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_008.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_004.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out - Out:: + Out: - It. |Loss |Delta loss - -------------------------------- - 0|1.693084e-01|0.000000e+00 - 1|1.610121e-01|-5.152589e-02 - 2|1.609378e-01|-4.622297e-04 - 3|1.609284e-01|-5.830043e-05 - 4|1.609284e-01|-1.111407e-12 + .. code-block:: none + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 0|1.693084e-01|0.000000e+00|0.000000e+00 + 1|1.610202e-01|5.147342e-02|8.288260e-03 + 2|1.609508e-01|4.309685e-04|6.936474e-05 + 3|1.609484e-01|1.524885e-05|2.454278e-06 + 4|1.609477e-01|3.863641e-06|6.218444e-07 + 5|1.609475e-01|1.433633e-06|2.307397e-07 + 6|1.609474e-01|6.332412e-07|1.019185e-07 + 7|1.609474e-01|2.950826e-07|4.749276e-08 + 8|1.609473e-01|1.508393e-07|2.427718e-08 + 9|1.609473e-01|7.859971e-08|1.265041e-08 + 10|1.609473e-01|4.337432e-08|6.980981e-09 + /home/rflamary/PYTHON/POT/examples/plot_optim_OTreg.py:129: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 0 minutes 1.990 seconds) + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.985 seconds) + + +.. _sphx_glr_download_auto_examples_plot_optim_OTreg.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_optim_OTreg.py <plot_optim_OTreg.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_optim_OTreg.ipynb <plot_optim_OTreg.ipynb>` @@ -660,4 +590,4 @@ Solve EMD with Frobenius norm + entropic regularization .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_classes.ipynb b/docs/source/auto_examples/plot_otda_classes.ipynb index 643e760..283d227 100644 --- a/docs/source/auto_examples/plot_otda_classes.ipynb +++ b/docs/source/auto_examples/plot_otda_classes.ipynb @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_otda_classes.py b/docs/source/auto_examples/plot_otda_classes.py index c311fbd..f028022 100644 --- a/docs/source/auto_examples/plot_otda_classes.py +++ b/docs/source/auto_examples/plot_otda_classes.py @@ -17,7 +17,6 @@ approaches currently supported in POT. import matplotlib.pylab as pl import ot - ############################################################################## # Generate data # ------------- diff --git a/docs/source/auto_examples/plot_otda_classes.rst b/docs/source/auto_examples/plot_otda_classes.rst index 19756ff..9cf31ee 100644 --- a/docs/source/auto_examples/plot_otda_classes.rst +++ b/docs/source/auto_examples/plot_otda_classes.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_classes.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_otda_classes.py: + .. _sphx_glr_auto_examples_plot_otda_classes.py: ======================== @@ -12,8 +18,7 @@ approaches currently supported in POT. - -.. code-block:: python +.. code-block:: default # Authors: Remi Flamary <remi.flamary@unice.fr> @@ -35,8 +40,7 @@ Generate data ------------- - -.. code-block:: python +.. code-block:: default n_source_samples = 150 @@ -52,12 +56,12 @@ Generate data + Instantiate the different transport algorithms and fit them ----------------------------------------------------------- - -.. code-block:: python +.. code-block:: default # EMD Transport @@ -90,41 +94,44 @@ Instantiate the different transport algorithms and fit them .. rst-class:: sphx-glr-script-out - Out:: - - It. |Loss |Delta loss - -------------------------------- - 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.803696e+00|-1.178279e-04 + Out: + + .. code-block:: none + + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 0|9.484039e+00|0.000000e+00|0.000000e+00 + 1|1.976107e+00|3.799355e+00|7.507932e+00 + 2|1.749871e+00|1.292876e-01|2.262365e-01 + 3|1.692667e+00|3.379504e-02|5.720374e-02 + 4|1.676256e+00|9.790077e-03|1.641068e-02 + 5|1.667458e+00|5.276422e-03|8.798212e-03 + 6|1.661775e+00|3.419693e-03|5.682762e-03 + 7|1.658009e+00|2.271789e-03|3.766646e-03 + 8|1.655167e+00|1.716870e-03|2.841707e-03 + 9|1.651825e+00|2.023380e-03|3.342270e-03 + 10|1.649431e+00|1.451076e-03|2.393450e-03 + 11|1.648649e+00|4.742894e-04|7.819369e-04 + 12|1.647901e+00|4.538219e-04|7.478538e-04 + 13|1.647356e+00|3.313134e-04|5.457909e-04 + 14|1.646923e+00|2.627246e-04|4.326871e-04 + 15|1.646038e+00|5.375014e-04|8.847478e-04 + 16|1.645629e+00|2.483240e-04|4.086492e-04 + 17|1.645616e+00|8.248172e-06|1.357332e-05 + 18|1.645377e+00|1.452648e-04|2.390153e-04 + 19|1.644745e+00|3.838976e-04|6.314139e-04 + It. |Loss |Relative loss|Absolute loss + ------------------------------------------------ + 20|1.644164e+00|3.538439e-04|5.817773e-04 + + Fig 1 : plots source and target samples --------------------------------------- - -.. code-block:: python +.. code-block:: default pl.figure(1, figsize=(10, 5)) @@ -148,7 +155,8 @@ Fig 1 : plots source and target samples .. image:: /auto_examples/images/sphx_glr_plot_otda_classes_001.png - :align: center + :class: sphx-glr-single-img + @@ -157,8 +165,7 @@ Fig 2 : plot optimal couplings and transported samples ------------------------------------------------------ - -.. code-block:: python +.. code-block:: default param_img = {'interpolation': 'nearest'} @@ -230,28 +237,45 @@ Fig 2 : plot optimal couplings and transported samples -.. image:: /auto_examples/images/sphx_glr_plot_otda_classes_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_classes_002.png + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_otda_classes.py:149: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + -**Total running time of the script:** ( 0 minutes 1.423 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 2.083 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_classes.py: + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_otda_classes.py <plot_otda_classes.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_otda_classes.ipynb <plot_otda_classes.ipynb>` @@ -260,4 +284,4 @@ Fig 2 : plot optimal couplings and transported samples .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_color_images.ipynb b/docs/source/auto_examples/plot_otda_color_images.ipynb index 103bdec..c2afd41 100644 --- a/docs/source/auto_examples/plot_otda_color_images.ipynb +++ b/docs/source/auto_examples/plot_otda_color_images.ipynb @@ -26,7 +26,7 @@ }, "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\nfrom scipy import ndimage\nimport matplotlib.pylab as pl\nimport ot\n\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts an image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" + "# 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\n\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts an image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" ] }, { @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "# Loading images\nI1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" + "# Loading images\nI1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" ] }, { @@ -136,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.7" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_otda_color_images.py b/docs/source/auto_examples/plot_otda_color_images.py index 62383a2..d9cbd2b 100644 --- a/docs/source/auto_examples/plot_otda_color_images.py +++ b/docs/source/auto_examples/plot_otda_color_images.py @@ -18,7 +18,6 @@ SIAM Journal on Imaging Sciences, 7(3), 1853-1882. # License: MIT License import numpy as np -from scipy import ndimage import matplotlib.pylab as pl import ot @@ -45,8 +44,8 @@ def minmax(I): # ------------- # Loading images -I1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256 -I2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 +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) diff --git a/docs/source/auto_examples/plot_otda_color_images.rst b/docs/source/auto_examples/plot_otda_color_images.rst index ab0406e..a5b0d53 100644 --- a/docs/source/auto_examples/plot_otda_color_images.rst +++ b/docs/source/auto_examples/plot_otda_color_images.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_color_images.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_otda_color_images.py: + .. _sphx_glr_auto_examples_plot_otda_color_images.py: ============================= @@ -15,8 +21,7 @@ Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882. - -.. code-block:: python +.. code-block:: default # Authors: Remi Flamary <remi.flamary@unice.fr> @@ -25,7 +30,6 @@ SIAM Journal on Imaging Sciences, 7(3), 1853-1882. # License: MIT License import numpy as np - from scipy import ndimage import matplotlib.pylab as pl import ot @@ -53,17 +57,17 @@ SIAM Journal on Imaging Sciences, 7(3), 1853-1882. + Generate data ------------- - -.. code-block:: python +.. code-block:: default # Loading images - I1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256 - I2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 + 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) @@ -83,12 +87,12 @@ Generate data + Plot original image ------------------- - -.. code-block:: python +.. code-block:: default pl.figure(1, figsize=(6.4, 3)) @@ -108,17 +112,25 @@ Plot original image .. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_001.png - :align: center + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + + Text(0.5, 1.0, 'Image 2') + Scatter plot of colors ---------------------- - -.. code-block:: python +.. code-block:: default pl.figure(2, figsize=(6.4, 3)) @@ -142,8 +154,9 @@ Scatter plot of colors -.. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_002.png + :class: sphx-glr-single-img + @@ -152,8 +165,7 @@ Instantiate the different transport algorithms and fit them ----------------------------------------------------------- - -.. code-block:: python +.. code-block:: default # EMDTransport @@ -184,12 +196,12 @@ Instantiate the different transport algorithms and fit them + Plot new images --------------- - -.. code-block:: python +.. code-block:: default pl.figure(3, figsize=(8, 4)) @@ -229,28 +241,45 @@ Plot new images -.. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_005.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_color_images_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_otda_color_images.py:164: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + -**Total running time of the script:** ( 3 minutes 55.541 seconds) +.. rst-class:: sphx-glr-timing + **Total running time of the script:** ( 2 minutes 28.821 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_color_images.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_otda_color_images.py <plot_otda_color_images.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_otda_color_images.ipynb <plot_otda_color_images.ipynb>` @@ -259,4 +288,4 @@ Plot new images .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_d2.ipynb b/docs/source/auto_examples/plot_otda_d2.ipynb index b9002ee..a2a7839 100644 --- a/docs/source/auto_examples/plot_otda_d2.ipynb +++ b/docs/source/auto_examples/plot_otda_d2.ipynb @@ -136,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_otda_d2.rst b/docs/source/auto_examples/plot_otda_d2.rst index 80cc34c..6d8e429 100644 --- a/docs/source/auto_examples/plot_otda_d2.rst +++ b/docs/source/auto_examples/plot_otda_d2.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_d2.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_otda_d2.py: + .. _sphx_glr_auto_examples_plot_otda_d2.py: =================================================== @@ -16,8 +22,7 @@ transported samples are represented in order to give a visual understanding of what the transport methods are doing. - -.. code-block:: python +.. code-block:: default # Authors: Remi Flamary <remi.flamary@unice.fr> @@ -35,12 +40,12 @@ of what the transport methods are doing. + generate data ------------- - -.. code-block:: python +.. code-block:: default n_samples_source = 150 @@ -59,12 +64,12 @@ generate data + Instantiate the different transport algorithms and fit them ----------------------------------------------------------- - -.. code-block:: python +.. code-block:: default # EMD Transport @@ -91,12 +96,12 @@ Instantiate the different transport algorithms and fit them + Fig 1 : plots source and target samples + matrix of pairwise distance --------------------------------------------------------------------- - -.. code-block:: python +.. code-block:: default pl.figure(1, figsize=(10, 10)) @@ -126,7 +131,8 @@ Fig 1 : plots source and target samples + matrix of pairwise distance .. image:: /auto_examples/images/sphx_glr_plot_otda_d2_001.png - :align: center + :class: sphx-glr-single-img + @@ -135,8 +141,7 @@ Fig 2 : plots optimal couplings for the different methods --------------------------------------------------------- - -.. code-block:: python +.. code-block:: default pl.figure(2, figsize=(10, 6)) @@ -187,8 +192,9 @@ Fig 2 : plots optimal couplings for the different methods -.. image:: /auto_examples/images/sphx_glr_plot_otda_d2_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_d2_002.png + :class: sphx-glr-single-img + @@ -197,8 +203,7 @@ Fig 3 : plot transported samples -------------------------------- - -.. code-block:: python +.. code-block:: default # display transported samples @@ -236,28 +241,45 @@ Fig 3 : plot transported samples -.. image:: /auto_examples/images/sphx_glr_plot_otda_d2_006.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_d2_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_otda_d2.py:172: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 0 minutes 35.515 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 21.323 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_d2.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_otda_d2.py <plot_otda_d2.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_otda_d2.ipynb <plot_otda_d2.ipynb>` @@ -266,4 +288,4 @@ Fig 3 : plot transported samples .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_jcpot.ipynb b/docs/source/auto_examples/plot_otda_jcpot.ipynb new file mode 100644 index 0000000..a81d47a --- /dev/null +++ b/docs/source/auto_examples/plot_otda_jcpot.ipynb @@ -0,0 +1,173 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# OT for multi-source target shift\n\n\nThis example introduces a target shift problem with two 2D source and 1 target domain.\n\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Authors: Remi Flamary <remi.flamary@unice.fr>\n# Ievgen Redko <ievgen.redko@univ-st-etienne.fr>\n#\n# License: MIT License\n\nimport pylab as pl\nimport numpy as np\nimport ot\nfrom ot.datasets import make_data_classif" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Generate data\n-------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "n = 50\nsigma = 0.3\nnp.random.seed(1985)\n\np1 = .2\ndec1 = [0, 2]\n\np2 = .9\ndec2 = [0, -2]\n\npt = .4\ndect = [4, 0]\n\nxs1, ys1 = make_data_classif('2gauss_prop', n, nz=sigma, p=p1, bias=dec1)\nxs2, ys2 = make_data_classif('2gauss_prop', n + 1, nz=sigma, p=p2, bias=dec2)\nxt, yt = make_data_classif('2gauss_prop', n, nz=sigma, p=pt, bias=dect)\n\nall_Xr = [xs1, xs2]\nall_Yr = [ys1, ys2]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "da = 1.5\n\n\ndef plot_ax(dec, name):\n pl.plot([dec[0], dec[0]], [dec[1] - da, dec[1] + da], 'k', alpha=0.5)\n pl.plot([dec[0] - da, dec[0] + da], [dec[1], dec[1]], 'k', alpha=0.5)\n pl.text(dec[0] - .5, dec[1] + 2, name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Fig 1 : plots source and target samples\n---------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(1)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9,\n label='Source 1 ({:1.2f}, {:1.2f})'.format(1 - p1, p1))\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9,\n label='Source 2 ({:1.2f}, {:1.2f})'.format(1 - p2, p2))\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9,\n label='Target ({:1.2f}, {:1.2f})'.format(1 - pt, pt))\npl.title('Data')\n\npl.legend()\npl.axis('equal')\npl.axis('off')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instantiate Sinkhorn transport algorithm and fit them for all source domains\n----------------------------------------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1, metric='sqeuclidean')\n\n\ndef print_G(G, xs, ys, xt):\n for i in range(G.shape[0]):\n for j in range(G.shape[1]):\n if G[i, j] > 5e-4:\n if ys[i]:\n c = 'b'\n else:\n c = 'r'\n pl.plot([xs[i, 0], xt[j, 0]], [xs[i, 1], xt[j, 1]], c, alpha=.2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Fig 2 : plot optimal couplings and transported samples\n------------------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(2)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\nprint_G(ot_sinkhorn.fit(Xs=xs1, Xt=xt).coupling_, xs1, ys1, xt)\nprint_G(ot_sinkhorn.fit(Xs=xs2, Xt=xt).coupling_, xs2, ys2, xt)\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9)\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9)\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9)\n\npl.plot([], [], 'r', alpha=.2, label='Mass from Class 1')\npl.plot([], [], 'b', alpha=.2, label='Mass from Class 2')\n\npl.title('Independent OT')\n\npl.legend()\npl.axis('equal')\npl.axis('off')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instantiate JCPOT adaptation algorithm and fit it\n----------------------------------------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "otda = ot.da.JCPOTTransport(reg_e=1, max_iter=1000, metric='sqeuclidean', tol=1e-9, verbose=True, log=True)\notda.fit(all_Xr, all_Yr, xt)\n\nws1 = otda.proportions_.dot(otda.log_['D2'][0])\nws2 = otda.proportions_.dot(otda.log_['D2'][1])\n\npl.figure(3)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\nprint_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt)\nprint_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt)\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9)\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9)\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9)\n\npl.plot([], [], 'r', alpha=.2, label='Mass from Class 1')\npl.plot([], [], 'b', alpha=.2, label='Mass from Class 2')\n\npl.title('OT with prop estimation ({:1.3f},{:1.3f})'.format(otda.proportions_[0], otda.proportions_[1]))\n\npl.legend()\npl.axis('equal')\npl.axis('off')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Run oracle transport algorithm with known proportions\n----------------------------------------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "h_res = np.array([1 - pt, pt])\n\nws1 = h_res.dot(otda.log_['D2'][0])\nws2 = h_res.dot(otda.log_['D2'][1])\n\npl.figure(4)\npl.clf()\nplot_ax(dec1, 'Source 1')\nplot_ax(dec2, 'Source 2')\nplot_ax(dect, 'Target')\nprint_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt)\nprint_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt)\npl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9)\npl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9)\npl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9)\n\npl.plot([], [], 'r', alpha=.2, label='Mass from Class 1')\npl.plot([], [], 'b', alpha=.2, label='Mass from Class 2')\n\npl.title('OT with known proportion ({:1.1f},{:1.1f})'.format(h_res[0], h_res[1]))\n\npl.legend()\npl.axis('equal')\npl.axis('off')\npl.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}
\ No newline at end of file diff --git a/docs/source/auto_examples/plot_otda_jcpot.py b/docs/source/auto_examples/plot_otda_jcpot.py new file mode 100644 index 0000000..c495690 --- /dev/null +++ b/docs/source/auto_examples/plot_otda_jcpot.py @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- +""" +======================== +OT for multi-source target shift +======================== + +This example introduces a target shift problem with two 2D source and 1 target domain. + +""" + +# Authors: Remi Flamary <remi.flamary@unice.fr> +# Ievgen Redko <ievgen.redko@univ-st-etienne.fr> +# +# License: MIT License + +import pylab as pl +import numpy as np +import ot +from ot.datasets import make_data_classif + +############################################################################## +# Generate data +# ------------- +n = 50 +sigma = 0.3 +np.random.seed(1985) + +p1 = .2 +dec1 = [0, 2] + +p2 = .9 +dec2 = [0, -2] + +pt = .4 +dect = [4, 0] + +xs1, ys1 = make_data_classif('2gauss_prop', n, nz=sigma, p=p1, bias=dec1) +xs2, ys2 = make_data_classif('2gauss_prop', n + 1, nz=sigma, p=p2, bias=dec2) +xt, yt = make_data_classif('2gauss_prop', n, nz=sigma, p=pt, bias=dect) + +all_Xr = [xs1, xs2] +all_Yr = [ys1, ys2] +# %% + +da = 1.5 + + +def plot_ax(dec, name): + pl.plot([dec[0], dec[0]], [dec[1] - da, dec[1] + da], 'k', alpha=0.5) + pl.plot([dec[0] - da, dec[0] + da], [dec[1], dec[1]], 'k', alpha=0.5) + pl.text(dec[0] - .5, dec[1] + 2, name) + + +############################################################################## +# Fig 1 : plots source and target samples +# --------------------------------------- + +pl.figure(1) +pl.clf() +plot_ax(dec1, 'Source 1') +plot_ax(dec2, 'Source 2') +plot_ax(dect, 'Target') +pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9, + label='Source 1 ({:1.2f}, {:1.2f})'.format(1 - p1, p1)) +pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9, + label='Source 2 ({:1.2f}, {:1.2f})'.format(1 - p2, p2)) +pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9, + label='Target ({:1.2f}, {:1.2f})'.format(1 - pt, pt)) +pl.title('Data') + +pl.legend() +pl.axis('equal') +pl.axis('off') + +############################################################################## +# Instantiate Sinkhorn transport algorithm and fit them for all source domains +# ---------------------------------------------------------------------------- +ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1, metric='sqeuclidean') + + +def print_G(G, xs, ys, xt): + for i in range(G.shape[0]): + for j in range(G.shape[1]): + if G[i, j] > 5e-4: + if ys[i]: + c = 'b' + else: + c = 'r' + pl.plot([xs[i, 0], xt[j, 0]], [xs[i, 1], xt[j, 1]], c, alpha=.2) + + +############################################################################## +# Fig 2 : plot optimal couplings and transported samples +# ------------------------------------------------------ +pl.figure(2) +pl.clf() +plot_ax(dec1, 'Source 1') +plot_ax(dec2, 'Source 2') +plot_ax(dect, 'Target') +print_G(ot_sinkhorn.fit(Xs=xs1, Xt=xt).coupling_, xs1, ys1, xt) +print_G(ot_sinkhorn.fit(Xs=xs2, Xt=xt).coupling_, xs2, ys2, xt) +pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) +pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) +pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) + +pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') +pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') + +pl.title('Independent OT') + +pl.legend() +pl.axis('equal') +pl.axis('off') + +############################################################################## +# Instantiate JCPOT adaptation algorithm and fit it +# ---------------------------------------------------------------------------- +otda = ot.da.JCPOTTransport(reg_e=1, max_iter=1000, metric='sqeuclidean', tol=1e-9, verbose=True, log=True) +otda.fit(all_Xr, all_Yr, xt) + +ws1 = otda.proportions_.dot(otda.log_['D2'][0]) +ws2 = otda.proportions_.dot(otda.log_['D2'][1]) + +pl.figure(3) +pl.clf() +plot_ax(dec1, 'Source 1') +plot_ax(dec2, 'Source 2') +plot_ax(dect, 'Target') +print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) +print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) +pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) +pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) +pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) + +pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') +pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') + +pl.title('OT with prop estimation ({:1.3f},{:1.3f})'.format(otda.proportions_[0], otda.proportions_[1])) + +pl.legend() +pl.axis('equal') +pl.axis('off') + +############################################################################## +# Run oracle transport algorithm with known proportions +# ---------------------------------------------------------------------------- +h_res = np.array([1 - pt, pt]) + +ws1 = h_res.dot(otda.log_['D2'][0]) +ws2 = h_res.dot(otda.log_['D2'][1]) + +pl.figure(4) +pl.clf() +plot_ax(dec1, 'Source 1') +plot_ax(dec2, 'Source 2') +plot_ax(dect, 'Target') +print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) +print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) +pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) +pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) +pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) + +pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') +pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') + +pl.title('OT with known proportion ({:1.1f},{:1.1f})'.format(h_res[0], h_res[1])) + +pl.legend() +pl.axis('equal') +pl.axis('off') +pl.show() diff --git a/docs/source/auto_examples/plot_otda_jcpot.rst b/docs/source/auto_examples/plot_otda_jcpot.rst new file mode 100644 index 0000000..3433190 --- /dev/null +++ b/docs/source/auto_examples/plot_otda_jcpot.rst @@ -0,0 +1,336 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_jcpot.py>` to download the full example code + .. rst-class:: sphx-glr-example-title + + .. _sphx_glr_auto_examples_plot_otda_jcpot.py: + + +======================== +OT for multi-source target shift +======================== + +This example introduces a target shift problem with two 2D source and 1 target domain. + + + +.. code-block:: default + + + # Authors: Remi Flamary <remi.flamary@unice.fr> + # Ievgen Redko <ievgen.redko@univ-st-etienne.fr> + # + # License: MIT License + + import pylab as pl + import numpy as np + import ot + from ot.datasets import make_data_classif + + + + + + + + +Generate data +------------- + + +.. code-block:: default + + n = 50 + sigma = 0.3 + np.random.seed(1985) + + p1 = .2 + dec1 = [0, 2] + + p2 = .9 + dec2 = [0, -2] + + pt = .4 + dect = [4, 0] + + xs1, ys1 = make_data_classif('2gauss_prop', n, nz=sigma, p=p1, bias=dec1) + xs2, ys2 = make_data_classif('2gauss_prop', n + 1, nz=sigma, p=p2, bias=dec2) + xt, yt = make_data_classif('2gauss_prop', n, nz=sigma, p=pt, bias=dect) + + all_Xr = [xs1, xs2] + all_Yr = [ys1, ys2] + + + + + + + + +.. code-block:: default + + + da = 1.5 + + + def plot_ax(dec, name): + pl.plot([dec[0], dec[0]], [dec[1] - da, dec[1] + da], 'k', alpha=0.5) + pl.plot([dec[0] - da, dec[0] + da], [dec[1], dec[1]], 'k', alpha=0.5) + pl.text(dec[0] - .5, dec[1] + 2, name) + + + + + + + + + +Fig 1 : plots source and target samples +--------------------------------------- + + +.. code-block:: default + + + pl.figure(1) + pl.clf() + plot_ax(dec1, 'Source 1') + plot_ax(dec2, 'Source 2') + plot_ax(dect, 'Target') + pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9, + label='Source 1 ({:1.2f}, {:1.2f})'.format(1 - p1, p1)) + pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9, + label='Source 2 ({:1.2f}, {:1.2f})'.format(1 - p2, p2)) + pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9, + label='Target ({:1.2f}, {:1.2f})'.format(1 - pt, pt)) + pl.title('Data') + + pl.legend() + pl.axis('equal') + pl.axis('off') + + + + +.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + + (-1.85, 5.85, -4.1171725099266725, 4.197384527473105) + + + +Instantiate Sinkhorn transport algorithm and fit them for all source domains +---------------------------------------------------------------------------- + + +.. code-block:: default + + ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1, metric='sqeuclidean') + + + def print_G(G, xs, ys, xt): + for i in range(G.shape[0]): + for j in range(G.shape[1]): + if G[i, j] > 5e-4: + if ys[i]: + c = 'b' + else: + c = 'r' + pl.plot([xs[i, 0], xt[j, 0]], [xs[i, 1], xt[j, 1]], c, alpha=.2) + + + + + + + + + +Fig 2 : plot optimal couplings and transported samples +------------------------------------------------------ + + +.. code-block:: default + + pl.figure(2) + pl.clf() + plot_ax(dec1, 'Source 1') + plot_ax(dec2, 'Source 2') + plot_ax(dect, 'Target') + print_G(ot_sinkhorn.fit(Xs=xs1, Xt=xt).coupling_, xs1, ys1, xt) + print_G(ot_sinkhorn.fit(Xs=xs2, Xt=xt).coupling_, xs2, ys2, xt) + pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) + pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) + pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) + + pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') + pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') + + pl.title('Independent OT') + + pl.legend() + pl.axis('equal') + pl.axis('off') + + + + +.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_002.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + + (-1.85, 5.85, -4.11901398007908, 4.201462272227509) + + + +Instantiate JCPOT adaptation algorithm and fit it +---------------------------------------------------------------------------- + + +.. code-block:: default + + otda = ot.da.JCPOTTransport(reg_e=1, max_iter=1000, metric='sqeuclidean', tol=1e-9, verbose=True, log=True) + otda.fit(all_Xr, all_Yr, xt) + + ws1 = otda.proportions_.dot(otda.log_['D2'][0]) + ws2 = otda.proportions_.dot(otda.log_['D2'][1]) + + pl.figure(3) + pl.clf() + plot_ax(dec1, 'Source 1') + plot_ax(dec2, 'Source 2') + plot_ax(dect, 'Target') + print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) + print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) + pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) + pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) + pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) + + pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') + pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') + + pl.title('OT with prop estimation ({:1.3f},{:1.3f})'.format(otda.proportions_[0], otda.proportions_[1])) + + pl.legend() + pl.axis('equal') + pl.axis('off') + + + + +.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + + (-1.85, 5.85, -4.11901398007908, 4.201462272227509) + + + +Run oracle transport algorithm with known proportions +---------------------------------------------------------------------------- + + +.. code-block:: default + + h_res = np.array([1 - pt, pt]) + + ws1 = h_res.dot(otda.log_['D2'][0]) + ws2 = h_res.dot(otda.log_['D2'][1]) + + pl.figure(4) + pl.clf() + plot_ax(dec1, 'Source 1') + plot_ax(dec2, 'Source 2') + plot_ax(dect, 'Target') + print_G(ot.bregman.sinkhorn(ws1, [], otda.log_['M'][0], reg=1e-1), xs1, ys1, xt) + print_G(ot.bregman.sinkhorn(ws2, [], otda.log_['M'][1], reg=1e-1), xs2, ys2, xt) + pl.scatter(xs1[:, 0], xs1[:, 1], c=ys1, s=35, marker='x', cmap='Set1', vmax=9) + pl.scatter(xs2[:, 0], xs2[:, 1], c=ys2, s=35, marker='+', cmap='Set1', vmax=9) + pl.scatter(xt[:, 0], xt[:, 1], c=yt, s=35, marker='o', cmap='Set1', vmax=9) + + pl.plot([], [], 'r', alpha=.2, label='Mass from Class 1') + pl.plot([], [], 'b', alpha=.2, label='Mass from Class 2') + + pl.title('OT with known proportion ({:1.1f},{:1.1f})'.format(h_res[0], h_res[1])) + + pl.legend() + pl.axis('equal') + pl.axis('off') + pl.show() + + + +.. image:: /auto_examples/images/sphx_glr_plot_otda_jcpot_004.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_otda_jcpot.py:171: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 4.725 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_jcpot.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_otda_jcpot.py <plot_otda_jcpot.py>` + + + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_otda_jcpot.ipynb <plot_otda_jcpot.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_laplacian.ipynb b/docs/source/auto_examples/plot_otda_laplacian.ipynb new file mode 100644 index 0000000..c1e9efe --- /dev/null +++ b/docs/source/auto_examples/plot_otda_laplacian.ipynb @@ -0,0 +1,126 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# OT with Laplacian regularization for domain adaptation\n\n\nThis example introduces a domain adaptation in a 2D setting and OTDA\napproach with Laplacian regularization.\n\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Authors: Ievgen Redko <ievgen.redko@univ-st-etienne.fr>\n\n# License: MIT License\n\nimport matplotlib.pylab as pl\nimport ot" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Generate data\n-------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "n_source_samples = 150\nn_target_samples = 150\n\nXs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples)\nXt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instantiate the different transport algorithms and fit them\n-----------------------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# EMD Transport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\n\n# Sinkhorn Transport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=.01)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\n\n# EMD Transport with Laplacian regularization\not_emd_laplace = ot.da.EMDLaplaceTransport(reg_lap=100, reg_src=1)\not_emd_laplace.fit(Xs=Xs, Xt=Xt)\n\n# transport source samples onto target samples\ntransp_Xs_emd = ot_emd.transform(Xs=Xs)\ntransp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=Xs)\ntransp_Xs_emd_laplace = ot_emd_laplace.transform(Xs=Xs)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Fig 1 : plots source and target samples\n---------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(1, figsize=(10, 5))\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples')\npl.xticks([])\npl.yticks([])\npl.legend(loc=0)\npl.title('Source samples')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples')\npl.xticks([])\npl.yticks([])\npl.legend(loc=0)\npl.title('Target samples')\npl.tight_layout()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Fig 2 : plot optimal couplings and transported samples\n------------------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "param_img = {'interpolation': 'nearest'}\n\npl.figure(2, figsize=(15, 8))\npl.subplot(2, 3, 1)\npl.imshow(ot_emd.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nEMDTransport')\n\npl.figure(2, figsize=(15, 8))\npl.subplot(2, 3, 2)\npl.imshow(ot_sinkhorn.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nSinkhornTransport')\n\npl.subplot(2, 3, 3)\npl.imshow(ot_emd_laplace.coupling_, **param_img)\npl.xticks([])\npl.yticks([])\npl.title('Optimal coupling\\nEMDLaplaceTransport')\n\npl.subplot(2, 3, 4)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nEmdTransport')\npl.legend(loc=\"lower left\")\n\npl.subplot(2, 3, 5)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nSinkhornTransport')\n\npl.subplot(2, 3, 6)\npl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o',\n label='Target samples', alpha=0.3)\npl.scatter(transp_Xs_emd_laplace[:, 0], transp_Xs_emd_laplace[:, 1], c=ys,\n marker='+', label='Transp samples', s=30)\npl.xticks([])\npl.yticks([])\npl.title('Transported samples\\nEMDLaplaceTransport')\npl.tight_layout()\n\npl.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}
\ No newline at end of file diff --git a/docs/source/auto_examples/plot_otda_laplacian.py b/docs/source/auto_examples/plot_otda_laplacian.py new file mode 100644 index 0000000..67c8f67 --- /dev/null +++ b/docs/source/auto_examples/plot_otda_laplacian.py @@ -0,0 +1,127 @@ +# -*- coding: utf-8 -*- +""" +====================================================== +OT with Laplacian regularization for domain adaptation +====================================================== + +This example introduces a domain adaptation in a 2D setting and OTDA +approach with Laplacian regularization. + +""" + +# Authors: Ievgen Redko <ievgen.redko@univ-st-etienne.fr> + +# License: MIT License + +import matplotlib.pylab as pl +import ot + +############################################################################## +# Generate data +# ------------- + +n_source_samples = 150 +n_target_samples = 150 + +Xs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples) +Xt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples) + + +############################################################################## +# Instantiate the different transport algorithms and fit them +# ----------------------------------------------------------- + +# EMD Transport +ot_emd = ot.da.EMDTransport() +ot_emd.fit(Xs=Xs, Xt=Xt) + +# Sinkhorn Transport +ot_sinkhorn = ot.da.SinkhornTransport(reg_e=.01) +ot_sinkhorn.fit(Xs=Xs, Xt=Xt) + +# EMD Transport with Laplacian regularization +ot_emd_laplace = ot.da.EMDLaplaceTransport(reg_lap=100, reg_src=1) +ot_emd_laplace.fit(Xs=Xs, Xt=Xt) + +# transport source samples onto target samples +transp_Xs_emd = ot_emd.transform(Xs=Xs) +transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=Xs) +transp_Xs_emd_laplace = ot_emd_laplace.transform(Xs=Xs) + +############################################################################## +# Fig 1 : plots source and target samples +# --------------------------------------- + +pl.figure(1, figsize=(10, 5)) +pl.subplot(1, 2, 1) +pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') +pl.xticks([]) +pl.yticks([]) +pl.legend(loc=0) +pl.title('Source samples') + +pl.subplot(1, 2, 2) +pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') +pl.xticks([]) +pl.yticks([]) +pl.legend(loc=0) +pl.title('Target samples') +pl.tight_layout() + + +############################################################################## +# Fig 2 : plot optimal couplings and transported samples +# ------------------------------------------------------ + +param_img = {'interpolation': 'nearest'} + +pl.figure(2, figsize=(15, 8)) +pl.subplot(2, 3, 1) +pl.imshow(ot_emd.coupling_, **param_img) +pl.xticks([]) +pl.yticks([]) +pl.title('Optimal coupling\nEMDTransport') + +pl.figure(2, figsize=(15, 8)) +pl.subplot(2, 3, 2) +pl.imshow(ot_sinkhorn.coupling_, **param_img) +pl.xticks([]) +pl.yticks([]) +pl.title('Optimal coupling\nSinkhornTransport') + +pl.subplot(2, 3, 3) +pl.imshow(ot_emd_laplace.coupling_, **param_img) +pl.xticks([]) +pl.yticks([]) +pl.title('Optimal coupling\nEMDLaplaceTransport') + +pl.subplot(2, 3, 4) +pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', + label='Target samples', alpha=0.3) +pl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys, + marker='+', label='Transp samples', s=30) +pl.xticks([]) +pl.yticks([]) +pl.title('Transported samples\nEmdTransport') +pl.legend(loc="lower left") + +pl.subplot(2, 3, 5) +pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', + label='Target samples', alpha=0.3) +pl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys, + marker='+', label='Transp samples', s=30) +pl.xticks([]) +pl.yticks([]) +pl.title('Transported samples\nSinkhornTransport') + +pl.subplot(2, 3, 6) +pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', + label='Target samples', alpha=0.3) +pl.scatter(transp_Xs_emd_laplace[:, 0], transp_Xs_emd_laplace[:, 1], c=ys, + marker='+', label='Transp samples', s=30) +pl.xticks([]) +pl.yticks([]) +pl.title('Transported samples\nEMDLaplaceTransport') +pl.tight_layout() + +pl.show() diff --git a/docs/source/auto_examples/plot_otda_laplacian.rst b/docs/source/auto_examples/plot_otda_laplacian.rst new file mode 100644 index 0000000..12cd7b9 --- /dev/null +++ b/docs/source/auto_examples/plot_otda_laplacian.rst @@ -0,0 +1,233 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_laplacian.py>` to download the full example code + .. rst-class:: sphx-glr-example-title + + .. _sphx_glr_auto_examples_plot_otda_laplacian.py: + + +====================================================== +OT with Laplacian regularization for domain adaptation +====================================================== + +This example introduces a domain adaptation in a 2D setting and OTDA +approach with Laplacian regularization. + + + +.. code-block:: default + + + # Authors: Ievgen Redko <ievgen.redko@univ-st-etienne.fr> + + # License: MIT License + + import matplotlib.pylab as pl + import ot + + + + + + + + +Generate data +------------- + + +.. code-block:: default + + + n_source_samples = 150 + n_target_samples = 150 + + Xs, ys = ot.datasets.make_data_classif('3gauss', n_source_samples) + Xt, yt = ot.datasets.make_data_classif('3gauss2', n_target_samples) + + + + + + + + + +Instantiate the different transport algorithms and fit them +----------------------------------------------------------- + + +.. code-block:: default + + + # EMD Transport + ot_emd = ot.da.EMDTransport() + ot_emd.fit(Xs=Xs, Xt=Xt) + + # Sinkhorn Transport + ot_sinkhorn = ot.da.SinkhornTransport(reg_e=.01) + ot_sinkhorn.fit(Xs=Xs, Xt=Xt) + + # EMD Transport with Laplacian regularization + ot_emd_laplace = ot.da.EMDLaplaceTransport(reg_lap=100, reg_src=1) + ot_emd_laplace.fit(Xs=Xs, Xt=Xt) + + # transport source samples onto target samples + transp_Xs_emd = ot_emd.transform(Xs=Xs) + transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=Xs) + transp_Xs_emd_laplace = ot_emd_laplace.transform(Xs=Xs) + + + + + + + + +Fig 1 : plots source and target samples +--------------------------------------- + + +.. code-block:: default + + + pl.figure(1, figsize=(10, 5)) + pl.subplot(1, 2, 1) + pl.scatter(Xs[:, 0], Xs[:, 1], c=ys, marker='+', label='Source samples') + pl.xticks([]) + pl.yticks([]) + pl.legend(loc=0) + pl.title('Source samples') + + pl.subplot(1, 2, 2) + pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', label='Target samples') + pl.xticks([]) + pl.yticks([]) + pl.legend(loc=0) + pl.title('Target samples') + pl.tight_layout() + + + + + +.. image:: /auto_examples/images/sphx_glr_plot_otda_laplacian_001.png + :class: sphx-glr-single-img + + + + + +Fig 2 : plot optimal couplings and transported samples +------------------------------------------------------ + + +.. code-block:: default + + + param_img = {'interpolation': 'nearest'} + + pl.figure(2, figsize=(15, 8)) + pl.subplot(2, 3, 1) + pl.imshow(ot_emd.coupling_, **param_img) + pl.xticks([]) + pl.yticks([]) + pl.title('Optimal coupling\nEMDTransport') + + pl.figure(2, figsize=(15, 8)) + pl.subplot(2, 3, 2) + pl.imshow(ot_sinkhorn.coupling_, **param_img) + pl.xticks([]) + pl.yticks([]) + pl.title('Optimal coupling\nSinkhornTransport') + + pl.subplot(2, 3, 3) + pl.imshow(ot_emd_laplace.coupling_, **param_img) + pl.xticks([]) + pl.yticks([]) + pl.title('Optimal coupling\nEMDLaplaceTransport') + + pl.subplot(2, 3, 4) + pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', + label='Target samples', alpha=0.3) + pl.scatter(transp_Xs_emd[:, 0], transp_Xs_emd[:, 1], c=ys, + marker='+', label='Transp samples', s=30) + pl.xticks([]) + pl.yticks([]) + pl.title('Transported samples\nEmdTransport') + pl.legend(loc="lower left") + + pl.subplot(2, 3, 5) + pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', + label='Target samples', alpha=0.3) + pl.scatter(transp_Xs_sinkhorn[:, 0], transp_Xs_sinkhorn[:, 1], c=ys, + marker='+', label='Transp samples', s=30) + pl.xticks([]) + pl.yticks([]) + pl.title('Transported samples\nSinkhornTransport') + + pl.subplot(2, 3, 6) + pl.scatter(Xt[:, 0], Xt[:, 1], c=yt, marker='o', + label='Target samples', alpha=0.3) + pl.scatter(transp_Xs_emd_laplace[:, 0], transp_Xs_emd_laplace[:, 1], c=ys, + marker='+', label='Transp samples', s=30) + pl.xticks([]) + pl.yticks([]) + pl.title('Transported samples\nEMDLaplaceTransport') + pl.tight_layout() + + pl.show() + + + +.. image:: /auto_examples/images/sphx_glr_plot_otda_laplacian_002.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_otda_laplacian.py:127: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.195 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_laplacian.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_otda_laplacian.py <plot_otda_laplacian.py>` + + + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_otda_laplacian.ipynb <plot_otda_laplacian.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_linear_mapping.ipynb b/docs/source/auto_examples/plot_otda_linear_mapping.ipynb index 027b6cb..96eccbe 100644 --- a/docs/source/auto_examples/plot_otda_linear_mapping.ipynb +++ b/docs/source/auto_examples/plot_otda_linear_mapping.ipynb @@ -134,7 +134,7 @@ }, "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# %%" + "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))" ] }, { @@ -172,7 +172,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_otda_linear_mapping.rst b/docs/source/auto_examples/plot_otda_linear_mapping.rst index 8e2e0cf..63848d2 100644 --- a/docs/source/auto_examples/plot_otda_linear_mapping.rst +++ b/docs/source/auto_examples/plot_otda_linear_mapping.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_linear_mapping.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_otda_linear_mapping.py: + .. _sphx_glr_auto_examples_plot_otda_linear_mapping.py: ============================ @@ -10,8 +16,7 @@ Linear OT mapping estimation - -.. code-block:: python +.. code-block:: default # Author: Remi Flamary <remi.flamary@unice.fr> @@ -28,12 +33,12 @@ Linear OT mapping estimation + Generate data ------------- - -.. code-block:: python +.. code-block:: default n = 1000 @@ -64,12 +69,12 @@ Generate data + Plot data --------- - -.. code-block:: python +.. code-block:: default pl.figure(1, (5, 5)) @@ -81,8 +86,17 @@ Plot data .. image:: /auto_examples/images/sphx_glr_plot_otda_linear_mapping_001.png - :align: center + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + Out: + + .. code-block:: none + + + [<matplotlib.lines.Line2D object at 0x7f4c73a37320>] @@ -90,8 +104,7 @@ Estimate linear mapping and transport ------------------------------------- - -.. code-block:: python +.. code-block:: default Ae, be = ot.da.OT_mapping_linear(xs, xt) @@ -105,12 +118,12 @@ Estimate linear mapping and transport + Plot transported samples ------------------------ - -.. code-block:: python +.. code-block:: default pl.figure(1, (5, 5)) @@ -125,7 +138,17 @@ Plot transported samples .. image:: /auto_examples/images/sphx_glr_plot_otda_linear_mapping_002.png - :align: center + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_otda_linear_mapping.py:73: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -134,8 +157,7 @@ Load image data --------------- - -.. code-block:: python +.. code-block:: default @@ -167,12 +189,12 @@ Load image data + Estimate mapping and adapt ---------------------------- - -.. code-block:: python +.. code-block:: default mapping = ot.da.LinearTransport() @@ -186,8 +208,6 @@ Estimate mapping and adapt I1t = minmax(mat2im(xst, I1.shape)) I2t = minmax(mat2im(xts, I2.shape)) - # %% - @@ -199,8 +219,7 @@ Plot transformed images ----------------------- - -.. code-block:: python +.. code-block:: default pl.figure(2, figsize=(10, 7)) @@ -227,28 +246,44 @@ Plot transformed images -.. image:: /auto_examples/images/sphx_glr_plot_otda_linear_mapping_004.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_linear_mapping_003.png + :class: sphx-glr-single-img + +.. rst-class:: sphx-glr-script-out + Out: + .. code-block:: none -**Total running time of the script:** ( 0 minutes 0.635 seconds) + Text(0.5, 1.0, 'Inverse mapping Im. 2') + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.787 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_linear_mapping.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_otda_linear_mapping.py <plot_otda_linear_mapping.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_otda_linear_mapping.ipynb <plot_otda_linear_mapping.ipynb>` @@ -257,4 +292,4 @@ Plot transformed images .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_mapping.ipynb b/docs/source/auto_examples/plot_otda_mapping.ipynb index 898466d..ac02255 100644 --- a/docs/source/auto_examples/plot_otda_mapping.ipynb +++ b/docs/source/auto_examples/plot_otda_mapping.ipynb @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_otda_mapping.rst b/docs/source/auto_examples/plot_otda_mapping.rst index 1d95fc6..99787f7 100644 --- a/docs/source/auto_examples/plot_otda_mapping.rst +++ b/docs/source/auto_examples/plot_otda_mapping.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_mapping.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_otda_mapping.py: + .. _sphx_glr_auto_examples_plot_otda_mapping.py: =========================================== @@ -16,8 +22,7 @@ a linear or a kernelized mapping as introduced in [8]. Neural Information Processing Systems (NIPS), 2016. - -.. code-block:: python +.. code-block:: default # Authors: Remi Flamary <remi.flamary@unice.fr> @@ -36,12 +41,12 @@ a linear or a kernelized mapping as introduced in [8]. + Generate data ------------- - -.. code-block:: python +.. code-block:: default n_source_samples = 100 @@ -66,12 +71,12 @@ Generate data + Plot data --------- - -.. code-block:: python +.. code-block:: default pl.figure(1, (10, 5)) @@ -86,17 +91,25 @@ Plot data .. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_001.png - :align: center + :class: sphx-glr-single-img +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + + Text(0.5, 1.0, 'Source and target distributions') + Instantiate the different transport algorithms and fit them ----------------------------------------------------------- - -.. code-block:: python +.. code-block:: default # MappingTransport with linear kernel @@ -132,38 +145,41 @@ Instantiate the different transport algorithms and fit them .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none It. |Loss |Delta loss -------------------------------- - 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 + 0|4.212661e+03|0.000000e+00 + 1|4.198567e+03|-3.345626e-03 + 2|4.198198e+03|-8.797101e-05 + 3|4.198027e+03|-4.059527e-05 + 4|4.197928e+03|-2.355659e-05 + 5|4.197886e+03|-1.002352e-05 + 6|4.197853e+03|-7.873125e-06 It. |Loss |Delta loss -------------------------------- - 0|4.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 + 0|4.231694e+02|0.000000e+00 + 1|4.185911e+02|-1.081889e-02 + 2|4.182717e+02|-7.631953e-04 + 3|4.181271e+02|-3.455908e-04 + 4|4.180328e+02|-2.255461e-04 + 5|4.179645e+02|-1.634435e-04 + 6|4.179136e+02|-1.216359e-04 + 7|4.178752e+02|-9.198108e-05 + 8|4.178465e+02|-6.870868e-05 + 9|4.178243e+02|-5.321390e-05 + 10|4.178054e+02|-4.521725e-05 + + Plot transported samples ------------------------ - -.. code-block:: python +.. code-block:: default pl.figure(2) @@ -202,28 +218,45 @@ Plot transported samples -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_002.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_otda_mapping.py:125: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + -**Total running time of the script:** ( 0 minutes 0.795 seconds) +.. rst-class:: sphx-glr-timing + **Total running time of the script:** ( 0 minutes 0.843 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_mapping.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_otda_mapping.py <plot_otda_mapping.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_otda_mapping.ipynb <plot_otda_mapping.ipynb>` @@ -232,4 +265,4 @@ Plot transported samples .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb b/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb index baffef4..de46629 100644 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb +++ b/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb @@ -26,7 +26,7 @@ }, "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\nfrom scipy import ndimage\nimport matplotlib.pylab as pl\nimport ot\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" + "# 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\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" ] }, { @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "# Loading images\nI1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" + "# Loading images\nI1 = pl.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = pl.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" ] }, { @@ -136,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.7" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.py b/docs/source/auto_examples/plot_otda_mapping_colors_images.py index a20eca8..bc9afba 100644 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.py +++ b/docs/source/auto_examples/plot_otda_mapping_colors_images.py @@ -22,7 +22,6 @@ estimation [8]. # License: MIT License import numpy as np -from scipy import ndimage import matplotlib.pylab as pl import ot @@ -48,8 +47,8 @@ def minmax(I): # ------------- # Loading images -I1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256 -I2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 +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) diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.rst b/docs/source/auto_examples/plot_otda_mapping_colors_images.rst index 2afdc8a..26664e3 100644 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.rst +++ b/docs/source/auto_examples/plot_otda_mapping_colors_images.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_mapping_colors_images.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_otda_mapping_colors_images.py: + .. _sphx_glr_auto_examples_plot_otda_mapping_colors_images.py: ===================================================== @@ -19,8 +25,7 @@ estimation [8]. - -.. code-block:: python +.. code-block:: default # Authors: Remi Flamary <remi.flamary@unice.fr> @@ -29,7 +34,6 @@ estimation [8]. # License: MIT License import numpy as np - from scipy import ndimage import matplotlib.pylab as pl import ot @@ -56,17 +60,17 @@ estimation [8]. + Generate data ------------- - -.. code-block:: python +.. code-block:: default # Loading images - I1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256 - I2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256 + 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) @@ -87,12 +91,12 @@ Generate data + Domain adaptation for pixel distribution transfer ------------------------------------------------- - -.. code-block:: python +.. code-block:: default # EMDTransport @@ -128,7 +132,9 @@ Domain adaptation for pixel distribution transfer .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none It. |Loss |Delta loss -------------------------------- @@ -167,12 +173,13 @@ Domain adaptation for pixel distribution transfer 10|3.639419e+02|-3.209753e-05 + + Plot original images -------------------- - -.. code-block:: python +.. code-block:: default pl.figure(1, figsize=(6.4, 3)) @@ -192,7 +199,8 @@ Plot original images .. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png - :align: center + :class: sphx-glr-single-img + @@ -201,8 +209,7 @@ Plot pixel values distribution ------------------------------ - -.. code-block:: python +.. code-block:: default pl.figure(2, figsize=(6.4, 5)) @@ -226,8 +233,9 @@ Plot pixel values distribution -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_002.png + :class: sphx-glr-single-img + @@ -236,8 +244,7 @@ Plot transformed images ----------------------- - -.. code-block:: python +.. code-block:: default pl.figure(2, figsize=(10, 5)) @@ -277,28 +284,45 @@ Plot transformed images -.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_otda_mapping_colors_images.py:173: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 3 minutes 14.206 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 2 minutes 24.007 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_mapping_colors_images.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_otda_mapping_colors_images.py <plot_otda_mapping_colors_images.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_otda_mapping_colors_images.ipynb <plot_otda_mapping_colors_images.ipynb>` @@ -307,4 +331,4 @@ Plot transformed images .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_otda_semi_supervised.ipynb b/docs/source/auto_examples/plot_otda_semi_supervised.ipynb index e3192da..d2157fb 100644 --- a/docs/source/auto_examples/plot_otda_semi_supervised.ipynb +++ b/docs/source/auto_examples/plot_otda_semi_supervised.ipynb @@ -136,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_otda_semi_supervised.rst b/docs/source/auto_examples/plot_otda_semi_supervised.rst index 2ed7819..4a355e7 100644 --- a/docs/source/auto_examples/plot_otda_semi_supervised.rst +++ b/docs/source/auto_examples/plot_otda_semi_supervised.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_otda_semi_supervised.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_otda_semi_supervised.py: + .. _sphx_glr_auto_examples_plot_otda_semi_supervised.py: ============================================ @@ -16,8 +22,7 @@ transported samples are represented in order to give a visual understanding of what the transport methods are doing. - -.. code-block:: python +.. code-block:: default # Authors: Remi Flamary <remi.flamary@unice.fr> @@ -35,12 +40,12 @@ of what the transport methods are doing. + Generate data ------------- - -.. code-block:: python +.. code-block:: default n_samples_source = 150 @@ -56,12 +61,12 @@ Generate data + Transport source samples onto target samples -------------------------------------------- - -.. code-block:: python +.. code-block:: default @@ -94,12 +99,12 @@ Transport source samples onto target samples + Fig 1 : plots source and target samples + matrix of pairwise distance --------------------------------------------------------------------- - -.. code-block:: python +.. code-block:: default pl.figure(1, figsize=(10, 10)) @@ -139,7 +144,8 @@ Fig 1 : plots source and target samples + matrix of pairwise distance .. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_001.png - :align: center + :class: sphx-glr-single-img + @@ -148,8 +154,7 @@ Fig 2 : plots optimal couplings for the different methods --------------------------------------------------------- - -.. code-block:: python +.. code-block:: default pl.figure(2, figsize=(8, 4)) @@ -172,8 +177,9 @@ Fig 2 : plots optimal couplings for the different methods -.. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_002.png + :class: sphx-glr-single-img + @@ -182,8 +188,7 @@ Fig 3 : plot transported samples -------------------------------- - -.. code-block:: python +.. code-block:: default # display transported samples @@ -212,28 +217,45 @@ Fig 3 : plot transported samples -.. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_006.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_otda_semi_supervised_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + .. code-block:: none + /home/rflamary/PYTHON/POT/examples/plot_otda_semi_supervised.py:148: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 0 minutes 0.256 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.660 seconds) + + +.. _sphx_glr_download_auto_examples_plot_otda_semi_supervised.py: + + .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_otda_semi_supervised.py <plot_otda_semi_supervised.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_otda_semi_supervised.ipynb <plot_otda_semi_supervised.ipynb>` @@ -242,4 +264,4 @@ Fig 3 : plot transported samples .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb b/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb new file mode 100644 index 0000000..539d575 --- /dev/null +++ b/docs/source/auto_examples/plot_partial_wass_and_gromov.ipynb @@ -0,0 +1,126 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Partial Wasserstein and Gromov-Wasserstein example\n\n\nThis example is designed to show how to use the Partial (Gromov-)Wassertsein\ndistance computation in POT.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Author: Laetitia Chapel <laetitia.chapel@irisa.fr>\n# License: MIT License\n\n# necessary for 3d plot even if not used\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nimport scipy as sp\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Sample two 2D Gaussian distributions and plot them\n--------------------------------------------------\n\nFor demonstration purpose, we sample two Gaussian distributions in 2-d\nspaces and add some random noise.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "n_samples = 20 # nb samples (gaussian)\nn_noise = 20 # nb of samples (noise)\n\nmu = np.array([0, 0])\ncov = np.array([[1, 0], [0, 2]])\n\nxs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)\nxs = np.append(xs, (np.random.rand(n_noise, 2) + 1) * 4).reshape((-1, 2))\nxt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)\nxt = np.append(xt, (np.random.rand(n_noise, 2) + 1) * -3).reshape((-1, 2))\n\nM = sp.spatial.distance.cdist(xs, xt)\n\nfig = pl.figure()\nax1 = fig.add_subplot(131)\nax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\nax2 = fig.add_subplot(132)\nax2.scatter(xt[:, 0], xt[:, 1], color='r')\nax3 = fig.add_subplot(133)\nax3.imshow(M)\npl.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compute partial Wasserstein plans and distance\n----------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "p = ot.unif(n_samples + n_noise)\nq = ot.unif(n_samples + n_noise)\n\nw0, log0 = ot.partial.partial_wasserstein(p, q, M, m=0.5, log=True)\nw, log = ot.partial.entropic_partial_wasserstein(p, q, M, reg=0.1, m=0.5,\n log=True)\n\nprint('Partial Wasserstein distance (m = 0.5): ' + str(log0['partial_w_dist']))\nprint('Entropic partial Wasserstein distance (m = 0.5): ' +\n str(log['partial_w_dist']))\n\npl.figure(1, (10, 5))\npl.subplot(1, 2, 1)\npl.imshow(w0, cmap='jet')\npl.title('Partial Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(w, cmap='jet')\npl.title('Entropic partial Wasserstein')\npl.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Sample one 2D and 3D Gaussian distributions and plot them\n---------------------------------------------------------\n\nThe Gromov-Wasserstein distance allows to compute distances with samples that\ndo not belong to the same metric space. For demonstration purpose, we sample\ntwo Gaussian distributions in 2- and 3-dimensional spaces.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "n_samples = 20 # nb samples\nn_noise = 10 # nb of samples (noise)\n\np = ot.unif(n_samples + n_noise)\nq = ot.unif(n_samples + n_noise)\n\nmu_s = np.array([0, 0])\ncov_s = np.array([[1, 0], [0, 1]])\n\nmu_t = np.array([0, 0, 0])\ncov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])\n\n\nxs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s)\nxs = np.concatenate((xs, ((np.random.rand(n_noise, 2) + 1) * 4)), axis=0)\nP = sp.linalg.sqrtm(cov_t)\nxt = np.random.randn(n_samples, 3).dot(P) + mu_t\nxt = np.concatenate((xt, ((np.random.rand(n_noise, 3) + 1) * 10)), axis=0)\n\nfig = pl.figure()\nax1 = fig.add_subplot(121)\nax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\nax2 = fig.add_subplot(122, projection='3d')\nax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')\npl.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compute partial Gromov-Wasserstein plans and distance\n-----------------------------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "C1 = sp.spatial.distance.cdist(xs, xs)\nC2 = sp.spatial.distance.cdist(xt, xt)\n\n# transport 100% of the mass\nprint('-----m = 1')\nm = 1\nres0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)\nres, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,\n m=m, log=True)\n\nprint('Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))\nprint('Entropic Wasserstein distance (m = 1): ' + str(log['partial_gw_dist']))\n\npl.figure(1, (10, 5))\npl.title(\"mass to be transported m = 1\")\npl.subplot(1, 2, 1)\npl.imshow(res0, cmap='jet')\npl.title('Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(res, cmap='jet')\npl.title('Entropic Wasserstein')\npl.show()\n\n# transport 2/3 of the mass\nprint('-----m = 2/3')\nm = 2 / 3\nres0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)\nres, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,\n m=m, log=True)\n\nprint('Partial Wasserstein distance (m = 2/3): ' +\n str(log0['partial_gw_dist']))\nprint('Entropic partial Wasserstein distance (m = 2/3): ' +\n str(log['partial_gw_dist']))\n\npl.figure(1, (10, 5))\npl.title(\"mass to be transported m = 2/3\")\npl.subplot(1, 2, 1)\npl.imshow(res0, cmap='jet')\npl.title('Partial Wasserstein')\npl.subplot(1, 2, 2)\npl.imshow(res, cmap='jet')\npl.title('Entropic partial Wasserstein')\npl.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}
\ No newline at end of file diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.py b/docs/source/auto_examples/plot_partial_wass_and_gromov.py new file mode 100644 index 0000000..9f95a70 --- /dev/null +++ b/docs/source/auto_examples/plot_partial_wass_and_gromov.py @@ -0,0 +1,163 @@ +# -*- coding: utf-8 -*-
+"""
+==================================================
+Partial Wasserstein and Gromov-Wasserstein example
+==================================================
+
+This example is designed to show how to use the Partial (Gromov-)Wassertsein
+distance computation in POT.
+"""
+
+# Author: Laetitia Chapel <laetitia.chapel@irisa.fr>
+# License: MIT License
+
+# necessary for 3d plot even if not used
+from mpl_toolkits.mplot3d import Axes3D # noqa
+import scipy as sp
+import numpy as np
+import matplotlib.pylab as pl
+import ot
+
+
+#############################################################################
+#
+# Sample two 2D Gaussian distributions and plot them
+# --------------------------------------------------
+#
+# For demonstration purpose, we sample two Gaussian distributions in 2-d
+# spaces and add some random noise.
+
+
+n_samples = 20 # nb samples (gaussian)
+n_noise = 20 # nb of samples (noise)
+
+mu = np.array([0, 0])
+cov = np.array([[1, 0], [0, 2]])
+
+xs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)
+xs = np.append(xs, (np.random.rand(n_noise, 2) + 1) * 4).reshape((-1, 2))
+xt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)
+xt = np.append(xt, (np.random.rand(n_noise, 2) + 1) * -3).reshape((-1, 2))
+
+M = sp.spatial.distance.cdist(xs, xt)
+
+fig = pl.figure()
+ax1 = fig.add_subplot(131)
+ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')
+ax2 = fig.add_subplot(132)
+ax2.scatter(xt[:, 0], xt[:, 1], color='r')
+ax3 = fig.add_subplot(133)
+ax3.imshow(M)
+pl.show()
+
+#############################################################################
+#
+# Compute partial Wasserstein plans and distance
+# ----------------------------------------------
+
+p = ot.unif(n_samples + n_noise)
+q = ot.unif(n_samples + n_noise)
+
+w0, log0 = ot.partial.partial_wasserstein(p, q, M, m=0.5, log=True)
+w, log = ot.partial.entropic_partial_wasserstein(p, q, M, reg=0.1, m=0.5,
+ log=True)
+
+print('Partial Wasserstein distance (m = 0.5): ' + str(log0['partial_w_dist']))
+print('Entropic partial Wasserstein distance (m = 0.5): ' +
+ str(log['partial_w_dist']))
+
+pl.figure(1, (10, 5))
+pl.subplot(1, 2, 1)
+pl.imshow(w0, cmap='jet')
+pl.title('Partial Wasserstein')
+pl.subplot(1, 2, 2)
+pl.imshow(w, cmap='jet')
+pl.title('Entropic partial Wasserstein')
+pl.show()
+
+
+#############################################################################
+#
+# Sample one 2D and 3D Gaussian distributions and plot them
+# ---------------------------------------------------------
+#
+# The Gromov-Wasserstein distance allows to compute distances with samples that
+# do not belong to the same metric space. For demonstration purpose, we sample
+# two Gaussian distributions in 2- and 3-dimensional spaces.
+
+n_samples = 20 # nb samples
+n_noise = 10 # nb of samples (noise)
+
+p = ot.unif(n_samples + n_noise)
+q = ot.unif(n_samples + n_noise)
+
+mu_s = np.array([0, 0])
+cov_s = np.array([[1, 0], [0, 1]])
+
+mu_t = np.array([0, 0, 0])
+cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
+
+
+xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s)
+xs = np.concatenate((xs, ((np.random.rand(n_noise, 2) + 1) * 4)), axis=0)
+P = sp.linalg.sqrtm(cov_t)
+xt = np.random.randn(n_samples, 3).dot(P) + mu_t
+xt = np.concatenate((xt, ((np.random.rand(n_noise, 3) + 1) * 10)), axis=0)
+
+fig = pl.figure()
+ax1 = fig.add_subplot(121)
+ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')
+ax2 = fig.add_subplot(122, projection='3d')
+ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')
+pl.show()
+
+
+#############################################################################
+#
+# Compute partial Gromov-Wasserstein plans and distance
+# -----------------------------------------------------
+
+C1 = sp.spatial.distance.cdist(xs, xs)
+C2 = sp.spatial.distance.cdist(xt, xt)
+
+# transport 100% of the mass
+print('-----m = 1')
+m = 1
+res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)
+res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,
+ m=m, log=True)
+
+print('Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist']))
+print('Entropic Wasserstein distance (m = 1): ' + str(log['partial_gw_dist']))
+
+pl.figure(1, (10, 5))
+pl.title("mass to be transported m = 1")
+pl.subplot(1, 2, 1)
+pl.imshow(res0, cmap='jet')
+pl.title('Wasserstein')
+pl.subplot(1, 2, 2)
+pl.imshow(res, cmap='jet')
+pl.title('Entropic Wasserstein')
+pl.show()
+
+# transport 2/3 of the mass
+print('-----m = 2/3')
+m = 2 / 3
+res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True)
+res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10,
+ m=m, log=True)
+
+print('Partial Wasserstein distance (m = 2/3): ' +
+ str(log0['partial_gw_dist']))
+print('Entropic partial Wasserstein distance (m = 2/3): ' +
+ str(log['partial_gw_dist']))
+
+pl.figure(1, (10, 5))
+pl.title("mass to be transported m = 2/3")
+pl.subplot(1, 2, 1)
+pl.imshow(res0, cmap='jet')
+pl.title('Partial Wasserstein')
+pl.subplot(1, 2, 2)
+pl.imshow(res, cmap='jet')
+pl.title('Entropic partial Wasserstein')
+pl.show()
diff --git a/docs/source/auto_examples/plot_partial_wass_and_gromov.rst b/docs/source/auto_examples/plot_partial_wass_and_gromov.rst new file mode 100644 index 0000000..2d51210 --- /dev/null +++ b/docs/source/auto_examples/plot_partial_wass_and_gromov.rst @@ -0,0 +1,312 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_plot_partial_wass_and_gromov.py>` to download the full example code + .. rst-class:: sphx-glr-example-title + + .. _sphx_glr_auto_examples_plot_partial_wass_and_gromov.py: + + +================================================== +Partial Wasserstein and Gromov-Wasserstein example +================================================== + +This example is designed to show how to use the Partial (Gromov-)Wassertsein +distance computation in POT. + + +.. code-block:: default + + + # Author: Laetitia Chapel <laetitia.chapel@irisa.fr> + # License: MIT License + + # necessary for 3d plot even if not used + from mpl_toolkits.mplot3d import Axes3D # noqa + import scipy as sp + import numpy as np + import matplotlib.pylab as pl + import ot + + + + + + + + + +Sample two 2D Gaussian distributions and plot them +-------------------------------------------------- + +For demonstration purpose, we sample two Gaussian distributions in 2-d +spaces and add some random noise. + + +.. code-block:: default + + + + n_samples = 20 # nb samples (gaussian) + n_noise = 20 # nb of samples (noise) + + mu = np.array([0, 0]) + cov = np.array([[1, 0], [0, 2]]) + + xs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov) + xs = np.append(xs, (np.random.rand(n_noise, 2) + 1) * 4).reshape((-1, 2)) + xt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov) + xt = np.append(xt, (np.random.rand(n_noise, 2) + 1) * -3).reshape((-1, 2)) + + M = sp.spatial.distance.cdist(xs, xt) + + fig = pl.figure() + ax1 = fig.add_subplot(131) + ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') + ax2 = fig.add_subplot(132) + ax2.scatter(xt[:, 0], xt[:, 1], color='r') + ax3 = fig.add_subplot(133) + ax3.imshow(M) + pl.show() + + + + +.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:51: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + +Compute partial Wasserstein plans and distance +---------------------------------------------- + + +.. code-block:: default + + + p = ot.unif(n_samples + n_noise) + q = ot.unif(n_samples + n_noise) + + w0, log0 = ot.partial.partial_wasserstein(p, q, M, m=0.5, log=True) + w, log = ot.partial.entropic_partial_wasserstein(p, q, M, reg=0.1, m=0.5, + log=True) + + print('Partial Wasserstein distance (m = 0.5): ' + str(log0['partial_w_dist'])) + print('Entropic partial Wasserstein distance (m = 0.5): ' + + str(log['partial_w_dist'])) + + pl.figure(1, (10, 5)) + pl.subplot(1, 2, 1) + pl.imshow(w0, cmap='jet') + pl.title('Partial Wasserstein') + pl.subplot(1, 2, 2) + pl.imshow(w, cmap='jet') + pl.title('Entropic partial Wasserstein') + pl.show() + + + + + +.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_002.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + Partial Wasserstein distance (m = 0.5): 0.507323938973194 + Entropic partial Wasserstein distance (m = 0.5): 0.5205305886057896 + /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:76: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + +Sample one 2D and 3D Gaussian distributions and plot them +--------------------------------------------------------- + +The Gromov-Wasserstein distance allows to compute distances with samples that +do not belong to the same metric space. For demonstration purpose, we sample +two Gaussian distributions in 2- and 3-dimensional spaces. + + +.. code-block:: default + + + n_samples = 20 # nb samples + n_noise = 10 # nb of samples (noise) + + p = ot.unif(n_samples + n_noise) + q = ot.unif(n_samples + n_noise) + + mu_s = np.array([0, 0]) + cov_s = np.array([[1, 0], [0, 1]]) + + mu_t = np.array([0, 0, 0]) + cov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) + + + xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s) + xs = np.concatenate((xs, ((np.random.rand(n_noise, 2) + 1) * 4)), axis=0) + P = sp.linalg.sqrtm(cov_t) + xt = np.random.randn(n_samples, 3).dot(P) + mu_t + xt = np.concatenate((xt, ((np.random.rand(n_noise, 3) + 1) * 10)), axis=0) + + fig = pl.figure() + ax1 = fig.add_subplot(121) + ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples') + ax2 = fig.add_subplot(122, projection='3d') + ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r') + pl.show() + + + + + +.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:112: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + +Compute partial Gromov-Wasserstein plans and distance +----------------------------------------------------- + + +.. code-block:: default + + + C1 = sp.spatial.distance.cdist(xs, xs) + C2 = sp.spatial.distance.cdist(xt, xt) + + # transport 100% of the mass + print('-----m = 1') + m = 1 + res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True) + res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10, + m=m, log=True) + + print('Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist'])) + print('Entropic Wasserstein distance (m = 1): ' + str(log['partial_gw_dist'])) + + pl.figure(1, (10, 5)) + pl.title("mass to be transported m = 1") + pl.subplot(1, 2, 1) + pl.imshow(res0, cmap='jet') + pl.title('Wasserstein') + pl.subplot(1, 2, 2) + pl.imshow(res, cmap='jet') + pl.title('Entropic Wasserstein') + pl.show() + + # transport 2/3 of the mass + print('-----m = 2/3') + m = 2 / 3 + res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True) + res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10, + m=m, log=True) + + print('Partial Wasserstein distance (m = 2/3): ' + + str(log0['partial_gw_dist'])) + print('Entropic partial Wasserstein distance (m = 2/3): ' + + str(log['partial_gw_dist'])) + + pl.figure(1, (10, 5)) + pl.title("mass to be transported m = 2/3") + pl.subplot(1, 2, 1) + pl.imshow(res0, cmap='jet') + pl.title('Partial Wasserstein') + pl.subplot(1, 2, 2) + pl.imshow(res, cmap='jet') + pl.title('Entropic partial Wasserstein') + pl.show() + + + +.. image:: /auto_examples/images/sphx_glr_plot_partial_wass_and_gromov_004.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + -----m = 1 + Wasserstein distance (m = 1): 63.65368600872179 + Entropic Wasserstein distance (m = 1): 65.23659085946916 + /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:141: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + -----m = 2/3 + Partial Wasserstein distance (m = 2/3): 0.23235485397666825 + Entropic partial Wasserstein distance (m = 2/3): 1.4645434781619244 + /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:157: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance. + pl.subplot(1, 2, 1) + /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:160: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance. + pl.subplot(1, 2, 2) + /home/rflamary/PYTHON/POT/examples/plot_partial_wass_and_gromov.py:163: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.543 seconds) + + +.. _sphx_glr_download_auto_examples_plot_partial_wass_and_gromov.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_partial_wass_and_gromov.py <plot_partial_wass_and_gromov.py>` + + + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_partial_wass_and_gromov.ipynb <plot_partial_wass_and_gromov.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_screenkhorn_1D.ipynb b/docs/source/auto_examples/plot_screenkhorn_1D.ipynb new file mode 100644 index 0000000..1c27d3b --- /dev/null +++ b/docs/source/auto_examples/plot_screenkhorn_1D.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 Screened optimal transport\n\n\nThis example illustrates the computation of Screenkhorn:\nScreening Sinkhorn Algorithm for Optimal transport.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Author: Mokhtar Z. Alaya <mokhtarzahdi.alaya@gmail.com>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot.plot\nfrom ot.datasets import make_1D_gauss as gauss\nfrom ot.bregman import screenkhorn" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Generate data\n-------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "n = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plot distributions and loss matrix\n----------------------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()\n\n# plot distributions and loss matrix\n\npl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Solve Screenkhorn\n-----------------------\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Screenkhorn\nlambd = 2e-03 # entropy parameter\nns_budget = 30 # budget number of points to be keeped in the source distribution\nnt_budget = 30 # budget number of points to be keeped in the target distribution\n\nG_screen = screenkhorn(a, b, M, lambd, ns_budget, nt_budget, uniform=False, restricted=True, verbose=True)\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G_screen, 'OT matrix Screenkhorn')\npl.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}
\ No newline at end of file diff --git a/docs/source/auto_examples/plot_screenkhorn_1D.py b/docs/source/auto_examples/plot_screenkhorn_1D.py new file mode 100644 index 0000000..840ead8 --- /dev/null +++ b/docs/source/auto_examples/plot_screenkhorn_1D.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" +=============================== +1D Screened optimal transport +=============================== + +This example illustrates the computation of Screenkhorn: +Screening Sinkhorn Algorithm for Optimal transport. +""" + +# Author: Mokhtar Z. Alaya <mokhtarzahdi.alaya@gmail.com> +# +# License: MIT License + +import numpy as np +import matplotlib.pylab as pl +import ot.plot +from ot.datasets import make_1D_gauss as gauss +from ot.bregman import screenkhorn + +############################################################################## +# Generate data +# ------------- + +#%% parameters + +n = 100 # nb bins + +# bin positions +x = np.arange(n, dtype=np.float64) + +# Gaussian distributions +a = gauss(n, m=20, s=5) # m= mean, s= std +b = gauss(n, m=60, s=10) + +# loss matrix +M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) +M /= M.max() + +############################################################################## +# Plot distributions and loss matrix +# ---------------------------------- + +#%% plot the distributions + +pl.figure(1, figsize=(6.4, 3)) +pl.plot(x, a, 'b', label='Source distribution') +pl.plot(x, b, 'r', label='Target distribution') +pl.legend() + +# plot distributions and loss matrix + +pl.figure(2, figsize=(5, 5)) +ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') + +############################################################################## +# Solve Screenkhorn +# ----------------------- + +# Screenkhorn +lambd = 2e-03 # entropy parameter +ns_budget = 30 # budget number of points to be keeped in the source distribution +nt_budget = 30 # budget number of points to be keeped in the target distribution + +G_screen = screenkhorn(a, b, M, lambd, ns_budget, nt_budget, uniform=False, restricted=True, verbose=True) +pl.figure(4, figsize=(5, 5)) +ot.plot.plot1D_mat(a, b, G_screen, 'OT matrix Screenkhorn') +pl.show() diff --git a/docs/source/auto_examples/plot_screenkhorn_1D.rst b/docs/source/auto_examples/plot_screenkhorn_1D.rst new file mode 100644 index 0000000..039479e --- /dev/null +++ b/docs/source/auto_examples/plot_screenkhorn_1D.rst @@ -0,0 +1,178 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_plot_screenkhorn_1D.py>` to download the full example code + .. rst-class:: sphx-glr-example-title + + .. _sphx_glr_auto_examples_plot_screenkhorn_1D.py: + + +=============================== +1D Screened optimal transport +=============================== + +This example illustrates the computation of Screenkhorn: +Screening Sinkhorn Algorithm for Optimal transport. + + +.. code-block:: default + + + # Author: Mokhtar Z. Alaya <mokhtarzahdi.alaya@gmail.com> + # + # License: MIT License + + import numpy as np + import matplotlib.pylab as pl + import ot.plot + from ot.datasets import make_1D_gauss as gauss + from ot.bregman import screenkhorn + + + + + + + + +Generate data +------------- + + +.. code-block:: default + + + n = 100 # nb bins + + # bin positions + x = np.arange(n, dtype=np.float64) + + # Gaussian distributions + a = gauss(n, m=20, s=5) # m= mean, s= std + b = gauss(n, m=60, s=10) + + # loss matrix + M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) + M /= M.max() + + + + + + + + +Plot distributions and loss matrix +---------------------------------- + + +.. code-block:: default + + + pl.figure(1, figsize=(6.4, 3)) + pl.plot(x, a, 'b', label='Source distribution') + pl.plot(x, b, 'r', label='Target distribution') + pl.legend() + + # plot distributions and loss matrix + + pl.figure(2, figsize=(5, 5)) + ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') + + + + +.. rst-class:: sphx-glr-horizontal + + + * + + .. image:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_001.png + :class: sphx-glr-multi-img + + * + + .. image:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_002.png + :class: sphx-glr-multi-img + + + + + +Solve Screenkhorn +----------------------- + + +.. code-block:: default + + + # Screenkhorn + lambd = 2e-03 # entropy parameter + ns_budget = 30 # budget number of points to be keeped in the source distribution + nt_budget = 30 # budget number of points to be keeped in the target distribution + + G_screen = screenkhorn(a, b, M, lambd, ns_budget, nt_budget, uniform=False, restricted=True, verbose=True) + pl.figure(4, figsize=(5, 5)) + ot.plot.plot1D_mat(a, b, G_screen, 'OT matrix Screenkhorn') + pl.show() + + + +.. image:: /auto_examples/images/sphx_glr_plot_screenkhorn_1D_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/ot/bregman.py:2056: UserWarning: Bottleneck module is not installed. Install it from https://pypi.org/project/Bottleneck/ for better performance. + "Bottleneck module is not installed. Install it from https://pypi.org/project/Bottleneck/ for better performance.") + epsilon = 0.020986042861303855 + + kappa = 3.7476531411890917 + + Cardinality of selected points: |Isel| = 30 |Jsel| = 30 + + /home/rflamary/PYTHON/POT/examples/plot_screenkhorn_1D.py:68: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.228 seconds) + + +.. _sphx_glr_download_auto_examples_plot_screenkhorn_1D.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_screenkhorn_1D.py <plot_screenkhorn_1D.py>` + + + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_screenkhorn_1D.ipynb <plot_screenkhorn_1D.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/auto_examples/plot_stochastic.ipynb b/docs/source/auto_examples/plot_stochastic.ipynb index 7f6ff3d..c29f75a 100644 --- a/docs/source/auto_examples/plot_stochastic.ipynb +++ b/docs/source/auto_examples/plot_stochastic.ipynb @@ -287,7 +287,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.7" + "version": "3.6.9" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_stochastic.rst b/docs/source/auto_examples/plot_stochastic.rst index d531045..63fc74f 100644 --- a/docs/source/auto_examples/plot_stochastic.rst +++ b/docs/source/auto_examples/plot_stochastic.rst @@ -1,6 +1,12 @@ +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + Click :ref:`here <sphx_glr_download_auto_examples_plot_stochastic.py>` to download the full example code + .. rst-class:: sphx-glr-example-title -.. _sphx_glr_auto_examples_plot_stochastic.py: + .. _sphx_glr_auto_examples_plot_stochastic.py: ========================== @@ -12,8 +18,7 @@ algorithms for descrete and semicontinous measures from the POT library. - -.. code-block:: python +.. code-block:: default # Author: Kilian Fatras <kilian.fatras@gmail.com> @@ -32,6 +37,7 @@ algorithms for descrete and semicontinous measures from the POT library. + COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM ############################################################################ ############################################################################ @@ -44,8 +50,7 @@ COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM and the target measures and finally the cost matrix c. - -.. code-block:: python +.. code-block:: default n_source = 7 @@ -67,6 +72,7 @@ COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM + Call the "SAG" method to find the transportation matrix in the discrete case --------------------------------------------- @@ -74,8 +80,7 @@ Define the method "SAG", call ot.solve_semi_dual_entropic and plot the results. - -.. code-block:: python +.. code-block:: default method = "SAG" @@ -89,7 +94,9 @@ results. .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none [[2.55553509e-02 9.96395660e-02 1.76579142e-02 4.31178196e-06] [1.21640234e-01 1.25357448e-02 1.30225078e-03 7.37891338e-03] @@ -100,6 +107,8 @@ results. [4.15462212e-02 2.65987989e-02 7.23177216e-02 2.39440107e-03]] + + SEMICONTINOUS CASE: Sample one general measure a, one discrete measures b for the semicontinous @@ -110,8 +119,7 @@ Define one general measure a, one discrete measures b, the points where are defined the source and the target measures and finally the cost matrix c. - -.. code-block:: python +.. code-block:: default n_source = 7 @@ -134,6 +142,7 @@ are defined the source and the target measures and finally the cost matrix c. + Call the "ASGD" method to find the transportation matrix in the semicontinous case --------------------------------------------- @@ -142,8 +151,7 @@ Define the method "ASGD", call ot.solve_semi_dual_entropic and plot the results. - -.. code-block:: python +.. code-block:: default method = "ASGD" @@ -158,17 +166,21 @@ results. .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none + + [3.89943264 7.64823414 3.9284189 2.67501041 1.42825446 3.26039819 + 2.79237712] [-2.50786905 -2.42684838 -0.93647774 5.87119517] + [[2.50229922e-02 1.00367920e-01 1.74615056e-02 4.72486104e-06] + [1.20583329e-01 1.27839737e-02 1.30373565e-03 8.18610462e-03] + [3.49243139e-03 7.68200813e-02 6.25444833e-02 1.46879008e-07] + [2.58205995e-02 3.39501207e-02 8.26360982e-02 4.50324517e-04] + [8.94164918e-03 7.02183713e-04 9.92028326e-03 1.23293027e-01] + [1.97360234e-02 8.46022708e-04 1.72001583e-03 1.20555081e-01] + [4.10386980e-02 2.70289873e-02 7.21425804e-02 2.64687723e-03]] + - [3.98220325 7.76235856 3.97645524 2.72051681 1.23219313 3.07696856 - 2.84476972] [-2.65544161 -2.50838395 -0.9397765 6.10360206] - [[2.34528761e-02 1.00491956e-01 1.89058354e-02 6.47543413e-06] - [1.16616747e-01 1.32074516e-02 1.45653361e-03 1.15764107e-02] - [3.16154850e-03 7.42892944e-02 6.54061055e-02 1.94426150e-07] - [2.33152216e-02 3.27486992e-02 8.61986263e-02 5.94595747e-04] - [6.34131496e-03 5.31975896e-04 8.12724003e-03 1.27856612e-01] - [1.41744829e-02 6.49096245e-04 1.42704389e-03 1.26606520e-01] - [3.73127657e-02 2.62526499e-02 7.57727161e-02 3.51901117e-03]] Compare the results with the Sinkhorn algorithm @@ -177,8 +189,7 @@ Compare the results with the Sinkhorn algorithm Call the Sinkhorn algorithm from POT - -.. code-block:: python +.. code-block:: default sinkhorn_pi = ot.sinkhorn(a, b, M, reg) @@ -191,27 +202,29 @@ Call the Sinkhorn algorithm from POT .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none + + [[2.55553508e-02 9.96395661e-02 1.76579142e-02 4.31178193e-06] + [1.21640234e-01 1.25357448e-02 1.30225079e-03 7.37891333e-03] + [3.56123974e-03 7.61451746e-02 6.31505947e-02 1.33831455e-07] + [2.61515201e-02 3.34246014e-02 8.28734709e-02 4.07550425e-04] + [9.85500876e-03 7.52288523e-04 1.08262629e-02 1.21423583e-01] + [2.16904255e-02 9.03825804e-04 1.87178504e-03 1.18391107e-01] + [4.15462212e-02 2.65987989e-02 7.23177217e-02 2.39440105e-03]] + - [[2.55535622e-02 9.96413843e-02 1.76578860e-02 4.31043335e-06] - [1.21640742e-01 1.25369034e-02 1.30234529e-03 7.37715259e-03] - [3.56096458e-03 7.61460101e-02 6.31500344e-02 1.33788624e-07] - [2.61499607e-02 3.34255577e-02 8.28741973e-02 4.07427179e-04] - [9.85698720e-03 7.52505948e-04 1.08291770e-02 1.21418473e-01] - [2.16947591e-02 9.04086158e-04 1.87228707e-03 1.18386011e-01] - [4.15442692e-02 2.65998963e-02 7.23192701e-02 2.39370724e-03]] PLOT TRANSPORTATION MATRIX ############################################################################# - Plot SAG results ---------------- - -.. code-block:: python +.. code-block:: default pl.figure(4, figsize=(5, 5)) @@ -222,8 +235,18 @@ Plot SAG results -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_004.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_stochastic_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:119: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -232,8 +255,7 @@ Plot ASGD results ----------------- - -.. code-block:: python +.. code-block:: default pl.figure(4, figsize=(5, 5)) @@ -244,8 +266,18 @@ Plot ASGD results -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_005.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_stochastic_002.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:128: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -254,8 +286,7 @@ Plot Sinkhorn results --------------------- - -.. code-block:: python +.. code-block:: default pl.figure(4, figsize=(5, 5)) @@ -266,8 +297,18 @@ Plot Sinkhorn results -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_006.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_stochastic_003.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:137: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -285,8 +326,7 @@ COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM are defined the source and the target measures and finally the cost matrix c. - -.. code-block:: python +.. code-block:: default n_source = 7 @@ -311,6 +351,7 @@ COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM + Call the "SGD" dual method to find the transportation matrix in the semicontinous case --------------------------------------------- @@ -318,8 +359,7 @@ semicontinous case Call ot.solve_dual_entropic and plot the results. - -.. code-block:: python +.. code-block:: default sgd_dual_pi, log_sgd = ot.stochastic.solve_dual_entropic(a, b, M, reg, @@ -334,17 +374,21 @@ Call ot.solve_dual_entropic and plot the results. .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none + + [0.91421006 2.78075506 1.06828701 0.01979397 0.60914807 1.81887037 + 0.1152939 ] [0.33964624 0.47604281 1.57223631 4.93843308] + [[2.18038772e-02 9.24355133e-02 1.08426805e-02 9.39355366e-08] + [1.59966167e-02 1.79248770e-03 1.23251128e-04 2.47779034e-05] + [3.44864558e-03 8.01760930e-02 4.40119061e-02 3.30922887e-09] + [3.12954103e-02 4.34915712e-02 7.13747533e-02 1.24533534e-05] + [6.79742497e-02 5.64192090e-03 5.37416946e-02 2.13851205e-02] + [8.05141568e-02 3.64790957e-03 5.00040902e-03 1.12213345e-02] + [4.86643900e-02 3.38763749e-02 6.09634969e-02 7.16139950e-05]] + - [0.92449986 2.75486107 1.07923806 0.02741145 0.61355413 1.81961594 - 0.12072562] [0.33831611 0.46806842 1.5640451 4.96947652] - [[2.20001105e-02 9.26497883e-02 1.08654588e-02 9.78995555e-08] - [1.55669974e-02 1.73279561e-03 1.19120878e-04 2.49058251e-05] - [3.48198483e-03 8.04151063e-02 4.41335396e-02 3.45115752e-09] - [3.14927954e-02 4.34760520e-02 7.13338154e-02 1.29442395e-05] - [6.81836550e-02 5.62182457e-03 5.35386584e-02 2.21568095e-02] - [8.04671052e-02 3.62163462e-03 4.96331605e-03 1.15837801e-02] - [4.88644009e-02 3.37903481e-02 6.07955004e-02 7.42743505e-05]] Compare the results with the Sinkhorn algorithm @@ -353,8 +397,7 @@ Compare the results with the Sinkhorn algorithm Call the Sinkhorn algorithm from POT - -.. code-block:: python +.. code-block:: default sinkhorn_pi = ot.sinkhorn(a, b, M, reg) @@ -366,23 +409,26 @@ Call the Sinkhorn algorithm from POT .. rst-class:: sphx-glr-script-out - Out:: + Out: + + .. code-block:: none + + [[2.55553508e-02 9.96395661e-02 1.76579142e-02 4.31178193e-06] + [1.21640234e-01 1.25357448e-02 1.30225079e-03 7.37891333e-03] + [3.56123974e-03 7.61451746e-02 6.31505947e-02 1.33831455e-07] + [2.61515201e-02 3.34246014e-02 8.28734709e-02 4.07550425e-04] + [9.85500876e-03 7.52288523e-04 1.08262629e-02 1.21423583e-01] + [2.16904255e-02 9.03825804e-04 1.87178504e-03 1.18391107e-01] + [4.15462212e-02 2.65987989e-02 7.23177217e-02 2.39440105e-03]] + - [[2.55535622e-02 9.96413843e-02 1.76578860e-02 4.31043335e-06] - [1.21640742e-01 1.25369034e-02 1.30234529e-03 7.37715259e-03] - [3.56096458e-03 7.61460101e-02 6.31500344e-02 1.33788624e-07] - [2.61499607e-02 3.34255577e-02 8.28741973e-02 4.07427179e-04] - [9.85698720e-03 7.52505948e-04 1.08291770e-02 1.21418473e-01] - [2.16947591e-02 9.04086158e-04 1.87228707e-03 1.18386011e-01] - [4.15442692e-02 2.65998963e-02 7.23192701e-02 2.39370724e-03]] Plot SGD results ----------------- - -.. code-block:: python +.. code-block:: default pl.figure(4, figsize=(5, 5)) @@ -393,8 +439,18 @@ Plot SGD results -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_007.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_stochastic_004.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:199: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() @@ -403,8 +459,7 @@ Plot Sinkhorn results --------------------- - -.. code-block:: python +.. code-block:: default pl.figure(4, figsize=(5, 5)) @@ -413,28 +468,45 @@ Plot Sinkhorn results -.. image:: /auto_examples/images/sphx_glr_plot_stochastic_008.png - :align: center +.. image:: /auto_examples/images/sphx_glr_plot_stochastic_005.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/rflamary/PYTHON/POT/examples/plot_stochastic.py:208: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + pl.show() -**Total running time of the script:** ( 0 minutes 20.889 seconds) +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 8.885 seconds) + + +.. _sphx_glr_download_auto_examples_plot_stochastic.py: .. only :: html .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_stochastic.py <plot_stochastic.py>` - .. container:: sphx-glr-download + .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_stochastic.ipynb <plot_stochastic.ipynb>` @@ -443,4 +515,4 @@ Plot Sinkhorn results .. rst-class:: sphx-glr-signature - `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_ + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ |