Baltor Get started

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.

Files, names only

  • ATTRIBUTION.md 3.9 KB
  • LICENSE 1.0 KB
  • README.md 2.6 KB
  • atom_cli.py 3.0 KB
  • component.json 8.7 KB
  • numerics.py 28.0 KB
  • rbf_maximum_mean_discrepancy.py 5.0 KB
  • schema_lite.py 8.9 KB
  • test_package.py 12.0 KB
  • test_rbf_maximum_mean_discrepancy.py 3.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

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.