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


Python networkx.k_core方法代码示例

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


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

示例1: get_kcore_dict

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def get_kcore_dict(self,df):
        g = nx.Graph()
        g.add_nodes_from(df.qid1)
        edges = list(df[["qid1", "qid2"]].to_records(index=False))
        g.add_edges_from(edges)
        g.remove_edges_from(g.selfloop_edges())

        df_output = pd.DataFrame(data=list(g.nodes()), columns=["qid"])
        df_output["kcore"] = 0
        for k in range(2, self.NB_CORES + 1):
            ck = set(nx.k_core(g, k=k).nodes())
            print("kcore", k)
            df_output.ix[df_output.qid.isin(ck), "kcore"] = k

        return df_output.to_dict()["kcore"] 
开发者ID:lampts,项目名称:wsdm19cup,代码行数:17,代码来源:make_handcrafted_33_features.py

示例2: build_arbitrage_graph_for_exchanges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def build_arbitrage_graph_for_exchanges(exchanges: list):
    """
    This function is currently inefficient as it finds the entire graph for the given exchanges then finds the k-core
    for that graph. todo: It would be great if someone could improve the efficiency of it but this is not a priority.

    IMPORTANT: For this function to work, the @not_implemented_for('multigraph') decorator above the core_number
    function in networkx.algorithms.core.py must be removed or commented out.
    Todo: Improve this project so that the above does not have to be done.

    :param exchanges: A list of exchanges (e.g. ['bittrex', 'poloniex', 'bitstamp', 'gdax']
    """
    return nx.k_core(build_multi_graph_for_exchanges(exchanges), 2) 
开发者ID:wardbradt,项目名称:peregrine,代码行数:14,代码来源:multi_graph_builder.py

示例3: get_kcore_dict

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def get_kcore_dict(df):
    g = nx.Graph()
    g.add_nodes_from(df.qid1)
    edges = list(df[["qid1", "qid2"]].to_records(index=False))
    g.add_edges_from(edges)
    g.remove_edges_from(g.selfloop_edges())

    df_output = pd.DataFrame(data=g.nodes(), columns=["qid"])
    df_output["kcore"] = 0
    for k in range(2, NB_CORES + 1):
        ck = nx.k_core(g, k=k).nodes()
        print("kcore", k)
        df_output.ix[df_output.qid.isin(ck), "kcore"] = k

    return df_output.to_dict()["kcore"] 
开发者ID:aerdem4,项目名称:kaggle-quora-dup,代码行数:17,代码来源:non_nlp_feature_extraction.py

示例4: test_main_core

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def test_main_core(self):
        main_core_subgraph=nx.k_core(self.H)
        assert_equal(sorted(main_core_subgraph.nodes()),[2,4,5,6]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_core.py

示例5: test_k_core

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def test_k_core(self):
        # k=0
        k_core_subgraph=nx.k_core(self.H,k=0)
        assert_equal(sorted(k_core_subgraph.nodes()),sorted(self.H.nodes()))
        # k=1
        k_core_subgraph=nx.k_core(self.H,k=1)
        assert_equal(sorted(k_core_subgraph.nodes()),[1,2,3,4,5,6])
        # k=2
        k_core_subgraph=nx.k_core(self.H,k=2)
        assert_equal(sorted(k_core_subgraph.nodes()),[2,4,5,6]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:12,代码来源:test_core.py

示例6: _cliques_heuristic

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def _cliques_heuristic(G, H, k, min_density):
    h_cnumber = nx.core_number(H)
    for i, c_value in enumerate(sorted(set(h_cnumber.values()), reverse=True)):
        cands = set(n for n, c in h_cnumber.items() if c == c_value)
        # Skip checking for overlap for the highest core value
        if i == 0:
            overlap = False
        else:
            overlap = set.intersection(*[
                        set(x for x in H[n] if x not in cands)
                        for n in cands])
        if overlap and len(overlap) < k:
            SH = H.subgraph(cands | overlap)
        else:
            SH = H.subgraph(cands)
        sh_cnumber = nx.core_number(SH)
        SG = nx.k_core(G.subgraph(SH), k)
        while not (_same(sh_cnumber) and nx.density(SH) >= min_density):
            SH = H.subgraph(SG)
            if len(SH) <= k:
                break
            sh_cnumber = nx.core_number(SH)
            sh_deg = SH.degree()
            min_deg = min(sh_deg.values())
            SH.remove_nodes_from(n for n, d in sh_deg.items() if d == min_deg)
            SG = nx.k_core(G.subgraph(SH), k)
        else:
            yield SG 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:30,代码来源:kcomponents.py

示例7: test_main_core

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def test_main_core(self):
        main_core_subgraph = nx.k_core(self.H)
        assert_equal(sorted(main_core_subgraph.nodes()), [2, 4, 5, 6]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_core.py

示例8: test_k_core

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def test_k_core(self):
        # k=0
        k_core_subgraph = nx.k_core(self.H, k=0)
        assert_equal(sorted(k_core_subgraph.nodes()), sorted(self.H.nodes()))
        # k=1
        k_core_subgraph = nx.k_core(self.H, k=1)
        assert_equal(sorted(k_core_subgraph.nodes()), [1, 2, 3, 4, 5, 6])
        # k = 2
        k_core_subgraph = nx.k_core(self.H, k=2)
        assert_equal(sorted(k_core_subgraph.nodes()), [2, 4, 5, 6]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:12,代码来源:test_core.py

示例9: _cliques_heuristic

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import k_core [as 别名]
def _cliques_heuristic(G, H, k, min_density):
    h_cnumber = nx.core_number(H)
    for i, c_value in enumerate(sorted(set(h_cnumber.values()), reverse=True)):
        cands = set(n for n, c in h_cnumber.items() if c == c_value)
        # Skip checking for overlap for the highest core value
        if i == 0:
            overlap = False
        else:
            overlap = set.intersection(*[
                set(x for x in H[n] if x not in cands)
                for n in cands])
        if overlap and len(overlap) < k:
            SH = H.subgraph(cands | overlap)
        else:
            SH = H.subgraph(cands)
        sh_cnumber = nx.core_number(SH)
        SG = nx.k_core(G.subgraph(SH), k)
        while not (_same(sh_cnumber) and nx.density(SH) >= min_density):
            #!! This subgraph must be writable => .copy()
            SH = H.subgraph(SG).copy()
            if len(SH) <= k:
                break
            sh_cnumber = nx.core_number(SH)
            sh_deg = dict(SH.degree())
            min_deg = min(sh_deg.values())
            SH.remove_nodes_from(n for n, d in sh_deg.items() if d == min_deg)
            SG = nx.k_core(G.subgraph(SH), k)
        else:
            yield SG 
开发者ID:holzschu,项目名称:Carnets,代码行数:31,代码来源:kcomponents.py


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