Implementation of a Permutation Test using the Energy Distance for two sample tests and posterior coverage tests
Project description
PTED: Permutation Test using the Energy Distance
Think of it like a multi-dimensional KS-test! It is used for two sample testing and posterior coverage tests. In some cases it is even more sensitive than the KS-test, but likely not all cases.
Install
To install PTED, run the following:
pip install pted
Usage
PTED (pronounced "ted") takes in x and y two datasets and determines if they
come from the same underlying distribution. For information about each argument,
just use help(pted.pted) or help(pted.pted_coverage_test).
The returned value is a p-value, an estimate of the probability of a more
extreme instance occurring. Under the null hypothesis, a p-value is drawn from a
random uniform distribution (range 0 to 1). If the null hypothesis is false, one
would expect to see very low p-values and so one can set a limit such as
p=0.01 below which we reject the null hypothesis. In this case 1/100th of
the time even when the null hypothesis is true, we will reject the null.
Example: Two-Sample-Test
from pted import pted
import numpy as np
x = np.random.normal(size = (500, 10)) # (n_samples_x, n_dimensions)
y = np.random.normal(size = (400, 10)) # (n_samples_y, n_dimensions)
p_value = pted(x, y)
print(f"p-value: {p_value:.3f}") # expect uniform random from 0-1
Example: Coverage Test
from pted import pted_coverage_test
import numpy as np
g = np.random.normal(size = (100, 10)) # ground truth (n_simulations, n_dimensions)
s = np.random.normal(size = (200, 100, 10)) # posterior samples (n_samples, n_simulations, n_dimensions)
p_value = pted_coverage_test(g, s)
print(f"p-value: {p_value:.3f}") # expect uniform random from 0-1
GPU Compatibility
PTED works on both CPU and GPU. All that is needed is to pass the x and y as
PyTorch Tensors on the appropriate device.
Reference
I didn't invent this test, I just think its neat. Here is a paper on the subject:
@article{szekely2004testing,
title={Testing for equal distributions in high dimension},
author={Sz{\'e}kely, G{\'a}bor J and Rizzo, Maria L and others},
journal={InterStat},
volume={5},
number={16.10},
pages={1249--1272},
year={2004},
publisher={Citeseer}
}
Permutation tests are a whole class of tests, with much literature. Here are some starting points:
@book{good2013permutation,
title={Permutation tests: a practical guide to resampling methods for testing hypotheses},
author={Good, Phillip},
year={2013},
publisher={Springer Science \& Business Media}
}
@book{rizzo2019statistical,
title={Statistical computing with R},
author={Rizzo, Maria L},
year={2019},
publisher={Chapman and Hall/CRC}
}
There is also the wikipedia page, and the more general scipy implementation, and other python implementations
Project details
Release history Release notifications | RSS feed
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 pted-1.0.0.tar.gz.
File metadata
- Download URL: pted-1.0.0.tar.gz
- Upload date:
- Size: 261.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9566d407541c9011c2181bd94068846ce4ccfd8db811ceb719d9d7316b479d8a
|
|
| MD5 |
430b0b0a096ef6ad166b51143f6abf40
|
|
| BLAKE2b-256 |
efc90504c9c9d797cf32ea82de17eb5d5b62f51d4cb986b2dd83df034da40ae8
|
Provenance
The following attestation bundles were made for pted-1.0.0.tar.gz:
Publisher:
cd.yml on ConnorStoneAstro/pted
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pted-1.0.0.tar.gz -
Subject digest:
9566d407541c9011c2181bd94068846ce4ccfd8db811ceb719d9d7316b479d8a - Sigstore transparency entry: 203234026
- Sigstore integration time:
-
Permalink:
ConnorStoneAstro/pted@6335cbbe1ad8ea56b5ce9d9ee333d264d96cb27c -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ConnorStoneAstro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@6335cbbe1ad8ea56b5ce9d9ee333d264d96cb27c -
Trigger Event:
release
-
Statement type:
File details
Details for the file pted-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pted-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0d3d55d8e41f5071ecfd5c3a8942e9d69a8c971137da1e5396a48d6cf5c50a6
|
|
| MD5 |
48143a5634614d9f3ae8d69ecf3c5d1f
|
|
| BLAKE2b-256 |
61dd43763443a7d073a45a93bb56458be4ab54a76a317b159e53891126b5b8e9
|
Provenance
The following attestation bundles were made for pted-1.0.0-py3-none-any.whl:
Publisher:
cd.yml on ConnorStoneAstro/pted
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pted-1.0.0-py3-none-any.whl -
Subject digest:
d0d3d55d8e41f5071ecfd5c3a8942e9d69a8c971137da1e5396a48d6cf5c50a6 - Sigstore transparency entry: 203234028
- Sigstore integration time:
-
Permalink:
ConnorStoneAstro/pted@6335cbbe1ad8ea56b5ce9d9ee333d264d96cb27c -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ConnorStoneAstro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@6335cbbe1ad8ea56b5ce9d9ee333d264d96cb27c -
Trigger Event:
release
-
Statement type: