本文整理匯總了Python中networkx.stochastic_graph方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.stochastic_graph方法的具體用法?Python networkx.stochastic_graph怎麽用?Python networkx.stochastic_graph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.stochastic_graph方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_stochastic
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_stochastic():
G=nx.DiGraph()
G.add_edge(0,1)
G.add_edge(0,2)
S=nx.stochastic_graph(G)
assert_true(nx.is_isomorphic(G,S))
assert_equal(sorted(S.edges(data=True)),
[(0, 1, {'weight': 0.5}),
(0, 2, {'weight': 0.5})])
S=nx.stochastic_graph(G,copy=True)
assert_equal(sorted(S.edges(data=True)),
[(0, 1, {'weight': 0.5}),
(0, 2, {'weight': 0.5})])
示例2: test_stochastic_ints
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_stochastic_ints():
G=nx.DiGraph()
G.add_edge(0,1,weight=1)
G.add_edge(0,2,weight=1)
S=nx.stochastic_graph(G)
assert_equal(sorted(S.edges(data=True)),
[(0, 1, {'weight': 0.5}),
(0, 2, {'weight': 0.5})])
示例3: test_stochastic_graph_input
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_stochastic_graph_input():
S = nx.stochastic_graph(nx.Graph())
示例4: test_stochastic_multigraph_input
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_stochastic_multigraph_input():
S = nx.stochastic_graph(nx.MultiGraph())
示例5: test_default_weights
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_default_weights(self):
G = nx.DiGraph()
G.add_edge(0, 1)
G.add_edge(0, 2)
S = nx.stochastic_graph(G)
assert_true(nx.is_isomorphic(G, S))
assert_equal(sorted(S.edges(data=True)),
[(0, 1, {'weight': 0.5}), (0, 2, {'weight': 0.5})])
示例6: test_in_place
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_in_place(self):
"""Tests for an in-place reweighting of the edges of the graph.
"""
G = nx.DiGraph()
G.add_edge(0, 1, weight=1)
G.add_edge(0, 2, weight=1)
nx.stochastic_graph(G, copy=False)
assert_equal(sorted(G.edges(data=True)),
[(0, 1, {'weight': 0.5}), (0, 2, {'weight': 0.5})])
示例7: test_arbitrary_weights
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_arbitrary_weights(self):
G = nx.DiGraph()
G.add_edge(0, 1, weight=1)
G.add_edge(0, 2, weight=1)
S = nx.stochastic_graph(G)
assert_equal(sorted(S.edges(data=True)),
[(0, 1, {'weight': 0.5}), (0, 2, {'weight': 0.5})])
示例8: test_multidigraph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_multidigraph(self):
G = nx.MultiDiGraph()
G.add_edges_from([(0, 1), (0, 1), (0, 2), (0, 2)])
S = nx.stochastic_graph(G)
d = dict(weight=0.25)
assert_equal(sorted(S.edges(data=True)),
[(0, 1, d), (0, 1, d), (0, 2, d), (0, 2, d)])
示例9: test_graph_disallowed
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def test_graph_disallowed(self):
nx.stochastic_graph(nx.Graph())
示例10: pagerank_iterative
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import stochastic_graph [as 別名]
def pagerank_iterative(G, d=0.85, max_iter=100, tol=1.0e-6, weight='weight'):
"""
PageRank calculation iteratively
"""
# Step 1: Initiate PageRank
N = G.number_of_nodes() # N = 11
node_and_pr = dict.fromkeys(G, 1.0 / N)
# Step 2: Create a copy in (right) stochastic form
stochastic_graph = nx.stochastic_graph(G, weight=weight) # M = 1/L(pj)
# Step 3: Power iteration: make up to max_iter iterations
dangling_value = (1-d)/N
for _ in range(max_iter): # for each iteration
node_and_prev_pr = node_and_pr
node_and_pr = dict.fromkeys(node_and_prev_pr.keys(), 0)
for node in node_and_pr: # for each node
for out_node in stochastic_graph[node]: # node --> out_node
node_and_pr[out_node] += d * node_and_prev_pr[node] * stochastic_graph[node][out_node][weight] # PR(p_i) = d * PR(p_j)}/L(p_j)
node_and_pr[node] += dangling_value
# Plot graph with one iteration
'''
out_file = 'wikipedia_pagerank_example_iteration_1.pdf'
node_size = [pr*30000 for node, pr in node_and_pr.items()]
node_and_labels = {node : node+'\n'+str(round(pr, 3))
for node, pr in node_and_pr.items()}
plotnxgraph.plot_graph(G, out_file=out_file, node_size=node_size, node_and_labels=node_and_labels)
return
'''
# check convergence, l1 norm
err = sum([abs(node_and_pr[node] - node_and_prev_pr[node]) for node in node_and_pr])
if err < N*tol:
return node_and_pr
raise NetworkXError('pagerank: power iteration failed to converge in {} iterations.'.format(max_iter))