[MRG]Add UnifOrtho sampling of slicing directions for Sliced Wasserstein - #853
Samuel-Vangu wants to merge 5 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #853 +/- ##
========================================
Coverage 96.86% 96.86%
========================================
Files 128 128
Lines 26181 26289 +108
========================================
+ Hits 25359 25465 +106
- Misses 822 824 +2 🚀 New features to boost your workflow:
|
clbonet
left a comment
There was a problem hiding this comment.
Thank you @Samuel-Vangu for this PR. The code looks very good, I only have few minor comments.
| ax1.set_title("Uniform (Monte Carlo)") | ||
|
|
||
| ax2 = fig.add_subplot(1, 2, 2, projection="3d") | ||
| block_ids = np.repeat(np.arange(n_blocks), d) | ||
| ax2.scatter( | ||
| theta_uniortho[0], | ||
| theta_uniortho[1], | ||
| theta_uniortho[2], | ||
| c=block_ids, | ||
| cmap="tab10", | ||
| s=25, | ||
| alpha=0.9, | ||
| ) | ||
| ax2.set_title("UnifOrtho (one color per orthogonal block)") | ||
|
|
||
| for ax in (ax1, ax2): | ||
| ax.set_box_aspect([1, 1, 1]) | ||
| ax.view_init(elev=20, azim=45) | ||
| ax.set_xticks([]) | ||
| ax.set_yticks([]) | ||
| ax.set_zticks([]) | ||
|
|
||
| pl.tight_layout() | ||
| pl.show() |
There was a problem hiding this comment.
Add a sphere for better visualization?
| than independent draws would. | ||
|
|
||
| We first visualize this block structure on the ordinary 3D sphere, purely | ||
| for intuition -- dimension 3 is precisely where QSW/RQSW should be |
There was a problem hiding this comment.
You could maybe add this baseline in the 3D example to show that QMC is better than UnifOrtho in this case.
| return radius * x_azimuth / nx.sqrt(norm2) | ||
|
|
||
|
|
||
| def get_projections_uniortho(d, n_projections, seed=None, backend=None, type_as=None): |
| # directions (see get_random_rotations for the QR-based construction | ||
| # and its Mezzadri (2007) sign correction, which is what makes the | ||
| # rotation genuinely Haar-uniform rather than merely orthogonal). | ||
| rotations = get_random_rotations(d, k, seed=seed, backend=nx, type_as=type_as) |
| .. [95] Nguyen, K., Bariletto, N., & Ho, N. (2024). "Quasi-Monte Carlo for 3D Sliced Wasserstein." International Conference on Learning Representations (ICLR). | ||
| .. [96] Rakhmanov, E. A., Saff, E. B., & Zhou, Y. M. (1994). "Minimal Discrete Energy on the Sphere." Mathematical Research Letters, 1(6), 647-662. | ||
| .. [97] Rowland, M., Hron, J., Tang, Y., Choromanski, K., Sarlos, T., & Weller, A. (2019). "Orthogonal Estimation of Wasserstein Distances." Proceedings of the 22nd International Conference on Artificial Intelligence and Statistics (AISTATS), PMLR 89. | ||
| .. [98] Petrovic, V., Bardenet, R., & Desolneux, A. (2025). "Repulsive Monte Carlo on the sphere for the sliced Wasserstein distance." arXiv:2509.10166. |
There was a problem hiding this comment.
This is a TMLR paper, add the right citation
There was a problem hiding this comment.
I guess you can also cite https://openreview.net/forum?id=ECBepTWAFG which also studies methods to draw directions and tested the UnifOrth
Types of changes
Motivation and context / Related issue
The Sliced Wasserstein distance only supports a low-discrepancy sampling
alternative to plain Monte Carlo (QSW/RQSW, PR #838) for
dim == 3. Thisleaves no principled alternative in higher dimension, where variance
reduction matters most.
Adds UnifOrtho sampling: independent blocks of mutually orthogonal
directions, drawn from the Haar measure on
O(dim), defined for anydimand recommended specifically for large dimension by a recentnumerical and theoretical study. Reuses the existing
get_random_rotationsdirectly, requiring no new randomization primitive.
Closes #850 .
How has this been tested (if it applies)
within a block, correctness for arbitrary dimensions (including
non-multiples of
dim), seed reproducibility, cross-backend consistency(NumPy, PyTorch, JAX, TensorFlow), and reduced approximation error
compared to uniform sampling in high dimension against a closed-form
reference distance.
plot_uniortho.py) demonstrating both theorthogonal block structure and the convergence gain in high dimension.
PR checklist