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