本文整理匯總了Python中networkx.eigenvector_centrality_numpy方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.eigenvector_centrality_numpy方法的具體用法?Python networkx.eigenvector_centrality_numpy怎麽用?Python networkx.eigenvector_centrality_numpy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.eigenvector_centrality_numpy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_K5
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_K5(self):
"""Eigenvector centrality: K5"""
G=networkx.complete_graph(5)
b=networkx.eigenvector_centrality(G)
v=math.sqrt(1/5.0)
b_answer=dict.fromkeys(G,v)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
nstart = dict([(n,1) for n in G])
b=networkx.eigenvector_centrality(G,nstart=nstart)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
b=networkx.eigenvector_centrality_numpy(G)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n],places=3)
示例2: baseline_eigencentrality_top_flips
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def baseline_eigencentrality_top_flips(adj_matrix, candidates, n_flips):
"""Selects the top (n_flips) number of flips using eigencentrality score of the edges.
Applicable only when removing edges.
:param adj_matrix: sp.spmatrix
The graph represented as a sparse scipy matrix
:param candidates: np.ndarray, shape [?, 2]
Candidate set of edge flips
:param n_flips: int
Number of flips to select
:return: np.ndarray, shape [?, 2]
The top edge flips from the candidate set
"""
edges = np.column_stack(sp.triu(adj_matrix, 1).nonzero())
line_graph = construct_line_graph(adj_matrix)
eigcentrality_scores = nx.eigenvector_centrality_numpy(nx.Graph(line_graph))
eigcentrality_scores = {tuple(edges[k]): eigcentrality_scores[k] for k, v in eigcentrality_scores.items()}
eigcentrality_scores = np.array([eigcentrality_scores[tuple(cnd)] for cnd in candidates])
scores_argsrt = eigcentrality_scores.argsort()
return candidates[scores_argsrt[-n_flips:]]
示例3: test_K5
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_K5(self):
"""Eigenvector centrality: K5"""
G = nx.complete_graph(5)
b = nx.eigenvector_centrality(G)
v = math.sqrt(1 / 5.0)
b_answer = dict.fromkeys(G, v)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n])
nstart = dict([(n, 1) for n in G])
b = nx.eigenvector_centrality(G, nstart=nstart)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n])
b = nx.eigenvector_centrality_numpy(G)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n], places=3)
示例4: test_K5
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_K5(self):
"""Eigenvector centrality: K5"""
G=nx.complete_graph(5)
b=nx.eigenvector_centrality(G)
v=math.sqrt(1/5.0)
b_answer=dict.fromkeys(G,v)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
nstart = dict([(n,1) for n in G])
b=nx.eigenvector_centrality(G,nstart=nstart)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
b=nx.eigenvector_centrality_numpy(G)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n],places=3)
示例5: test_P3
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_P3(self):
"""Eigenvector centrality: P3"""
G=networkx.path_graph(3)
b_answer={0: 0.5, 1: 0.7071, 2: 0.5}
b=networkx.eigenvector_centrality_numpy(G)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n],places=4)
示例6: test_P3_unweighted
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_P3_unweighted(self):
"""Eigenvector centrality: P3"""
G=networkx.path_graph(3)
b_answer={0: 0.5, 1: 0.7071, 2: 0.5}
b=networkx.eigenvector_centrality_numpy(G, weight=None)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n],places=4)
示例7: test_eigenvector_centrality_weighted_numpy
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_eigenvector_centrality_weighted_numpy(self):
G=self.G
p=networkx.eigenvector_centrality_numpy(G)
for (a,b) in zip(list(p.values()),self.G.evc):
assert_almost_equal(a,b)
示例8: test_eigenvector_centrality_unweighted_numpy
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_eigenvector_centrality_unweighted_numpy(self):
G=self.H
p=networkx.eigenvector_centrality_numpy(G)
for (a,b) in zip(list(p.values()),self.G.evc):
assert_almost_equal(a,b)
示例9: test_empty_numpy
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_empty_numpy(self):
e = networkx.eigenvector_centrality_numpy(networkx.Graph())
示例10: test_K5
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_K5(self):
"""Katz centrality: K5"""
G = networkx.complete_graph(5)
alpha = 0.1
b = networkx.katz_centrality(G, alpha)
v = math.sqrt(1 / 5.0)
b_answer = dict.fromkeys(G, v)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n])
nstart = dict([(n, 1) for n in G])
b = networkx.eigenvector_centrality_numpy(G)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n], places=3)
示例11: test_K5_unweighted
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_K5_unweighted(self):
"""Katz centrality: K5"""
G = networkx.complete_graph(5)
alpha = 0.1
b = networkx.katz_centrality(G, alpha, weight=None)
v = math.sqrt(1 / 5.0)
b_answer = dict.fromkeys(G, v)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n])
nstart = dict([(n, 1) for n in G])
b = networkx.eigenvector_centrality_numpy(G)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n], places=3)
示例12: test_eigenvector_v_katz_random
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_eigenvector_v_katz_random(self):
G = networkx.gnp_random_graph(10,0.5, seed=1234)
l = float(max(eigvals(networkx.adjacency_matrix(G).todense())))
e = networkx.eigenvector_centrality_numpy(G)
k = networkx.katz_centrality_numpy(G, 1.0/l)
for n in G:
assert_almost_equal(e[n], k[n])
示例13: test_P3
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_P3(self):
"""Eigenvector centrality: P3"""
G = nx.path_graph(3)
b_answer = {0: 0.5, 1: 0.7071, 2: 0.5}
b = nx.eigenvector_centrality_numpy(G)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n], places=4)
b = nx.eigenvector_centrality(G)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n], places=4)
示例14: test_P3_unweighted
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_P3_unweighted(self):
"""Eigenvector centrality: P3"""
G = nx.path_graph(3)
b_answer = {0: 0.5, 1: 0.7071, 2: 0.5}
b = nx.eigenvector_centrality_numpy(G, weight=None)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n], places=4)
示例15: test_eigenvector_centrality_weighted_numpy
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import eigenvector_centrality_numpy [as 別名]
def test_eigenvector_centrality_weighted_numpy(self):
G = self.G
p = nx.eigenvector_centrality_numpy(G)
for (a, b) in zip(list(p.values()), self.G.evc):
assert_almost_equal(a, b)