Skip to content

Commit

Permalink
update posterior sampling method (#1279)
Browse files Browse the repository at this point in the history
* update posterior sampling method

* local test fix
  • Loading branch information
JuliaLinhart authored Sep 23, 2024
1 parent 363e74d commit 4a7ed2b
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 50 deletions.
26 changes: 13 additions & 13 deletions tests/lc2st_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ def test_running_lc2st(method, classifier, cv_folds, num_ensemble, z_score):

@pytest.mark.slow
@pytest.mark.parametrize("method", (LC2ST, LC2ST_NF))
def test_lc2st_true_negativ_rate(method):
"""Tests the true negative rate of the LC2ST-(NF) test:
def test_lc2st_true_positiv_rate(method):
"""Tests the true positiv rate of the LC2ST-(NF) test:
for a "bad" estimator, the LC2ST-(NF) should reject the null hypothesis."""
num_runs = 100
confidence_level = 0.95

# use little training data and num_epochs to obtain "bad" estimator.
# use small num_train and num_epochs to obtain "bad" estimator
# (no convergence to the true posterior)
num_train = 100
num_epochs = 2
Expand Down Expand Up @@ -189,15 +189,15 @@ def test_lc2st_true_negativ_rate(method):

@pytest.mark.slow
@pytest.mark.parametrize("method", (LC2ST, LC2ST_NF))
def test_lc2st_true_positiv_rate(method):
"""Tests the true negative rate of the LC2ST-(NF) test:
for a "good" estimator, the LC2ST-(NF) should accept the null hypothesis."""
def test_lc2st_false_positiv_rate(method):
"""Tests the false positiv rate of the LC2ST-(NF) test:
for a "good" estimator, the LC2ST-(NF) should not reject the null hypothesis."""
num_runs = 100
confidence_level = 0.95

# good estimator: big training and num_epochs = accept
# use big num_train and num_epochs to obtain "good" estimator
# (convergence of the estimator)
num_train = 5_000
num_train = 1_000
num_epochs = 200

num_cal = 1_000
Expand Down Expand Up @@ -259,8 +259,8 @@ def test_lc2st_true_positiv_rate(method):

proportion_rejected = torch.tensor(results).float().mean()

assert (
proportion_rejected < 1 - confidence_level
), f"LC2ST p-values too small, test should be accepted \
at least {confidence_level * 100}% of the time, but was accepted \
only {(1 - proportion_rejected) * 100}% of the time."
assert proportion_rejected < (
1 - confidence_level
), f"LC2ST p-values too small, test should be rejected \
less then {(1 - confidence_level) * 100}% of the time, \
but was rejected {proportion_rejected * 100}% of the time."
Loading

0 comments on commit 4a7ed2b

Please sign in to comment.