def test_sparse_ICE_normalization(): n = 100 X = np.random.random((n, n)) thres = (np.random.random((n, n)) > 0.5).astype(bool) X[thres] = 0 X = X + X.T sparse_X = sparse.csr_matrix(X) true_normed_X = ICE_normalization(X, eps=1e-10, max_iter=10) normed_X = ICE_normalization(sparse_X, eps=1e-10, max_iter=10) assert_array_almost_equal(X, sparse_X.todense()) assert_array_almost_equal(true_normed_X, np.array(normed_X.todense()))
def test_sparse_ICE_normalization(): n = 100 random_state = np.random.RandomState(seed=42) X = random_state.randint(0, 100, size=(n, n)) thres = (random_state.rand(n, n) > 0.5).astype(bool) X[thres] = 0 X = X + X.T sparse_X = sparse.csr_matrix(X) true_normed_X = ICE_normalization(X, eps=1e-10, max_iter=10) normed_X = ICE_normalization(sparse_X, eps=1e-10, max_iter=10) assert_array_almost_equal(X, sparse_X.todense()) assert_array_almost_equal(true_normed_X, np.array(normed_X.todense()))
def test_sparse_ICE_normalization_triu(): n = 100 random_state = np.random.RandomState(seed=42) X = random_state.randint(0, 100, size=(n, n)) thres = (random_state.rand(n, n) > 0.5).astype(bool) X[thres] = 0 X = X + X.T sparse_X = sparse.triu(X) true_normed_X = ICE_normalization(X, eps=1e-10, max_iter=10) true_normed_X = np.triu(true_normed_X) X = np.triu(X) normed_X = ICE_normalization(sparse_X, eps=1e-10, max_iter=10) assert_array_almost_equal(X, sparse_X.todense()) # The sparse and dense version are going to be equal up to a constant # factor normed_X *= true_normed_X.mean() / normed_X.mean() assert_array_almost_equal(true_normed_X, np.array(normed_X.todense()))
def test_sparse_ICE_normalization_triu(): n = 100 random_state = np.random.RandomState(seed=42) X = random_state.randint(0, 100, size=(n, n)) thres = (random_state.rand(n, n) > 0.5).astype(bool) X[thres] = 0 X = X + X.T sparse_X = sparse.triu(X) true_normed_X, true_biases = ICE_normalization(X, eps=1e-10, max_iter=10, output_bias=True) true_normed_X = np.triu(true_normed_X) normed_X_sparse, biases_sparse = ICE_normalization(sparse_X, eps=1e-10, max_iter=100, output_bias=True) normed_X_dense, biases_dense = ICE_normalization(np.triu(X), eps=1e-10, max_iter=100, output_bias=True) # The sparse and dense version are going to be equal up to a constant # factor assert_array_almost_equal(normed_X_dense, np.array(normed_X_sparse.toarray())) normed_X_sparse *= true_normed_X.mean() / normed_X_sparse.mean() normed_X_dense *= true_normed_X.mean() / normed_X_dense.mean() assert_array_almost_equal(true_normed_X, np.array(normed_X_sparse.todense())) assert_array_almost_equal(true_normed_X, normed_X_dense) total_counts = 5000 normed_X = ICE_normalization(sparse_X, eps=1e-10, total_counts=total_counts) assert pytest.approx(normed_X.sum(), total_counts)
def test_sparse_ICE_normalization_triu(): n = 100 random_state = np.random.RandomState(seed=42) X = random_state.randint(0, 100, size=(n, n)) thres = (random_state.rand(n, n) > 0.5).astype(bool) X[thres] = 0 X = X + X.T sparse_X = sparse.triu(X) true_normed_X, true_biases = ICE_normalization( X, eps=1e-10, max_iter=10, output_bias=True) true_normed_X = np.triu(true_normed_X) normed_X_sparse, biases_sparse = ICE_normalization( sparse_X, eps=1e-10, max_iter=100, output_bias=True) normed_X_dense, biases_dense = ICE_normalization( np.triu(X), eps=1e-10, max_iter=100, output_bias=True) # The sparse and dense version are going to be equal up to a constant # factor assert_array_almost_equal(normed_X_dense, np.array(normed_X_sparse.toarray())) normed_X_sparse *= true_normed_X.mean() / normed_X_sparse.mean() normed_X_dense *= true_normed_X.mean() / normed_X_dense.mean() assert_array_almost_equal(true_normed_X, np.array(normed_X_sparse.todense())) assert_array_almost_equal(true_normed_X, normed_X_dense) total_counts = 5000 normed_X = ICE_normalization(sparse_X, eps=1e-10, total_counts=total_counts) assert_almost_equal(normed_X.sum(), total_counts)