def test_fast_versions_properties_threshold_graphs(self): cs = "ddiiddid" G = nxt.threshold_graph(cs) assert nxt.density("ddiiddid") == nx.density(G) assert sorted(nxt.degree_sequence(cs)) == sorted( d for n, d in G.degree()) ts = nxt.triangle_sequence(cs) assert ts == list(nx.triangles(G).values()) assert sum(ts) // 3 == nxt.triangles(cs) c1 = nxt.cluster_sequence(cs) c2 = list(nx.clustering(G).values()) assert almost_equal(sum([abs(c - d) for c, d in zip(c1, c2)]), 0) b1 = nx.betweenness_centrality(G).values() b2 = nxt.betweenness_sequence(cs) assert sum([abs(c - d) for c, d in zip(b1, b2)]) < 1e-14 assert nxt.eigenvalues(cs) == [0, 1, 3, 3, 5, 7, 7, 8] # Degree Correlation assert abs(nxt.degree_correlation(cs) + 0.593038821954) < 1e-12 assert nxt.degree_correlation("diiiddi") == -0.8 assert nxt.degree_correlation("did") == -1.0 assert nxt.degree_correlation("ddd") == 1.0 assert nxt.eigenvalues("dddiii") == [0, 0, 0, 0, 3, 3] assert nxt.eigenvalues("dddiiid") == [0, 1, 1, 1, 4, 4, 7]
def test_fast_versions_properties_threshold_graphs(self): cs='ddiiddid' G=nxt.threshold_graph(cs) assert_equal(nxt.density('ddiiddid'), nx.density(G)) assert_equal(sorted(nxt.degree_sequence(cs)), sorted(d for n, d in G.degree())) ts=nxt.triangle_sequence(cs) assert_equal(ts, list(nx.triangles(G).values())) assert_equal(sum(ts) // 3, nxt.triangles(cs)) c1=nxt.cluster_sequence(cs) c2=list(nx.clustering(G).values()) assert_almost_equal(sum([abs(c-d) for c,d in zip(c1,c2)]), 0) b1=nx.betweenness_centrality(G).values() b2=nxt.betweenness_sequence(cs) assert_true(sum([abs(c-d) for c,d in zip(b1,b2)]) < 1e-14) assert_equal(nxt.eigenvalues(cs), [0, 1, 3, 3, 5, 7, 7, 8]) # Degree Correlation assert_true(abs(nxt.degree_correlation(cs)+0.593038821954) < 1e-12) assert_equal(nxt.degree_correlation('diiiddi'), -0.8) assert_equal(nxt.degree_correlation('did'), -1.0) assert_equal(nxt.degree_correlation('ddd'), 1.0) assert_equal(nxt.eigenvalues('dddiii'), [0, 0, 0, 0, 3, 3]) assert_equal(nxt.eigenvalues('dddiiid'), [0, 1, 1, 1, 4, 4, 7])
def test_fast_versions_properties_threshold_graphs(self): cs = 'ddiiddid' G = nxt.threshold_graph(cs) assert_equal(nxt.density('ddiiddid'), nx.density(G)) assert_equal(sorted(nxt.degree_sequence(cs)), sorted(d for n, d in G.degree())) ts = nxt.triangle_sequence(cs) assert_equal(ts, list(nx.triangles(G).values())) assert_equal(sum(ts) // 3, nxt.triangles(cs)) c1 = nxt.cluster_sequence(cs) c2 = list(nx.clustering(G).values()) assert_almost_equal(sum([abs(c - d) for c, d in zip(c1, c2)]), 0) b1 = nx.betweenness_centrality(G).values() b2 = nxt.betweenness_sequence(cs) assert_true(sum([abs(c - d) for c, d in zip(b1, b2)]) < 1e-14) assert_equal(nxt.eigenvalues(cs), [0, 1, 3, 3, 5, 7, 7, 8]) # Degree Correlation assert_true(abs(nxt.degree_correlation(cs) + 0.593038821954) < 1e-12) assert_equal(nxt.degree_correlation('diiiddi'), -0.8) assert_equal(nxt.degree_correlation('did'), -1.0) assert_equal(nxt.degree_correlation('ddd'), 1.0) assert_equal(nxt.eigenvalues('dddiii'), [0, 0, 0, 0, 3, 3]) assert_equal(nxt.eigenvalues('dddiiid'), [0, 1, 1, 1, 4, 4, 7])