Skip to content

[MRG] Stereographic Spherical Sliced Wasserstein - #836

Open
huytransformer wants to merge 4 commits into
PythonOT:masterfrom
huytransformer:s3w
Open

[MRG] Stereographic Spherical Sliced Wasserstein#836
huytransformer wants to merge 4 commits into
PythonOT:masterfrom
huytransformer:s3w

Conversation

@huytransformer

Copy link
Copy Markdown

Types of changes

This PR aims to add the Stereographic Spherical Sliced Wasserstein distance and its rotationally invariant extension introduced in Stereographic Spherical Sliced Wasserstein Distances.

Changes:

  • Added the ot.sliced.stereographic_sliced_wasserstein_sphere function to compute the S3W distance, and the RI-S3W distance with the n_rotations argument. The amortized version ARI-S3W can be computed by pregenerating a pool of rotations with ot.sliced.get_random_rotations and passing a random subset with the rotations argument.
  • Added the ot.sliced.get_random_rotations function to sample rotations uniformly on SO(d), used for RI-S3W.
  • Added tests for these functions in test/sliced/test_spherical_sliced.py.

Motivation and context / Related issue

The S3W distances are fast alternatives to ot.sliced_wasserstein_sphere for comparing distributions on the sphere: after a stereographic projection composed with a near-isometric map, they only require computing sliced Wasserstein distances in R^{d-1}, and they support all backends including tensorflow.

How has this been tested (if it applies)

I added tests of these functions in test/sliced/test_spherical_sliced.py.

PR checklist

  • I have read the CONTRIBUTING document.
  • The documentation is up-to-date with the changes I made (check build artifacts).
  • All tests passed, and additional code has been covered with new tests.
  • I have added the PR and Issue fix to the RELEASES.md file.

@rflamary
rflamary requested a review from clbonet August 6, 2026 09:40
@clbonet

clbonet commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Thank you @huytransformer for this PR! This is a very good work, and we were waiting for more sliced distances on the sphere!

I did a review. The code seems good to me and I only have minor comments.

Comment thread ot/sliced/_spherical_sliced.py Outdated
return res


def _projection_sphere_stereographic(x, eps, nx):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be moved to _utils.py?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the description of parameters and returned values

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it uses the composition of h with the stereographic projection, the name might be a bit misleading?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, done, and done (I renamed it to projection_sphere_to_ball)

Comment thread ot/sliced/_spherical_sliced.py Outdated
def _projection_sphere_stereographic(x, eps, nx):
r"""Maps points on :math:`S^{d-1}` to :math:`\mathbb{R}^{d-1}` with :math:`h\circ\phi_\epsilon`,
where :math:`\phi_\epsilon` is the stereographic projection with an :math:`\epsilon`-cap
around the north pole and :math:`h` the defining function of :ref:`[93] <references-s3w>`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it h_1 in [93]?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya

Comment thread ot/sliced/_spherical_sliced.py Outdated
sphere, :math:`\theta_\# \mu` stands for the pushforwards of the projection
:math:`X \in \mathbb{R}^{d-1} \mapsto \langle \theta, X \rangle`,
:math:`\phi_\epsilon` is the stereographic projection
:math:`\phi(x) = \frac{x_{1:d-1}}{1-x_d}` restricted to the sphere without the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lack a 2?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed!

Comment thread ot/sliced/_utils.py Outdated

def get_random_rotations(d, n_rotations, seed=None, backend=None, type_as=None):
r"""
Generates n_rotations samples from the uniform (Haar) distribution on the special orthogonal group :math:`\mathrm{SO}(d)=\{R \in \mathbb{R}^{d\times d}, R^TR=I_d, \mathrm{det}(R)=1\}`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack .

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants