bundles / scipy 1.17.1 / scipy / stats / _stats_py / energy_distance
function
scipy.stats._stats_py:energy_distance
source: /scipy/stats/_stats_py.py :9687
Signature
def energy_distance ( u_values , v_values , u_weights = None , v_weights = None ) Summary
Compute the energy distance between two 1D distributions.
Extended Summary
Parameters
u_values, v_values: array_likeValues observed in the (empirical) distribution.
u_weights, v_weights: array_like, optionalWeight for each value. If unspecified, each value is assigned the same weight.
u_weights(resp.v_weights) must have the same length asu_values(resp.v_values). If the weight sum differs from 1, it must still be positive and finite so that the weights can be normalized to sum to 1.
Returns
distance: floatThe computed distance between the distributions.
Notes
The energy distance between two distributions and , whose respective CDFs are and , equals to:
where and (resp. and ) are independent random variables whose probability distribution is (resp. ).
Sometimes the square of this quantity is referred to as the "energy distance" (e.g. in [2], [4]), but as noted in [1] and [3], only the definition above satisfies the axioms of a distance function (metric).
As shown in [2], for one-dimensional real-valued variables, the energy distance is linked to the non-distribution-free version of the Cramér-von Mises distance:
Note that the common Cramér-von Mises criterion uses the distribution-free version of the distance. See [2] (section 2), for more details about both versions of the distance.
The input distributions can be empirical, therefore coming from samples whose values are effectively inputs of the function, or they can be seen as generalized functions, in which case they are weighted sums of Dirac delta functions located at the specified values.
Array API Standard Support
energy_distance has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy.stats import energy_distance
✓energy_distance([0], [2]) energy_distance([0, 8], [0, 8], [3, 1], [2, 2]) energy_distance([0.7, 7.4, 2.4, 6.8], [1.4, 8. ], [2.1, 4.2, 7.4, 8. ], [7.6, 8.8])✗
Aliases
-
scipy.stats.energy_distance