def test_random_uniform(self): uniform = BlockMatrix.random(10, 10, gaussian=False) nuniform = uniform.to_numpy() for row in nuniform: for entry in row: assert entry > 0
def test_random_uniform(self): uniform = BlockMatrix.random(10, 10, gaussian=False) nuniform = uniform.to_numpy() for row in nuniform: for entry in row: assert entry > 0
def get_Z(N_r): r''' Returns `N_r`-dim standard normal random vector ''' Z = BlockMatrix.random( n_rows=N_r, n_cols=1, gaussian=True) # N_r-dimensional standard normal random vector return Z
def test_to_matrix_table(self): n_partitions = 2 rows, cols = 2, 5 bm = BlockMatrix._create(rows, cols, [float(i) for i in range(10)]) actual = bm.to_matrix_table_row_major(n_partitions) expected = hl.utils.range_matrix_table(rows, cols) expected = expected.annotate_entries(element=hl.float64(expected.row_idx * cols + expected.col_idx)) expected = expected.key_cols_by(col_idx=hl.int64(expected.col_idx)) expected = expected.key_rows_by(row_idx=hl.int64(expected.row_idx)) assert expected._same(actual) bm = BlockMatrix.random(50, 100, block_size=25, seed=0) mt = bm.to_matrix_table_row_major(n_partitions) mt_round_trip = BlockMatrix.from_entry_expr(mt.element).to_matrix_table_row_major() assert mt._same(mt_round_trip)
def test_to_matrix_table(self): n_partitions = 2 rows, cols = 2, 5 bm = BlockMatrix._create(rows, cols, [float(i) for i in range(10)]) actual = bm.to_matrix_table_row_major(n_partitions) expected = hl.utils.range_matrix_table(rows, cols) expected = expected.annotate_entries(element=hl.float64(expected.row_idx * cols + expected.col_idx)) expected = expected.key_cols_by(col_idx=hl.int64(expected.col_idx)) expected = expected.key_rows_by(row_idx=hl.int64(expected.row_idx)) assert expected._same(actual) bm = BlockMatrix.random(50, 100, block_size=25, seed=0) mt = bm.to_matrix_table_row_major(n_partitions) mt_round_trip = BlockMatrix.from_entry_expr(mt.element).to_matrix_table_row_major() assert mt._same(mt_round_trip)
def get_beta(M, h2, pi=1, seed=None, astype=BlockMatrix): r''' Returns M-dim vector of true SNP effect sizes ''' assert pi >= 0 and pi <= 1, '`pi` (proportion of causal variants) must be in the interval [0,1]' kwargs = {'seed': seed} if type(seed) != type(None) else {} if pi == 1: #infinitesimal model beta = np.sqrt(h2 / M) * BlockMatrix.random( n_rows=M, n_cols=1, gaussian=True, **kwargs) else: np.random.seed(seed) M_causal = round(M * pi) # number of causal variants causal_beta = np.random.normal(loc=0, scale=np.sqrt(h2 / M_causal), size=(M_causal, 1)) causal_idx = np.random.choice(M, replace=False, size=M_causal) causal_idx.sort() beta = np.zeros(shape=(M, 1)) beta[causal_idx] = causal_beta return _cast(beta, astype=astype)
import hail as hl from hail.linalg import BlockMatrix mt = hl.import_vcf('gs://hail-1kg/1kg_coreexome.vcf.bgz', min_partitions=16) mt = mt.annotate_rows(x=5) mt._force_count_rows() mt = hl.import_bgen('gs://hail-common/test-resources/example.8bits.bgen', entry_fields=['GT']) mt._force_count_rows() bm = BlockMatrix.random(10, 11, block_size=32) bm.to_numpy(_force_blocking=True) bm.to_numpy()
import hail as hl from hail.linalg import BlockMatrix mt = hl.import_vcf('gs://hail-1kg/1kg_coreexome.vcf.bgz') mt = mt.annotate_rows(x = 5) mt._force_count_rows() mt = hl.import_bgen('gs://hail-ci/example.8bits.bgen', entry_fields=['GT']) mt._force_count_rows() bm = BlockMatrix.random(10, 11) bm.to_numpy(_force_blocking=True) bm.to_numpy()
import hail as hl from hail.linalg import BlockMatrix mt = hl.import_vcf('gs://hail-1kg/1kg_coreexome.vcf.bgz') mt = mt.annotate_rows(x=5) mt._force_count_rows() mt = hl.import_bgen('gs://hail-ci/example.8bits.bgen', entry_fields=['GT']) mt._force_count_rows() bm = BlockMatrix.random(10, 11) bm.to_numpy(_force_blocking=True) bm.to_numpy()