brainmass.objectives.wasserstein_1d#
- brainmass.objectives.wasserstein_1d(p, q, x)[source]#
Wasserstein-1 distance between two 1-D densities on a shared grid.
\[W_1(p, q) = \int \left| F_p(x) - F_q(x) \right| \, dx,\]discretised on the uniform grid
x. Both inputs are normalised internally (CDFs run 0..1), sopandqmay be densities or unnormalised histograms; the returned value lives in the same units asx. Unlikeks_distance()this is smooth and differentiable in both inputs, making it the preferred distributional loss for gradient-based fitting. Matchesscipy.stats.wasserstein_distance()as the grid is refined.- Parameters:
p (array) – Densities or histograms on the shared grid
x.q (array) – Densities or histograms on the shared grid
x.x (array) – Uniform evaluation grid (same length as
p/q).
- Returns:
Scalar Wasserstein-1 distance.
- Return type:
jax.Array
See also
ks_distancethe non-smooth KS counterpart.