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


Python networkx.eigenvector_centrality方法代码示例

本文整理汇总了Python中networkx.eigenvector_centrality方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.eigenvector_centrality方法的具体用法?Python networkx.eigenvector_centrality怎么用?Python networkx.eigenvector_centrality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.eigenvector_centrality方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_K5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [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: _calc_graph_func

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def _calc_graph_func(p):
    con, times_chunk, graph_func = p
    vals = []
    now = time.time()
    for run, t in enumerate(times_chunk):
        utils.time_to_go(now, run, len(times_chunk), 10)
        con_t = con[:, :, t]
        g = nx.from_numpy_matrix(con_t)
        if graph_func == 'closeness_centrality':
            x = nx.closeness_centrality(g)
        elif graph_func == 'degree_centrality':
            x = nx.degree_centrality(g)
        elif graph_func == 'eigenvector_centrality':
            x = nx.eigenvector_centrality(g, max_iter=10000)
        elif graph_func == 'katz_centrality':
            x = nx.katz_centrality(g, max_iter=100000)
        else:
            raise Exception('Wrong graph func!')
        vals.append([x[k] for k in range(len(x))])
    vals = np.array(vals)
    return vals, times_chunk 
开发者ID:pelednoam,项目名称:mmvt,代码行数:23,代码来源:analyse_meg_epilepsy_clips.py

示例3: test_K5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [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 [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_interact_with_env_replicable_randomagent

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_interact_with_env_replicable_randomagent(self):
    graph = nx.karate_club_graph()
    centrality = nx.eigenvector_centrality(graph)
    sorted_nodes = sorted(
        centrality.keys(), key=lambda k: centrality[k], reverse=True)
    # Infect the 3rd through 5th most central people.
    initial_health_state = [
        1 if index in sorted_nodes[3:6] else 0
        for index in range(len(sorted_nodes))
    ]
    env, agent, _ = set_up_and_observe(
        population_graph=graph,
        initial_health_state=initial_health_state,
        agent_class=infectious_disease_agents.RandomAgent)
    test_util.run_test_simulation(env=env, agent=agent) 
开发者ID:google,项目名称:ml-fairness-gym,代码行数:17,代码来源:infectious_disease_agents_test.py

示例6: test_interact_with_env_replicable_centralityagent

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_interact_with_env_replicable_centralityagent(self):
    graph = nx.karate_club_graph()
    centrality = nx.eigenvector_centrality(graph)
    sorted_nodes = sorted(
        centrality.keys(), key=lambda k: centrality[k], reverse=True)
    # Infect the 3rd through 5th most central people.
    initial_health_state = [
        1 if index in sorted_nodes[3:6] else 0
        for index in range(len(sorted_nodes))
    ]
    env, agent, _ = set_up_and_observe(
        population_graph=graph,
        initial_health_state=initial_health_state,
        agent_class=infectious_disease_agents.CentralityAgent)
    test_util.run_test_simulation(env=env, agent=agent) 
开发者ID:google,项目名称:ml-fairness-gym,代码行数:17,代码来源:infectious_disease_agents_test.py

示例7: test_centrality_treatment_ordering_correct

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_centrality_treatment_ordering_correct(self):
    # Initialize a small example graph and sort nodes by their centrality.
    graph = nx.karate_club_graph()
    centrality = nx.eigenvector_centrality(graph)
    sorted_nodes = sorted(
        centrality.keys(),
        key=lambda k: centrality[k],
        reverse=True)

    # Infect the 3rd through 5th most central people.  We expect these people to
    # be the 1st through 3rd people to receive treatment.
    initial_health_state = [
        1 if index in sorted_nodes[3:6] else 0
        for index in range(len(sorted_nodes))]

    # Initialize an environment with that initial health state and a centrality
    # agent.
    env, agent = instantiate_environment_and_agent(
        agent_class=infectious_disease_agents.CentralityAgent,
        population_graph=graph,
        initial_health_state=initial_health_state)

    # Confirm that the infected people are sorted by centrality in the agent's
    # action.  We expect 3rd the through 5th most central people to be the 1st
    # through 3rd people to receive treatment.
    observation = env._get_observable_state()
    action = agent.act(observation, False)
    self.assertEqual(sorted_nodes[3:6], action[:3].tolist()) 
开发者ID:google,项目名称:ml-fairness-gym,代码行数:30,代码来源:infectious_disease_agents_test.py

示例8: _triage

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def _triage(self, observation):
    """Returns person indices ordered from first to last person to treat.

    Infected people are prioritized above non-infected people, and infected
    people are ranked according to their centrality in the contact graph.

    Args:
      observation: An observation from a Dict Space with 'health_states' and
        'population_graph' keys.  The 'health_states' observation contains the
        health states of the population, and the 'population_graph' observation
        contains the contact graph over which disease spreads.

    Returns:
      A numpy array of population indices representing the triage order.
    """
    infections = _infection_indicator(
        observation['health_states'], self.initial_params.infectious_index)
    centrality = nx.eigenvector_centrality(observation['population_graph'])

    # Negate because lower scores are treated first. Note that centrality is a
    # dict that maps from node-keys to centrality values, and it happens
    # that the node keys are zero-counted contiguouos integers, which is
    # required for the following enumeration-based indexing to work out.  This
    # condition is checked by the assertion immediately below.
    assert list(
        observation['population_graph'].nodes()) == list(
            range(observation['population_graph'].number_of_nodes()))
    triage_scores = np.array([
        -infection * centrality[i] for i, infection in enumerate(infections)])

    max_treatments = len(self.action_space.nvec)
    return np.argsort(triage_scores)[:max_treatments] 
开发者ID:google,项目名称:ml-fairness-gym,代码行数:34,代码来源:infectious_disease_agents.py

示例9: test_maxiter

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_maxiter(self):
        G=networkx.path_graph(3)
        b=networkx.eigenvector_centrality(G,max_iter=0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_eigenvector_centrality.py

示例10: test_eigenvector_centrality_weighted

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_eigenvector_centrality_weighted(self):
        G=self.G
        p=networkx.eigenvector_centrality(G)
        for (a,b) in zip(list(p.values()),self.G.evc):
            assert_almost_equal(a,b,places=4) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_eigenvector_centrality.py

示例11: test_eigenvector_centrality_unweighted

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_eigenvector_centrality_unweighted(self):
        G=self.H
        p=networkx.eigenvector_centrality(G)
        for (a,b) in zip(list(p.values()),self.G.evc):
            assert_almost_equal(a,b,places=4) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_eigenvector_centrality.py

示例12: test_multigraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_multigraph(self):
        e = networkx.eigenvector_centrality(networkx.MultiGraph()) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:4,代码来源:test_eigenvector_centrality.py

示例13: test_P3

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [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_maxiter

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_maxiter(self):
        G = nx.path_graph(3)
        b = nx.eigenvector_centrality(G, max_iter=0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_eigenvector_centrality.py

示例15: test_eigenvector_centrality_weighted

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import eigenvector_centrality [as 别名]
def test_eigenvector_centrality_weighted(self):
        G = self.G
        p = nx.eigenvector_centrality(G)
        for (a, b) in zip(list(p.values()), self.G.evc):
            assert_almost_equal(a, b, places=4) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_eigenvector_centrality.py


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