當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。