本文整理汇总了Python中networkx.star_graph方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.star_graph方法的具体用法?Python networkx.star_graph怎么用?Python networkx.star_graph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.star_graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_line_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_line_graph():
N = 5
G = dgl.DGLGraph(nx.star_graph(N))
G.edata['h'] = F.randn((2 * N, D))
n_edges = G.number_of_edges()
L = G.line_graph(shared=True)
assert L.number_of_nodes() == 2 * N
L.ndata['h'] = F.randn((2 * N, D))
# update node features on line graph should reflect to edge features on
# original graph.
u = [0, 0, 2, 3]
v = [1, 2, 0, 0]
eid = G.edge_ids(u, v)
L.nodes[eid].data['h'] = F.zeros((4, D))
assert F.allclose(G.edges[u, v].data['h'], F.zeros((4, D)))
# adding a new node feature on line graph should also reflect to a new
# edge feature on original graph
data = F.randn((n_edges, D))
L.ndata['w'] = data
assert F.allclose(G.edata['w'], data)
示例2: test_neighbors
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_neighbors(self):
graph = nx.complete_graph(100)
pop = random.sample(graph.nodes(), 1)
nbors = list(nx.neighbors(graph, pop[0]))
# should be all the other vertices in the graph
assert_equal(len(nbors), len(graph) - 1)
graph = nx.path_graph(100)
node = random.sample(graph.nodes(), 1)[0]
nbors = list(nx.neighbors(graph, node))
# should be all the other vertices in the graph
if node != 0 and node != 99:
assert_equal(len(nbors), 2)
else:
assert_equal(len(nbors), 1)
# create a star graph with 99 outer nodes
graph = nx.star_graph(99)
nbors = list(nx.neighbors(graph, 0))
assert_equal(len(nbors), 99)
示例3: test_non_edges
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_non_edges(self):
# All possible edges exist
graph = nx.complete_graph(5)
nedges = list(nx.non_edges(graph))
assert_equal(len(nedges), 0)
graph = nx.path_graph(4)
expected = [(0, 2), (0, 3), (1, 3)]
nedges = list(nx.non_edges(graph))
for (u, v) in expected:
assert_true( (u, v) in nedges or (v, u) in nedges )
graph = nx.star_graph(4)
expected = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
nedges = list(nx.non_edges(graph))
for (u, v) in expected:
assert_true( (u, v) in nedges or (v, u) in nedges )
# Directed graphs
graph = nx.DiGraph()
graph.add_edges_from([(0, 2), (2, 0), (2, 1)])
expected = [(0, 1), (1, 0), (1, 2)]
nedges = list(nx.non_edges(graph))
for e in expected:
assert_true(e in nedges)
示例4: test_threshold_sequence_graph_test
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_threshold_sequence_graph_test(self):
G=nx.star_graph(10)
assert_true(nxt.is_threshold_graph(G))
assert_true(nxt.is_threshold_sequence(list(G.degree().values())))
G=nx.complete_graph(10)
assert_true(nxt.is_threshold_graph(G))
assert_true(nxt.is_threshold_sequence(list(G.degree().values())))
deg=[3,2,2,1,1,1]
assert_false(nxt.is_threshold_sequence(deg))
deg=[3,2,2,1]
assert_true(nxt.is_threshold_sequence(deg))
G=nx.generators.havel_hakimi_graph(deg)
assert_true(nxt.is_threshold_graph(G))
示例5: test_ego
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_ego(self):
G=nx.star_graph(3)
H=nx.ego_graph(G,0)
assert_true(nx.is_isomorphic(G,H))
G.add_edge(1,11)
G.add_edge(2,22)
G.add_edge(3,33)
H=nx.ego_graph(G,0)
assert_true(nx.is_isomorphic(nx.star_graph(3),H))
G=nx.path_graph(3)
H=nx.ego_graph(G,0)
assert_equal(H.edges(), [(0, 1)])
H=nx.ego_graph(G,0,undirected=True)
assert_equal(H.edges(), [(0, 1)])
H=nx.ego_graph(G,0,center=False)
assert_equal(H.edges(), [])
示例6: test_neighbors_complete_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_neighbors_complete_graph(self):
graph = nx.complete_graph(100)
pop = random.sample(list(graph), 1)
nbors = list(nx.neighbors(graph, pop[0]))
# should be all the other vertices in the graph
assert_equal(len(nbors), len(graph) - 1)
graph = nx.path_graph(100)
node = random.sample(list(graph), 1)[0]
nbors = list(nx.neighbors(graph, node))
# should be all the other vertices in the graph
if node != 0 and node != 99:
assert_equal(len(nbors), 2)
else:
assert_equal(len(nbors), 1)
# create a star graph with 99 outer nodes
graph = nx.star_graph(99)
nbors = list(nx.neighbors(graph, 0))
assert_equal(len(nbors), 99)
示例7: test_non_edges
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_non_edges(self):
# All possible edges exist
graph = nx.complete_graph(5)
nedges = list(nx.non_edges(graph))
assert_equal(len(nedges), 0)
graph = nx.path_graph(4)
expected = [(0, 2), (0, 3), (1, 3)]
nedges = list(nx.non_edges(graph))
for (u, v) in expected:
assert_true((u, v) in nedges or (v, u) in nedges)
graph = nx.star_graph(4)
expected = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
nedges = list(nx.non_edges(graph))
for (u, v) in expected:
assert_true((u, v) in nedges or (v, u) in nedges)
# Directed graphs
graph = nx.DiGraph()
graph.add_edges_from([(0, 2), (2, 0), (2, 1)])
expected = [(0, 1), (1, 0), (1, 2)]
nedges = list(nx.non_edges(graph))
for e in expected:
assert_true(e in nedges)
示例8: test_ego
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_ego(self):
G = nx.star_graph(3)
H = nx.ego_graph(G, 0)
assert_true(nx.is_isomorphic(G, H))
G.add_edge(1, 11)
G.add_edge(2, 22)
G.add_edge(3, 33)
H = nx.ego_graph(G, 0)
assert_true(nx.is_isomorphic(nx.star_graph(3), H))
G = nx.path_graph(3)
H = nx.ego_graph(G, 0)
assert_edges_equal(H.edges(), [(0, 1)])
H = nx.ego_graph(G, 0, undirected=True)
assert_edges_equal(H.edges(), [(0, 1)])
H = nx.ego_graph(G, 0, center=False)
assert_edges_equal(H.edges(), [])
示例9: test_neighbors
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_neighbors(self):
graph = nx.complete_graph(100)
pop = random.sample(list(graph), 1)
nbors = list(nx.neighbors(graph, pop[0]))
# should be all the other vertices in the graph
assert_equal(len(nbors), len(graph) - 1)
graph = nx.path_graph(100)
node = random.sample(list(graph), 1)[0]
nbors = list(nx.neighbors(graph, node))
# should be all the other vertices in the graph
if node != 0 and node != 99:
assert_equal(len(nbors), 2)
else:
assert_equal(len(nbors), 1)
# create a star graph with 99 outer nodes
graph = nx.star_graph(99)
nbors = list(nx.neighbors(graph, 0))
assert_equal(len(nbors), 99)
示例10: test_threshold_sequence_graph_test
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_threshold_sequence_graph_test(self):
G = nx.star_graph(10)
assert_true(nxt.is_threshold_graph(G))
assert_true(nxt.is_threshold_sequence(list(d for n, d in G.degree())))
G = nx.complete_graph(10)
assert_true(nxt.is_threshold_graph(G))
assert_true(nxt.is_threshold_sequence(list(d for n, d in G.degree())))
deg = [3, 2, 2, 1, 1, 1]
assert_false(nxt.is_threshold_sequence(deg))
deg = [3, 2, 2, 1]
assert_true(nxt.is_threshold_sequence(deg))
G = nx.generators.havel_hakimi_graph(deg)
assert_true(nxt.is_threshold_graph(G))
示例11: _gen_star
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def _gen_star(self, n):
for _ in range(n):
num_v = np.random.randint(self.min_num_v, self.max_num_v)
# nx.star_graph(N) gives a star graph with N+1 nodes
g = nx.star_graph(num_v - 1)
self.graphs.append(g)
self.labels.append(1)
示例12: test_no_backtracking
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_no_backtracking():
N = 5
G = dgl.DGLGraph(nx.star_graph(N))
L = G.line_graph(backtracking=False)
assert L.number_of_nodes() == 2 * N
for i in range(1, N):
e1 = G.edge_id(0, i)
e2 = G.edge_id(i, 0)
assert not L.has_edge_between(e1, e2)
assert not L.has_edge_between(e2, e1)
# reverse graph related
示例13: test_graph_directed
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_graph_directed():
"""
Ensure we keep newly constructed topologies as directed graph
"""
topo = complete_topology(5)
assert isinstance(topo.get_graph(), networkx.DiGraph)
# even if original graph is undirected
topo = Topology(u'noname', networkx.star_graph(8))
assert topo.get_graph().is_directed()
示例14: test_non_neighbors
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_non_neighbors(self):
graph = nx.complete_graph(100)
pop = random.sample(graph.nodes(), 1)
nbors = list(nx.non_neighbors(graph, pop[0]))
# should be all the other vertices in the graph
assert_equal(len(nbors), 0)
graph = nx.path_graph(100)
node = random.sample(graph.nodes(), 1)[0]
nbors = list(nx.non_neighbors(graph, node))
# should be all the other vertices in the graph
if node != 0 and node != 99:
assert_equal(len(nbors), 97)
else:
assert_equal(len(nbors), 98)
# create a star graph with 99 outer nodes
graph = nx.star_graph(99)
nbors = list(nx.non_neighbors(graph, 0))
assert_equal(len(nbors), 0)
# disconnected graph
graph = nx.Graph()
graph.add_nodes_from(range(10))
nbors = list(nx.non_neighbors(graph, 0))
assert_equal(len(nbors), 9)
示例15: test_S4
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import star_graph [as 别名]
def test_S4(self):
G = nx.star_graph(4)
self.test(G, 1, 2, [0])