test_realistic_skat.py

Streaming Polyphase Factor Decomposition / SKAT

test_realistic_skat.py

Download original file

This is the original source text. Reading it does not run or verify the program.

Read the typeset paper

Skip source text

1 import unittest
2 import numpy as np
3 
4 from benchmark_realistic_skat import (
5     simulate_copy_ld_fixed,
6     simulate_gaussian_ld,
7     covariates,
8     process_full,
9     stream_kernel_raw,
10     spectrum_from_kernel,
11 )
12 
13 
14 class RealisticSKATTests(unittest.TestCase):
15     def test_copy_ld_is_reproducible_and_valid_genotype(self):
16         G1, maf1 = simulate_copy_ld_fixed(
17             n=120, m=300, block=30, copy_prob=0.9, seed=11
18         )
19         G2, maf2 = simulate_copy_ld_fixed(
20             n=120, m=300, block=30, copy_prob=0.9, seed=11
21         )
22         self.assertTrue(np.array_equal(G1, G2))
23         self.assertTrue(np.array_equal(maf1, maf2))
24         self.assertTrue(np.all(np.isin(G1, [0.0, 1.0, 2.0])))
25 
26     def test_streamed_raw_kernel_matches_materialized_factor(self):
27         G, maf = simulate_gaussian_ld(
28             n=140, m=500, block=25, rho=0.8, seed=12
29         )
30         _, Qx = covariates(140, seed=13)
31         _, Kfull, _, _ = process_full(G, maf, Qx)
32 
33         for bs in [17, 61, 149]:
34             Ks, _ = stream_kernel_raw(G, maf, Qx, bs)
35             rel = np.linalg.norm(Ks-Kfull) / np.linalg.norm(Kfull)
36             self.assertLess(rel, 2e-12)
37 
38     def test_spectrum_is_psd_after_kernel_construction(self):
39         G, maf = simulate_copy_ld_fixed(
40             n=100, m=250, block=25, copy_prob=0.85, seed=14
41         )
42         _, Qx = covariates(100, seed=15)
43         _, K, _, _ = process_full(G, maf, Qx)
44         lam, _, _ = spectrum_from_kernel(K)
45         self.assertTrue(np.all(lam >= 0))
46 
47 
48 if __name__ == "__main__":
49     unittest.main(verbosity=2)

Back to source controls

Other PDFs for this work

Original file and source record

This copy matches the recorded source file. Its publication here does not change the work’s review status.

SHA-256: ab6dd573fcb33e2925fc5b2f28471f7a21de1df2dd13c78bd212a9733952a356

Original source on GitHub

Back to Streaming Polyphase Factor Decomposition / SKAT