-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,44 @@ | ||
import numpy as np | ||
import scipy.stats | ||
|
||
from test_kuiper import seed, double_check, check_uniform, check_fpp | ||
import htest | ||
import zm2 | ||
|
||
def test_null(): | ||
for N in 100, 1000, 10000: | ||
yield check_null, N | ||
def F(x): | ||
return htest.h_test(x)[2] | ||
|
||
def check_null(N): | ||
H, M, fpp = htest.h_test(np.random.random(N)) | ||
assert fpp>0.01 | ||
def test_uniform(): | ||
for N in 20, 100, 1000: | ||
yield check_uniform, F, N | ||
|
||
@seed() | ||
@double_check | ||
def test_non_null(): | ||
H, M, fpp = htest.h_test(np.random.random(1000)/2) | ||
assert fpp<0.01 | ||
|
||
|
||
def test_fpp(): | ||
for N in 100, 200: | ||
yield check_fpp, N, 1000, 0.05 | ||
|
||
def check_fpp(N,M,thresh): | ||
fp = 0 | ||
for i in range(M): | ||
H, m, fpp = htest.h_test(np.random.random(N)) | ||
if fpp<thresh: | ||
fp += 1 | ||
print thresh, float(fp)/M | ||
assert scipy.stats.binom(M,thresh).sf(fp-1)>0.005 | ||
assert scipy.stats.binom(M,thresh).cdf(fp-1)>0.005 | ||
for N in 10, 50, 100: | ||
yield check_fpp, F, N, 1000, 0.05 | ||
|
||
@seed() | ||
@double_check | ||
def test_mean_stddev(): | ||
Hs = [] | ||
for i in range(1000): | ||
H, M, fpp = htest.h_test(np.random.random(1000)) | ||
H, M, fpp = htest.h_test(np.random.random(100)) | ||
Hs.append(H) | ||
print np.mean(Hs), np.std(Hs) | ||
assert np.abs(np.mean(Hs)-2.51)<0.1 | ||
assert np.abs(np.std(Hs)-2.51)<0.3 | ||
|
||
@seed() | ||
def test_compare_zm2(): | ||
data = np.random.random(1000) | ||
H, M, fpp = htest.h_test(data) | ||
Z, zm2fpp = zm2.Zm2(data, M) | ||
Z, zm2fpp = zm2.zm2(data, M) | ||
assert np.abs(Z - (H+4*M-4))<1e-8 | ||
assert fpp>zm2fpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
import numpy as np | ||
import scipy.stats | ||
|
||
from test_kuiper import seed, double_check, check_uniform, check_fpp | ||
import zm2 | ||
|
||
def test_null(): | ||
for N in 100, 1000, 10000: | ||
yield check_null, N | ||
|
||
def check_null(N): | ||
Z, fpp = zm2.Zm2(np.random.random(N),5) | ||
assert fpp>0.01 | ||
for m in [1,2,5]: | ||
yield check_uniform, lambda x: zm2.zm2(x,m)[1], N | ||
|
||
@seed() | ||
@double_check | ||
def test_non_null(): | ||
Z, fpp = zm2.Zm2(np.random.random(1000)/2,5) | ||
Z, fpp = zm2.zm2(np.random.random(1000)/2,5) | ||
assert fpp<0.01 | ||
|
||
def test_fpp(): | ||
for N in 100, 200: | ||
yield check_fpp, N, 1000, 0.05 | ||
|
||
def check_fpp(N,M,thresh): | ||
fp = 0 | ||
for i in range(M): | ||
Z, fpp = zm2.Zm2(np.random.random(N),5) | ||
if fpp<thresh: | ||
fp += 1 | ||
print thresh, float(fp)/M | ||
assert scipy.stats.binom(M,thresh).sf(fp-1)>0.005 | ||
assert scipy.stats.binom(M,thresh).cdf(fp-1)>0.005 | ||
for N in 10, 100, 500: | ||
for m in [1,2,5]: | ||
yield check_fpp, lambda x: zm2.zm2(x,m)[1], N, 1000, 0.05 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters