def test_infomap_partition(): """ Test informap partition function """ tmpmat = np.ones((10, 10)) util.fill_diagonal(tmpmat, 0) graph = nx.from_numpy_matrix(tmpmat, nx.Graph(weighted=False)) part = mod.infomap_partition(graph) ## if all edges are connected expect only one partition expected_part = {0: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])} nt.assert_equal(part.index, expected_part)
def test_newman_partition(): """ Test Newman Partition function """ tmpmat = np.random.random((10, 10)) tmpmat[tmpmat < .5] = 0 graph = nx.from_numpy_matrix(tmpmat, nx.Graph(weighted=False)) npt.assert_raises(ValueError, mod.newman_partition, graph) tmpmat[:] = 0 # test that no edges raises error (from GraphPartition) graph = nx.from_numpy_matrix(tmpmat, nx.Graph(weighted=False)) npt.assert_raises(ValueError, mod.newman_partition, graph) tmpmat[:] = 1 util.fill_diagonal(tmpmat, 0) graph = nx.from_numpy_matrix(tmpmat, nx.Graph(weighted=False)) part = mod.newman_partition(graph) ## if all edges are connected expect only one partition expected_part = {0: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])} nt.assert_equal(part.index, expected_part)
def test_newman_partition(): """ Test Newman Partition function """ tmpmat = np.random.random((10, 10)) tmpmat[tmpmat < 0.5] = 0 graph = nx.from_numpy_matrix(tmpmat, nx.Graph(weighted=False)) npt.assert_raises(ValueError, mod.newman_partition, graph) tmpmat[:] = 0 # test that no edges raises error (from GraphPartition) graph = nx.from_numpy_matrix(tmpmat, nx.Graph(weighted=False)) npt.assert_raises(ValueError, mod.newman_partition, graph) tmpmat[:] = 1 util.fill_diagonal(tmpmat, 0) graph = nx.from_numpy_matrix(tmpmat, nx.Graph(weighted=False)) part = mod.newman_partition(graph) ## if all edges are connected expect only one partition expected_part = {0: set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])} nt.assert_equal(part.index, expected_part)
size = 11 th2 = 0.6 th1 = -th2 # Split the node list in half, and use two colors for each group split = size / 2 nodes = range(size) head, tail = nodes[:split], nodes[split:] labels = ['%s%s' % (chr(i), chr(i + 32)) for i in range(65, 65 + size)] #labels = map(str,nodes) colors = ['y' for _ in head] + ['r' for _ in tail] mat = util.symm_rand_arr(size) mat = 2 * mat - 1 # map values to [-1,1] range util.fill_diagonal(mat, 0) # diag==0 so we don't get self-links layout = nx.circular_layout G = util.mat2graph(mat, threshold=th1, threshold2=th2) pfig = nxplot.draw_graph( G, labels=labels, node_colors=colors, layout=layout, title=layout.func_name, #edge_cmap=cm.PuOr edge_cmap=cm.RdBu, #edge_cmap=cm.jet, colorbar=True,
size = 11 th2 = 0.6 th1 = -th2 # Split the node list in half, and use two colors for each group split = size/2 nodes = range(size) head,tail = nodes[:split],nodes[split:] labels = ['%s%s' % (chr(i),chr(i+32)) for i in range(65,65+size)] #labels = map(str,nodes) colors = ['y' for _ in head] + ['r' for _ in tail] mat = util.symm_rand_arr(size) mat = 2*mat-1 # map values to [-1,1] range util.fill_diagonal(mat,0) # diag==0 so we don't get self-links layout = nx.circular_layout G = util.mat2graph(mat, threshold=th1,threshold2=th2) pfig = nxplot.draw_graph(G, labels=labels, node_colors=colors, layout = layout, title = layout.func_name, #edge_cmap=cm.PuOr edge_cmap=cm.RdBu, #edge_cmap=cm.jet, colorbar=True, )