Skip to main content

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 bandwidth
  • p-values_per_bandwidth: permutation p-value for each bandwidth
  • p-value: a single Cauchy-combined p-value across the bandwidths
  • bandwidths: 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

ummd-0.1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ummd-0.1.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file ummd-0.1.1.tar.gz.

File metadata

  • Download URL: ummd-0.1.1.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

Hashes for ummd-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f2fe23f8f032c3dd3719727eef352e5e34d1586288c3630a30e1a99d31d7d324
MD5 c28eefbce5c0e7009b659a0d6be4a619
BLAKE2b-256 4747f18495283d35c0859519d0a54dd0dc863b756234bc377f32272fd7652a5a

See more details on using hashes here.

File details

Details for the file ummd-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ummd-0.1.1-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

Hashes for ummd-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7344ee3da9296810242987fb7799b330befdc4cd466cda1c4cc219b6b20a6c91
MD5 3e3a4d8ea504447136f73f552e3aa6cc
BLAKE2b-256 bf5071b6d6ba8655cb47d530ea8e8ee4701a09da63305c1f4260c5434dbd48f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page