|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | """ |
3 | | -========================== |
| 3 | +================================================== |
4 | 4 | Partial Wasserstein and Gromov-Wasserstein example |
5 | | -========================== |
| 5 | +================================================== |
6 | 6 |
|
7 | 7 | This example is designed to show how to use the Partial (Gromov-)Wassertsein |
8 | 8 | distance computation in POT. |
|
50 | 50 |
|
51 | 51 | ############################################################################# |
52 | 52 | # |
53 | | -# Compute partial Wasserstein plans and distance, |
54 | | -# by transporting 50% of the mass |
| 53 | +# Compute partial Wasserstein plans and distance |
55 | 54 | # ---------------------------------------------- |
56 | 55 |
|
57 | 56 | p = ot.unif(n_samples + n_noise) |
|
113 | 112 |
|
114 | 113 | ############################################################################# |
115 | 114 | # |
116 | | -# Compute partial Gromov-Wasserstein plans and distance, |
117 | | -# by transporting 100% and 2/3 of the mass |
| 115 | +# Compute partial Gromov-Wasserstein plans and distance |
118 | 116 | # ----------------------------------------------------- |
119 | 117 |
|
120 | 118 | C1 = sp.spatial.distance.cdist(xs, xs) |
121 | 119 | C2 = sp.spatial.distance.cdist(xt, xt) |
122 | 120 |
|
| 121 | +# transport 100% of the mass |
123 | 122 | print('-----m = 1') |
124 | 123 | m = 1 |
125 | | -res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, |
126 | | - log=True) |
| 124 | +res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True) |
127 | 125 | res, log = ot.partial.entropic_partial_gromov_wasserstein(C1, C2, p, q, 10, |
128 | 126 | m=m, log=True) |
129 | 127 |
|
130 | | -print('Partial Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist'])) |
131 | | -print('Entropic partial Wasserstein distance (m = 1): ' + |
132 | | - str(log['partial_gw_dist'])) |
| 128 | +print('Wasserstein distance (m = 1): ' + str(log0['partial_gw_dist'])) |
| 129 | +print('Entropic Wasserstein distance (m = 1): ' + str(log['partial_gw_dist'])) |
133 | 130 |
|
134 | 131 | pl.figure(1, (10, 5)) |
135 | 132 | pl.title("mass to be transported m = 1") |
136 | 133 | pl.subplot(1, 2, 1) |
137 | 134 | pl.imshow(res0, cmap='jet') |
138 | | -pl.title('Partial Wasserstein') |
| 135 | +pl.title('Wasserstein') |
139 | 136 | pl.subplot(1, 2, 2) |
140 | 137 | pl.imshow(res, cmap='jet') |
141 | | -pl.title('Entropic partial Wasserstein') |
| 138 | +pl.title('Entropic Wasserstein') |
142 | 139 | pl.show() |
143 | 140 |
|
| 141 | +# transport 2/3 of the mass |
144 | 142 | print('-----m = 2/3') |
145 | 143 | m = 2 / 3 |
146 | 144 | res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C2, p, q, m=m, log=True) |
|
0 commit comments