当前位置: 首页>>代码示例>>Python>>正文


Python networkx.stochastic_graph方法代码示例

本文整理汇总了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})]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:15,代码来源:test_stochastic.py

示例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})]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_stochastic.py

示例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()) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:4,代码来源:test_stochastic.py

示例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()) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:4,代码来源:test_stochastic.py

示例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})]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_stochastic.py

示例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})]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:12,代码来源:test_stochastic.py

示例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})]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_stochastic.py

示例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)]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_stochastic.py

示例9: test_graph_disallowed

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import stochastic_graph [as 别名]
def test_graph_disallowed(self):
        nx.stochastic_graph(nx.Graph()) 
开发者ID:holzschu,项目名称:Carnets,代码行数:4,代码来源:test_stochastic.py

示例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)) 
开发者ID:sparkandshine,项目名称:complex_network,代码行数:44,代码来源:pagerank_iterative.py


注:本文中的networkx.stochastic_graph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。