Skip to content

Commit

Permalink
update readme with howto
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorStoneAstro committed May 29, 2024
1 parent 27fd747 commit 2ae481b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# PQM
Implemenation of PQMass from Lemos et al. 2024

Implementation of the PQMass two sample test from Lemos et al. 2024

## Usage

```python
from pqm import pqm_pvalue
import numpy as np

x_sample = np.random.normal(size = (500, 10))
y_sample = np.random.normal(size = (400, 10))

pvalues = pqm_pvalue(x_sample, y_sample, num_refs = 100, bootstrap = 50)

print(np.mean(pvalues), np.std(pvalues))
```
8 changes: 3 additions & 5 deletions src/pqm/pqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from scipy.stats import chi2_contingency
from scipy.spatial import KDTree

__all__ = "get_pqm_pvalue"
__all__ = "pqm_pvalue"


def get_pqm_pvalue(
def pqm_pvalue(
x_samples: np.ndarray,
y_samples: np.ndarray,
num_refs: int = 100,
Expand All @@ -33,9 +33,7 @@ def get_pqm_pvalue(
pvalue. Null hypothesis that both samples are drawn from the same distribution.
"""
if bootstrap is not None:
return list(
get_pqm_pvalue(x_samples, y_samples, num_refs=num_refs) for _ in range(bootstrap)
)
return list(pqm_pvalue(x_samples, y_samples, num_refs=num_refs) for _ in range(bootstrap))
if len(y_samples) < num_refs:
raise ValueError(
"Number of reference samples must be less than the number of true samples."
Expand Down
4 changes: 2 additions & 2 deletions src/pqm/test_gaussian.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from .pqm import get_pqm_pvalue
from .pqm import pqm_pvalue


def test():
Expand All @@ -8,6 +8,6 @@ def test():
y_samples = np.random.normal(size=(500, 50))
x_samples = np.random.normal(size=(250, 50))

new.append(get_pqm_pvalue(x_samples, y_samples))
new.append(pqm_pvalue(x_samples, y_samples))

assert np.abs(np.mean(new) - 0.5) < 0.15
4 changes: 2 additions & 2 deletions tests/test_gaussian.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from pqm import get_pqm_pvalue
from pqm import pqm_pvalue


def test():
Expand All @@ -8,6 +8,6 @@ def test():
y_samples = np.random.normal(size=(500, 50))
x_samples = np.random.normal(size=(250, 50))

new.append(get_pqm_pvalue(x_samples, y_samples))
new.append(pqm_pvalue(x_samples, y_samples))

assert np.abs(np.mean(new) - 0.5) < 0.15

0 comments on commit 2ae481b

Please sign in to comment.