def test_omni_unconnected(): np.random.seed(4) n = 100 m = 50 graphs = [er_nm(n, m) for _ in range(2)] omni = OmnibusEmbed() with pytest.warns(UserWarning): omni.fit(graphs)
def test_diag_aug(): np.random.seed(5) n = 100 p = 0.25 graphs_list = [er_np(n, p) for _ in range(2)] graphs_arr = np.array(graphs_list) # Test that array and list inputs results in same embeddings omni_arr = OmnibusEmbed(diag_aug=True).fit_transform(graphs_arr) omni_list = OmnibusEmbed(diag_aug=True).fit_transform(graphs_list) assert array_equal(omni_list, omni_arr)
def test_omni_embed(): """ We compare the difference of norms of OmniBar and ABar. ABar is the lowest variance estimate of the latent positions X. OmniBar should be reasonablly close to ABar when n_vertices is high. """ def compute_bar(arr): n = arr.shape[0] // 2 return (arr[:n] + arr[n:]) / 2 X, A1, A2 = generate_data(1000) Abar = (A1 + A2) / 2 np.random.seed(11) omni = OmnibusEmbed(n_components=3) OmniBar = compute_bar(omni.fit_transform([A1, A2])) omni = OmnibusEmbed(n_components=3) ABar = compute_bar(omni.fit_transform([Abar, Abar])) tol = 1.0e-2 assert allclose(norm(OmniBar, axis=1), norm(ABar, axis=1), rtol=tol, atol=tol)
def run(diag_aug): X, A1, A2 = generate_data(1000, seed=2) Abar = (A1 + A2) / 2 omni = OmnibusEmbed(n_components=3, diag_aug=diag_aug) OmniBar = compute_bar(omni.fit_transform([A1, A2])) omni = OmnibusEmbed(n_components=3, diag_aug=diag_aug) ABar = compute_bar(omni.fit_transform([Abar, Abar])) tol = 1.0e-2 assert allclose(norm(OmniBar, axis=1), norm(ABar, axis=1), rtol=tol, atol=tol)
def test_omni_matrix_invalid_inputs(): with pytest.raises(ValueError): empty_list = [] omni = OmnibusEmbed(n_components=2) omni.fit(empty_list) with pytest.raises(ValueError): wrong_shapes = [np.ones((10, 10)), np.ones((20, 20))] omni = OmnibusEmbed(n_components=2) omni.fit(wrong_shapes) with pytest.raises(TypeError): wrong_dtypes = [1, 2, 3] omni = OmnibusEmbed(n_components=2) omni.fit(wrong_dtypes)