Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA018 · Hypothesis test
Energy two-sample test
Compares within- and between-sample distances; extends baseline entry 168 to embeddings and model outputs.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page.
- Multivariate tests of equal distributions (energy, MMD, DISCO, classifier) Verified in Python and R
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Runs in CodeSplash
- Code example
- Complete calculation
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through multivariate.distribution_test. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Compares within- and between-sample distances; extends baseline entry 168 to embeddings and model outputs.
Question / hypotheses
H0: two distributions are equal under the applicable distance-space conditions.
Architecture / computational structure
Form between-group and within-group distance averages. The snippet uses the V-statistic including zero diagonal distances; the conventional two-sample energy statistic may additionally multiply by mn/(m+n). For fixed sample sizes, this positive scaling leaves permutation ordering unchanged.
Assumptions
The Euclidean population formulation assumes finite first moments. Permutation validity requires independent exchangeable units; other distances need suitable negative-type properties.
Formula / computational definition
Parameters and notation
The metric and embedding determine detectable differences. V-statistic and U-statistic estimates have different finite-sample properties; declare the selected scaling.
Fitting, fine-tuning, and adaptation
Choose the distance/embedding and whether to use a V- or U-statistic before analysis. Calibrate by reassigning complete exchangeable observations between groups; clustered or longitudinal data require a null transformation appropriate to their sampling design. Refit learned preprocessing inside resampling when required, rather than treating a data-adapted distance as fixed.
How to use and calibrate
Choose a distance suited to the observations, compute the empirical discrepancy, and calibrate by pooled-label permutations. Resample complete subjects or recordings rather than correlated frames.
Example application
Compare real and generated low-dimensional scientific measurements.
Interpretation / pitfalls
Watch out
A test on image pixels may emphasize nuisance shifts. A test on embeddings is conditional on what that encoder preserves. Statistical rejection does not measure practical harm.
Python and R code examples
Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.
Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs numpy, scipy
import numpy as np
from scipy.spatial.distance import cdist
x=np.array([[0.],[1.],[2.]]); y=np.array([[2.],[3.],[4.]])
print(2*cdist(x,y).mean()-cdist(x,x).mean()-cdist(y,y).mean())
Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.
x <- c(0,1,2); y <- c(2,3,4)
print(2*mean(abs(outer(x,y,"-")))-mean(abs(outer(x,x,"-")))-mean(abs(outer(y,y,"-"))))
Sources
- Source 1cran.r-project.org
From the CodeSplash reference, entry EVA018.