muspan.distribution.

sliced_wasserstein_distance#

sliced_wasserstein_distance(domain, population_A, population_B, include_boundaries=None, exclude_boundaries=None, boundary_exclude_distance=0, label_name=None, POT_args={})#

Compute the Sliced Wasserstein Distance between two populations within a given domain. Instead of computing the Wasserstein distance directly in high-dimensional space, the sliced wasserstein projects the distributions onto lower-dimensional subspaces (typically 1D) and computes the Wasserstein distance in these subspaces. The final distance is an average over multiple projections.

Parameters:
domainobject

The domain within which the populations are defined.

population_Aarray-like, list, tuple, or muspan query

The first population for which the Sliced Wasserstein Distance is to be computed.

population_Barray-like, list, tuple, or muspan query

The second population for which the Sliced Wasserstein Distance is to be computed.

include_boundariesarray-like, list, tuple, or muspan query, optional

Boundaries within which the populations are considered. If provided, only objects within this boundary are used.

exclude_boundariesarray-like, list, tuple, or muspan query, optional

Boundaries within which the populations are considered. If provided, only objects within this boundary are used.

boundary_exclude_distancefloat, optional

Buffer to exclude objects located within boundary_exclude_distance from the boundaries. Defaults to 0.

label_namestr, optional

The name of the label to weight the spatial distribution of objects. Must be a continuous label. Defaults to None.

POT_argsdict, optional

Additional arguments to pass to the POT (Python Optimal Transport) library’s sliced_wasserstein_distance function.

Returns:
float

The Sliced Wasserstein Distance between the two populations. If either population is empty, returns NaN.

Raises:
ValueError

If one or both of the populations contains no objects within the boundaries specified.

Notes

For information on the Wasserstein distance and computational approaces, see https://en.wikipedia.org/wiki/Wasserstein_metric and https://pythonot.github.io/index.html. The function first interprets the populations and boundary (if provided) to obtain object indices. It then computes the centroids of the objects in the populations and uses the POT library to calculate the Sliced Wasserstein Distance.