AI Glossary / Mathematics and optimization / Advanced
Energy distance
Definition
Energy distance is a measure of difference between probability distributions built from expected distances between independent observations. It compares cross-distribution separation with the separation already present within each distribution. This entry follows SciPy's square-root convention for real-valued distributions. Some statistical publications call the quantity before taking the square root the energy distance, so the convention must be checked when comparing formulas or software outputs.
What it means
The measure can detect distributional differences beyond a change in the mean. Two distributions with the same average can differ in spread or shape and therefore have positive energy distance. The word energy is mathematical terminology here; the number is not an estimate of electricity consumption. The relevant distance between observations and the conditions ensuring finite expectations are part of the definition. In the real-valued setting used below, observations are compared by absolute difference and the distributions have finite first moments.
How it works
Let X and X′ be independent draws from P, and Y and Y′ independent draws from Q, with the draws independent across distributions as well. Under the convention here, D(P, Q)² = 2E|X − Y| − E|X − X′| − E|Y − Y′|. Take the nonnegative square root to obtain D. For empirical distributions, replace expectations with weighted averages over all appropriate pairs. The within-sample averages include ordered pairs and zero self-distances under this empirical-distribution calculation. An unbiased estimator used in a particular statistical test may have a different normalization, so it should not be silently substituted.
Three practical examples
- A monitoring workflow can compare distributions of response times from two observation periods without reducing each period to its mean alone.
- A simulation-validation study can compare a simulated scalar output distribution with an observed one, while separately assessing model assumptions and sampling variability.
- A statistical analysis can use an appropriately calibrated energy-based two-sample procedure to investigate whether distributional differences exceed what sampling variation could explain.
Think of it this way
Think of comparing two groups of points while allowing for how spread out each group already is. Large cross-group distances are more informative when they cannot be explained simply by broad variation within both groups. This analogy conveys the subtraction in the formula, but the result is not obtained by choosing a few representative pairs or subtracting two ordinary standard deviations. The full expectation or specified sample statistic matters.
Worked example
Let P place probability 0.5 at 0 and 0.5 at 2, while Q places all its probability at 1. Both means are 1. For the cross term, |X − Y| is always 1, so E|X − Y| = 1. Two independent draws from P agree with probability 0.5 and differ by 2 with probability 0.5. Therefore E|X − X′| = 1. Draws from Q always agree, so E|Y − Y′| = 0. The squared energy distance is 2 × 1 − 1 − 0 = 1, and the square-root distance is also 1. To see a case where the convention changes the numerical result, compare a point mass at 0 with a point mass at 4. The within-distribution terms are both zero and the cross term is 4. The squared quantity is 8, while SciPy's distance is √8, approximately 2.828. If every coordinate is multiplied by a positive factor c, all absolute-distance expectations multiply by c, so D multiplies by √c. This differs from Wasserstein-1, which scales by c under the same coordinate change. The calculations are exact for the stated finite distributions.
Illustrative case study
In a fictional service study, Willow Desk compares two latency datasets that have nearly identical means. Analysts inspect their distributions and calculate an empirical energy distance to capture differences in shape. They report the formula convention, sample sizes and observation windows. Before claiming a population change, they use an appropriate statistical procedure that respects the sampling design. The case illustrates descriptive comparison followed by inference; a positive sample distance alone does not prove a change in service quality or establish its cause.
Common misconceptions and mistakes
Energy distance is not the difference between average outcomes, nor is it identical to earth mover's distance. A positive distance between empirical distributions does not automatically imply a statistically significant population difference. The square-root and squared conventions must not be mixed, particularly when setting thresholds or comparing units. Input weights must define valid nonnegative probability masses after normalization. Finally, the standard expected-distance formula needs suitable moment conditions; it is not automatically finite for every heavy-tailed distribution a model might specify.
Business use
Choose the distributional feature of interest, the observation scale and the formula convention before comparing results. Preserve information about sampling, dependence and missing observations. If the goal is hypothesis testing, use a test and calibration appropriate for that design rather than applying an arbitrary distance cutoff. For weighted observations, explain what the weights represent. When moving beyond one dimension, use a method that explicitly supports multivariate distributions and state the ground distance. Report descriptive plots alongside the number so readers can see whether the difference concerns location, spread or another feature.
People also ask
Can energy distance be zero for different distributions?
In the standard Euclidean setting with the required finite-moment conditions, zero characterizes equality of the distributions.
Is SciPy's energy_distance a multivariate function?
The documented function used here compares one-dimensional distributions; do not pass feature matrices and assume it performs a multivariate test.
Does a larger sample automatically make the empirical distance larger?
No. Sample size affects sampling behavior, but the distance is not simply a count of observations.
Check your understanding
Why is the distance positive for P at 0 and 2 versus Q at 1 even though both means are 1?
Answer: The distributions have different shapes. The cross and within-distribution terms give squared distance 1, which a mean-only comparison would miss.
Related terms
- Probability distribution
- Empirical distribution
- two-sample testing
- Cramér–von Mises distance
- Wasserstein distance
- statistical distance
Learn next
enumerate the four ordered pairs from P to verify its within-distribution expectation. Then multiply every location in the worked examples by 9 and confirm that the square-root energy distance triples. Compare that scaling with Wasserstein-1 and explain why units and conventions matter.
More in Mathematics and optimization
- Absolute error loss - Absolute error loss measures a numerical prediction's error as the absolute difference between its predicted and reference values: L(y,y-hat)=|y-y-hat|.
- Active-set method - An active-set method is an optimization approach that works with a changing subset of constraints believed to be tight at the solution.
- Adjoint state method - The adjoint state method computes how a chosen objective changes when the parameters of a mathematical model change.
- Σ-algebra
- Algebraic connectivity - Algebraic connectivity is the second-smallest eigenvalue of a graph's Laplacian matrix.
- Algorithm IMED - Algorithm IMED, short for Indexed Minimum Empirical Divergence, is a method for choosing actions in a stochastic multi-armed bandit problem.
Sources
Sources: SciPy, energy_distance documentation, https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.energy_distance.html ; SciPy, wasserstein_distance documentation for the contrasting transport measure, https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.wasserstein_distance.html . The discrete calculations, scaling comparison and fictional latency study are original educational examples.
Previous: Energy-based model Next: Energy in frame