Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Distances between distributions with complex samples #20493

Open
jmoraispk opened this issue Apr 16, 2024 · 0 comments
Open

ENH: Distances between distributions with complex samples #20493

jmoraispk opened this issue Apr 16, 2024 · 0 comments
Labels
enhancement A new feature or improvement scipy.stats

Comments

@jmoraispk
Copy link

Is your feature request related to a problem? Please describe.

When I try to compute

scipy.stats.wasserstein_distance(u,v) or scipy.stats.wasserstein_distance_nd(u,v) between distributions with complex samples, I get this warning:

/home/joao/mambaforge/envs/my-env/lib/python3.9/site-packages/scipy/stats/_stats_py.py:10628:
ComplexWarning: Casting complex values to real discards the imaginary part

Which means the distance is not happening between complex numbers, but between real numbers.

Describe the solution you'd like.

I'm not sure if this is the correct way of doing it, but I would like the distances to work normally for complex vectors. I tried the following changes, and they seem to be working.

Changing line 10628 in _stats_py.py from

values = np.asarray(values, dtype=float)
to:

if type(values) == np.ndarray and values.dtype in [np.complex64, np.complex128]:
    pass
else:
    values = np.asarray(values, dtype=float)

Describe alternatives you've considered.

I considered unfolding the complex into a 2*N vector with real and imaginary parts separated. But this will compute distances differently. Instead of shortest distances in the complex plane, it would sum the real distance with the imaginary.

(like summing the 2 sides of the rectangular triangle instead of the diagonal)the

Additional context (e.g. screenshots, GIFs)

No response

@jmoraispk jmoraispk added the enhancement A new feature or improvement label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.stats
Projects
None yet
Development

No branches or pull requests

3 participants
@jmoraispk @j-bowhay and others