本文整理汇总了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))