Library / Code module
Maximum mean discrepancy with an RBF kernel
rbf_maximum_mean_discrepancy
Compare two samples of vectors with the kernel maximum mean discrepancy: biased and unbiased estimators of MMD squared under a Gaussian kernel, the median-distance bandwidth, and a seeded permutation test. Use it to check whether two sets of outputs, embeddings or inputs come from one distribution.
ATTRIBUTION.md3.9 KBLICENSE1.0 KBREADME.md2.6 KBatom_cli.py3.0 KBcomponent.json8.7 KBnumerics.py28.0 KBrbf_maximum_mean_discrepancy.py5.0 KBschema_lite.py8.9 KBtest_package.py12.0 KBtest_rbf_maximum_mean_discrepancy.py3.1 KB
Full files in your harness.
What it takes and gives
- Runs with
- Python 3.10 or later
- Entry points
- mmd_squared, permutation_test, median_bandwidth
- Known answers
- 7 cases its tests reproduce
Cases it covers
- unbiased not clamped: Clamping the unbiased estimate at zero (or taking its square root) biases it upward and breaks its expectation.
Limits and scope
- Limits
- Quadratic cost in the pooled sample size: a few thousand rows at most, and permutation tests multiply that by the number of permutations. One Gaussian kernel with one bandwidth; the median heuristic is a convention, not an optimal choice, and the test's power depends on it. Rejecting the null says the samples differ, not how or whether the difference matters.
- Guarantees
- The biased estimate is non-negative and 0 for identical samples; the unbiased estimate is reported as computed, including negative values. p = (1 + #{permuted statistic >= observed}) / (1 + B) is a valid p-value under exchangeability of the pooled sample. Permutations use a seeded Fisher-Yates shuffle driven by random() only.
- Assumes
- Rows within each sample are exchangeable; under the null both samples come from one distribution. The bandwidth is fixed before the permutations (the median heuristic uses the pooled sample, which permutations do not change).
Details
- Kind
- Code module
- Licence
- MIT
- Declared effects
- runs commands
- Source
- github.com/alisonjieli-png/loop-engine/tools/creative_originals/evaluation_atoms/items/rbf_maximum_mean_discrepancy
- Size
- 10 files, 76.3 KB
- Identity
library.supply.creative_originals.008598e6b349a5ea60d9bb72.979b66d3ba7053bd- Version
979b66d3ba7053bd8c180a54d2418fd50006fc9a9d92d7f09504e7742d0464b9
The version is the SHA-256 of the item your harness downloads; every file in it names its own checksum.
Where it is shown
- Statistics for comparing resultsDeterministic skills
Related components
Something wrong with this item, its rights or its safety? Report it on the support page, or from your harness after a download.