|
12 | 12 |
|
13 | 13 | import numpy as np |
14 | 14 | from .backend import get_backend, NumpyBackend |
15 | | -from .utils import list_to_array |
| 15 | +from .utils import list_to_array, get_coordinate_circle |
16 | 16 | from .lp import wasserstein_circle, semidiscrete_wasserstein2_unif_circle |
17 | 17 |
|
18 | 18 |
|
@@ -348,8 +348,8 @@ def sliced_wasserstein_sphere(X_s, X_t, a=None, b=None, n_projections=50, |
348 | 348 | Xpt = Xpt / nx.sqrt(nx.sum(Xpt**2, -1, keepdims=True)) |
349 | 349 |
|
350 | 350 | # Get coordinates on [0,1[ |
351 | | - Xps_coords = (nx.atan2(-Xps[:, :, 1], -Xps[:, :, 0]) + np.pi) / (2 * np.pi) |
352 | | - Xpt_coords = (nx.atan2(-Xpt[:, :, 1], -Xpt[:, :, 0]) + np.pi) / (2 * np.pi) |
| 351 | + Xps_coords = nx.reshape(get_coordinate_circle(nx.reshape(Xps, (-1, 2))), (n_projections, n)) |
| 352 | + Xpt_coords = nx.reshape(get_coordinate_circle(nx.reshape(Xpt, (-1, 2))), (n_projections, m)) |
353 | 353 |
|
354 | 354 | projected_emd = wasserstein_circle(Xps_coords.T, Xpt_coords.T, u_weights=a, v_weights=b, p=p) |
355 | 355 | res = nx.mean(projected_emd) ** (1 / p) |
@@ -429,7 +429,7 @@ def sliced_wasserstein_sphere_unif(X_s, a=None, n_projections=50, seed=None, log |
429 | 429 | # Projection on sphere |
430 | 430 | Xps = Xps / nx.sqrt(nx.sum(Xps**2, -1, keepdims=True)) |
431 | 431 | # Get coordinates on [0,1[ |
432 | | - Xps_coords = (nx.atan2(-Xps[:, :, 1], -Xps[:, :, 0]) + np.pi) / (2 * np.pi) |
| 432 | + Xps_coords = nx.reshape(get_coordinate_circle(nx.reshape(Xps, (-1, 2))), (n_projections, n)) |
433 | 433 |
|
434 | 434 | projected_emd = semidiscrete_wasserstein2_unif_circle(Xps_coords.T, u_weights=a) |
435 | 435 | res = nx.mean(projected_emd) ** (1 / 2) |
|
0 commit comments