Efficient Maximum Mean Discrepancy two-sample testing for data with duplicate observations, scaling with unique values rather than sample size.
Project description
Unique Maximum Mean Discrepancy (uMMD)
An efficient implementation of the Maximum Mean Discrepancy two-sample test for datasets with duplicate observations via count-weighting of unique values. This implementation scales with unique data values rather than sample size.
Installation
pip install ummd
Quick start
import numpy as np
from ummd import MMD
rng = np.random.default_rng(0)
x = rng.integers(0, 10, size=500) # sample from one distribution
y = rng.integers(2, 12, size=500) # sample from a shifted distribution
result = MMD(x, y, unique=True, bandwidths=10, n_permutations=999)
print(result["biased_MMD"]) # MMD statistic per bandwidth
# [ 0.04408069 0.053788 0.06124013 0.06328209 0.06290089 0.0602459 0.04713144 0.02831863 0.01431563 0.0066321 ]
print(result["p-value"]) # combined p-value across bandwidths
# 0.001
Interpreting the result
MMD returns a dictionary with:
biased_MMD: the MMD statistic for each tested bandwidthp-values_per_bandwidth: permutation p-value for each bandwidthp-value: a single Cauchy-combined p-value across the bandwidthsbandwidths: the kernel bandwidths actually used
Why uMMD
A standard MMD test builds an N x N kernel matrix, so cost grows with sample size. When your data has many repeated values (counts, categories, discretised measurements), uMMD instead works over the u unique values, where u << n, giving the same test at a fraction of the cost.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ummd-0.1.0.tar.gz.
File metadata
- Download URL: ummd-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d9d2d1cdda34f45c19e3d9641bc5656f409304f576e3c4bb9162f0c879f3620
|
|
| MD5 |
b6194ed5e776233c1fc77899fcce15d2
|
|
| BLAKE2b-256 |
2ba570082bd2cf61bcc156a1cc141f994c9b3a390589dbd1d21510550162847c
|
File details
Details for the file ummd-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ummd-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35869a93a4ddc205ebfc5fe086544c075df1641220b881e83b385b69358d372f
|
|
| MD5 |
b852b1b6891140a69ab1dacb5d2b46c1
|
|
| BLAKE2b-256 |
f08421b5943011d88b74cd6327f4e4514a0391120754c74966796c4fbd1e78b9
|