def test_bad_inputs(): np.random.seed(1) single_graph = er_np(100, 0.2) different_size_graphs = [er_np(100, 0.2)] + [er_np(200, 0.2)] with pytest.raises(TypeError): "Invalid unscaled" mase = MultipleASE(scaled="1") with pytest.raises(TypeError): wrong_diag_aug = "True" mase = MultipleASE(diag_aug=wrong_diag_aug) with pytest.raises(ValueError): "Test single graph input" MultipleASE().fit(single_graph) with pytest.raises(ValueError): "Test 3-d tensor with 1 graph" single_graph_tensor = single_graph.reshape(1, 100, -1) MultipleASE().fit(single_graph_tensor) with pytest.raises(ValueError): "Empty list" MultipleASE().fit([]) with pytest.raises(ValueError): "Test graphs with different sizes" MultipleASE().fit(different_size_graphs)
def test_gridplot_outputs(): """ simple function to see if plot is made without errors """ X = [er_np(10, 0.5) for _ in range(2)] labels = ["Random A", "Random B"] fig = gridplot(X, labels) fig = gridplot(X, labels, transform="zero-boost") fig = gridplot(X, labels, "simple-all", title="Test", font_scale=0.9)
def test_omni_matrix_symmetric(): np.random.seed(3) n = 15 p = 0.4 n_graphs = [2, 5, 10] for n in n_graphs: graphs = [er_np(n, p) for _ in range(n)] output = _get_omni_matrix(graphs) assert is_symmetric(output)
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 mase_arr = MultipleASE(diag_aug=True).fit_transform(graphs_arr) mase_list = MultipleASE(diag_aug=True).fit_transform(graphs_list) assert array_equal(mase_list, mase_arr)
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_gridplot_inputs(): X = [er_np(10, 0.5)] labels = ["ER(10, 0.5)"] with pytest.raises(TypeError): gridplot(X="input", labels=labels) with pytest.raises(ValueError): gridplot(X, labels=["a", "b"]) # transform with pytest.raises(ValueError): transform = "bad transform" gridplot(X, labels=labels, transform=transform)
def test_omni_matrix_random(): expected_output = np.array([ [0.0, 1.0, 1.0, 0.0, 0.5, 0.5], [1.0, 0.0, 1.0, 0.5, 0.0, 1.0], [1.0, 1.0, 0.0, 0.5, 1.0, 0.0], [0.0, 0.5, 0.5, 0.0, 0.0, 0.0], [0.5, 0.0, 1.0, 0.0, 0.0, 1.0], [0.5, 1.0, 0.0, 0.0, 1.0, 0.0], ]) np.random.seed(4) graphs = [er_np(3, 0.5) for _ in range(2)] A = _get_omni_matrix(graphs) assert_allclose(A, expected_output)
def test_heatmap_output(): """ simple function to see if plot is made without errors """ X = er_np(10, 0.5) xticklabels = ["Dimension {}".format(i) for i in range(10)] yticklabels = ["Dimension {}".format(i) for i in range(10)] fig = heatmap(X, transform="log", xticklabels=xticklabels, yticklabels=yticklabels) fig = heatmap(X, transform="zero-boost") fig = heatmap(X, transform="simple-all") fig = heatmap(X, transform="simple-nonzero") fig = heatmap(X, cmap="gist_rainbow")
def _test_sbm_er_binary_undirected(self, method, P, *args, **kwargs): np.random.seed(8888) num_sims = 50 verts = 200 communities = 2 verts_per_community = [100, 100] sbm_wins = 0 er_wins = 0 for sim in range(0, num_sims): sbm_sample = sbm(verts_per_community, P) er = er_np(verts, 0.5) embed_sbm = method(n_components=2) embed_er = method(n_components=2) labels_sbm = np.zeros((verts), dtype=np.int8) labels_er = np.zeros((verts), dtype=np.int8) labels_sbm[100:] = 1 labels_er[100:] = 1 embed_sbm.fit(sbm_sample) embed_er.fit(er) X_sbm = embed_sbm.latent_left_ X_er = embed_er.latent_left_ self.assertEqual(X_sbm.shape, (verts, communities)) self.assertEqual(X_er.shape, (verts, communities)) aris = _kmeans_comparison((X_sbm, X_er), (labels_sbm, labels_er), communities) sbm_wins = sbm_wins + (aris[0] > aris[1]) er_wins = er_wins + (aris[0] < aris[1]) self.assertTrue(sbm_wins > er_wins)
def test_common_inputs(): X = er_np(100, 0.5) grid_labels = ["Test1"] # test figsize with pytest.raises(TypeError): figsize = "bad figsize" heatmap(X, figsize=figsize) # test height height = "1" with pytest.raises(TypeError): gridplot([X], grid_labels, height=height) with pytest.raises(TypeError): pairplot(X, height=height) # test title title = 1 with pytest.raises(TypeError): heatmap(X, title=title) with pytest.raises(TypeError): gridplot([X], grid_labels, title=title) with pytest.raises(TypeError): pairplot(X, title=title) # test context context = 123 with pytest.raises(TypeError): heatmap(X, context=context) with pytest.raises(TypeError): gridplot([X], grid_labels, context=context) with pytest.raises(TypeError): pairplot(X, context=context) context = "journal" with pytest.raises(ValueError): heatmap(X, context=context) with pytest.raises(ValueError): gridplot([X], grid_labels, context=context) with pytest.raises(ValueError): pairplot(X, context=context) # test font scales font_scales = ["1", []] for font_scale in font_scales: with pytest.raises(TypeError): heatmap(X, font_scale=font_scale) with pytest.raises(TypeError): gridplot([X], grid_labels, font_scale=font_scale) with pytest.raises(TypeError): pairplot(X, cont_scale=font_scale) # ticklabels with pytest.raises(TypeError): xticklabels = "labels" yticklabels = "labels" heatmap(X, xticklabels=xticklabels, yticklabels=yticklabels) with pytest.raises(ValueError): xticklabels = ["{}".format(i) for i in range(5)] yticklabels = ["{}".format(i) for i in range(5)] heatmap(X, xticklabels=xticklabels, yticklabels=yticklabels)
def setup_class(cls): # simple ERxN graph cls.n = 20 cls.p = 0.5 cls.A = er_np(cls.n, cls.p, directed=True, loops=False)