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


Python networkx.eigenvector_centrality_numpy方法代码示例

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

示例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:]] 
开发者ID:abojchevski,项目名称:node_embedding_attack,代码行数:24,代码来源:perturbation_attack.py

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

示例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) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:19,代码来源:test_eigenvector_centrality.py

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

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

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

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

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

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

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

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

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

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

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


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