本文整理汇总了Python中networkx.cubical_graph函数的典型用法代码示例。如果您正苦于以下问题:Python cubical_graph函数的具体用法?Python cubical_graph怎么用?Python cubical_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cubical_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_periodic
def test_periodic(self):
G = nx.grid_2d_graph(0, 0, periodic=True)
assert_equal(dict(G.degree()), {})
for m, n, H in [(2, 2, nx.cycle_graph(4)), (1, 7, nx.cycle_graph(7)),
(7, 1, nx.cycle_graph(7)),
(2, 5, nx.circular_ladder_graph(5)),
(5, 2, nx.circular_ladder_graph(5)),
(2, 4, nx.cubical_graph()),
(4, 2, nx.cubical_graph())]:
G = nx.grid_2d_graph(m, n, periodic=True)
assert_true(nx.could_be_isomorphic(G, H))
示例2: test_labels_and_colors
def test_labels_and_colors(self):
G = nx.cubical_graph()
pos = nx.spring_layout(G) # positions for all nodes
# nodes
nx.draw_networkx_nodes(G, pos,
nodelist=[0, 1, 2, 3],
node_color='r',
node_size=500,
alpha=0.8)
nx.draw_networkx_nodes(G, pos,
nodelist=[4, 5, 6, 7],
node_color='b',
node_size=500,
alpha=0.8)
# edges
nx.draw_networkx_edges(G, pos, width=1.0, alpha=0.5)
nx.draw_networkx_edges(G, pos,
edgelist=[(0, 1), (1, 2), (2, 3), (3, 0)],
width=8, alpha=0.5, edge_color='r')
nx.draw_networkx_edges(G, pos,
edgelist=[(4, 5), (5, 6), (6, 7), (7, 4)],
width=8, alpha=0.5, edge_color='b')
# some math labels
labels = {}
labels[0] = r'$a$'
labels[1] = r'$b$'
labels[2] = r'$c$'
labels[3] = r'$d$'
labels[4] = r'$\alpha$'
labels[5] = r'$\beta$'
labels[6] = r'$\gamma$'
labels[7] = r'$\delta$'
nx.draw_networkx_labels(G, pos, labels, font_size=16)
plt.show()
示例3: test_cubical
def test_cubical(self):
G = nx.cubical_graph()
assert_equal(list(nx.square_clustering(G).values()),
[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])
assert_equal(list(nx.square_clustering(G,[1,2]).values()),[0.5, 0.5])
assert_equal(nx.square_clustering(G,[1])[1],0.5)
assert_equal(nx.square_clustering(G,[1,2]),{1: 0.5, 2: 0.5})
示例4: CutOffLessThan5D
def CutOffLessThan5D(self, pairs, dataTbl, cmc):
# build matrix from pairs
sna.loadGraphFromCsv(foMF + ".pairs", " ")
sna.runMeasure("totaldegreeCentrality")
print("\n display results .\n")
sna.displayResults("totaldegreeCentrality")
print("\n")
try:
print("Loading network from file\n(%s)" % (foMF + ".pairs"))
self.graph = networkx.read_edgelist(foMF + ".pairs", delimiter=" ")
self.graph.name = "Social Network"
print("Attempt to draw graph.\n")
G = networkx.cubical_graph()
print("created G")
networkx.draw(G)
plt.show() # display
print("Degree centrality")
d = degree_centrality(G)
for v in G.nodes():
print("%0.2d %5.3f" % (v, d[v]))
except:
print("Unable to open file:", filename)
print("cutoff < 5 degrees end method.\n")
示例5: test_cubical
def test_cubical(self):
G = nx.cubical_graph()
assert_equal(nx.triangles(G).values(),
[0, 0, 0, 0, 0, 0, 0, 0])
assert_equal(nx.triangles(G,1),0)
assert_equal(nx.triangles(G,[1,2]).values(),[0, 0])
assert_equal(nx.triangles(G,1),0)
assert_equal(nx.triangles(G,[1,2]),{1: 0, 2: 0})
示例6: test_cartesian_product_classic
def test_cartesian_product_classic():
# test some classic product graphs
P2 = nx.path_graph(2)
P3 = nx.path_graph(3)
# cube = 2-path X 2-path
G=cartesian_product(P2,P2)
G=cartesian_product(P2,G)
assert_true(nx.is_isomorphic(G,nx.cubical_graph()))
# 3x3 grid
G=cartesian_product(P3,P3)
assert_true(nx.is_isomorphic(G,nx.grid_2d_graph(3,3)))
示例7: test_is_distance_regular
def test_is_distance_regular(self):
assert_true(nx.is_distance_regular(nx.icosahedral_graph()))
assert_true(nx.is_distance_regular(nx.petersen_graph()))
assert_true(nx.is_distance_regular(nx.cubical_graph()))
assert_true(nx.is_distance_regular(nx.complete_bipartite_graph(3,3)))
assert_true(nx.is_distance_regular(nx.tetrahedral_graph()))
assert_true(nx.is_distance_regular(nx.dodecahedral_graph()))
assert_true(nx.is_distance_regular(nx.pappus_graph()))
assert_true(nx.is_distance_regular(nx.heawood_graph()))
assert_true(nx.is_distance_regular(nx.cycle_graph(3)))
# no distance regular
assert_false(nx.is_distance_regular(nx.path_graph(4)))
示例8: test_tensor_product_classic_result
def test_tensor_product_classic_result():
K2 = nx.complete_graph(2)
G = nx.petersen_graph()
G = tensor_product(G,K2)
assert_true(nx.is_isomorphic(G,nx.desargues_graph()))
G = nx.cycle_graph(5)
G = tensor_product(G,K2)
assert_true(nx.is_isomorphic(G,nx.cycle_graph(10)))
G = nx.tetrahedral_graph()
G = tensor_product(G,K2)
assert_true(nx.is_isomorphic(G,nx.cubical_graph()))
示例9: test_tensor_product
def test_tensor_product():
null=nx.null_graph()
empty1=nx.empty_graph(1)
empty10=nx.empty_graph(10)
K2=nx.complete_graph(2)
K3=nx.complete_graph(3)
K5=nx.complete_graph(5)
K10=nx.complete_graph(10)
P2=nx.path_graph(2)
P3=nx.path_graph(3)
P5=nx.path_graph(5)
P10=nx.path_graph(10)
# null graph
G=tensor_product(null,null)
assert_true(nx.is_isomorphic(G,null))
# null_graph X anything = null_graph and v.v.
G=tensor_product(null,empty10)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(null,K3)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(null,K10)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(null,P3)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(null,P10)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(empty10,null)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(K3,null)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(K10,null)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(P3,null)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(P10,null)
assert_true(nx.is_isomorphic(G,null))
G=tensor_product(P5,K3)
assert_equal(nx.number_of_nodes(G),5*3)
G=tensor_product(K3,K5)
assert_equal(nx.number_of_nodes(G),3*5)
G = nx.petersen_graph()
G = tensor_product(G,K2)
assert_true(nx.is_isomorphic(G,nx.desargues_graph()))
G = nx.cycle_graph(5)
G = tensor_product(G,K2)
assert_true(nx.is_isomorphic(G,nx.cycle_graph(10)))
G = nx.tetrahedral_graph()
G = tensor_product(G,K2)
assert_true(nx.is_isomorphic(G,nx.cubical_graph()))
G = nx.erdos_renyi_graph(10,2/10.)
H = nx.erdos_renyi_graph(10,2/10.)
GH = tensor_product(G,H)
for (u_G,u_H) in GH.nodes_iter():
for (v_G,v_H) in GH.nodes_iter():
if H.has_edge(u_H,v_H) and G.has_edge(u_G,v_G):
assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))
else:
assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
示例10:
import matplotlib.pyplot as plt
import networkx as nx
G=nx.cubical_graph()
pos=nx.spring_layout(G) # positions for all nodes
print(G)
# nodes
nx.draw_networkx_nodes(G,pos,
nodelist=[0,1,2,3],
node_color='r',
node_size=500,
alpha=0.8)
nx.draw_networkx_nodes(G,pos,
nodelist=[4,5,6,7],
node_color='b',
node_size=500,
alpha=0.8)
# edges
nx.draw_networkx_edges(G,pos,width=1.0,alpha=0.5)
nx.draw_networkx_edges(G,pos,
edgelist=[(0,1),(1,2),(2,3),(3,0)],
width=8,alpha=0.5,edge_color='r')
nx.draw_networkx_edges(G,pos,
edgelist=[(4,5),(5,6),(6,7),(7,4)],
width=8,alpha=0.5,edge_color='b')
# some math labels
labels={}
示例11: test_cartesian_product
def test_cartesian_product():
null=nx.null_graph()
empty1=nx.empty_graph(1)
empty10=nx.empty_graph(10)
K3=nx.complete_graph(3)
K5=nx.complete_graph(5)
K10=nx.complete_graph(10)
P2=nx.path_graph(2)
P3=nx.path_graph(3)
P5=nx.path_graph(5)
P10=nx.path_graph(10)
# null graph
G=cartesian_product(null,null)
assert_true(nx.is_isomorphic(G,null))
# null_graph X anything = null_graph and v.v.
G=cartesian_product(null,empty10)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,K3)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,K10)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,P3)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,P10)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(empty10,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(K3,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(K10,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(P3,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(P10,null)
assert_true(nx.is_isomorphic(G,null))
# order(GXH)=order(G)*order(H)
G=cartesian_product(P5,K3)
assert_equal(nx.number_of_nodes(G),5*3)
assert_equal(nx.number_of_edges(G),
nx.number_of_edges(P5)*nx.number_of_nodes(K3)+
nx.number_of_edges(K3)*nx.number_of_nodes(P5))
G=cartesian_product(K3,K5)
assert_equal(nx.number_of_nodes(G),3*5)
assert_equal(nx.number_of_edges(G),
nx.number_of_edges(K5)*nx.number_of_nodes(K3)+
nx.number_of_edges(K3)*nx.number_of_nodes(K5))
# test some classic product graphs
# cube = 2-path X 2-path
G=cartesian_product(P2,P2)
G=cartesian_product(P2,G)
assert_true(nx.is_isomorphic(G,nx.cubical_graph()))
# 3x3 grid
G=cartesian_product(P3,P3)
assert_true(nx.is_isomorphic(G,nx.grid_2d_graph(3,3)))
G = nx.erdos_renyi_graph(10,2/10.)
H = nx.erdos_renyi_graph(10,2/10.)
GH = cartesian_product(G,H)
for (u_G,u_H) in GH.nodes_iter():
for (v_G,v_H) in GH.nodes_iter():
if (u_G==v_G and H.has_edge(u_H,v_H)) or \
(u_H==v_H and G.has_edge(u_G,v_G)):
assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))
else:
assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
示例12: test_special_cases
def test_special_cases(self):
for n, H in [(0, nx.null_graph()), (1, nx.path_graph(2)),
(2, nx.cycle_graph(4)), (3, nx.cubical_graph())]:
G = nx.hypercube_graph(n)
assert_true(nx.could_be_isomorphic(G, H))
示例13:
import networkx as nx
import matplotlib.pylab as plt
from plot_multigraph import plot_multigraph
graphs = [
("bull", nx.bull_graph()),
("chvatal", nx.chvatal_graph()),
("cubical", nx.cubical_graph()),
("desargues", nx.desargues_graph()),
("diamond", nx.diamond_graph()),
("dodecahedral", nx.dodecahedral_graph()),
("frucht", nx.frucht_graph()),
("heawood", nx.heawood_graph()),
("house", nx.house_graph()),
("house_x", nx.house_x_graph()),
("icosahedral", nx.icosahedral_graph()),
("krackhardt_kite", nx.krackhardt_kite_graph()),
("moebius_kantor", nx.moebius_kantor_graph()),
("octahedral", nx.octahedral_graph()),
("pappus", nx.pappus_graph()),
("petersen", nx.petersen_graph()),
("sedgewick_maze", nx.sedgewick_maze_graph()),
("tetrahedral", nx.tetrahedral_graph()),
("truncated_cube", nx.truncated_cube_graph()),
("truncated_tetrahedron", nx.truncated_tetrahedron_graph()),
]
plot_multigraph(graphs, 4, 5, node_size=50)
plt.savefig('graphs/small.png')
示例14: xrange
# -*- coding: utf-8 -*-
import networkx as nx
import matplotlib.pylab as plt
from numpy.random import *
import colorsys
if __name__ == '__main__':
sample = nx.cubical_graph()
for i in xrange(0,50):
sample.add_node(i)
for i in xrange(0,50):
sample.add_edge(i,poisson(lam=30))
#print sample.edges()
try: print nx.shortest_path(sample, 30, 0)
except: print u"ぼっち"
#graph layput
#circular, random, shell, spring, spectral
#ncolors = [colorsys.hsv_to_rgb(h / num_nodes, 1.0, 1.0)for h in range(num_nodes)]
nx.draw(sample, pos=nx.spring_layout(sample), node_color='white',edge_color="g")
plt.savefig("sample.png")
nx.write_gexf(sample, "sample.gexf")
示例15: generate_cubic
def generate_cubic():
return nx.cubical_graph()