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


Python networkx.subgraph方法代码示例

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


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

示例1: avg_distance

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def avg_distance(graph, communities, **kwargs):
    """Average distance.

    The average distance of a community is defined average path length across all possible pair of nodes composing it.

    :param graph: a networkx/igraph object
    :param communities: NodeClustering object
    :param summary: boolean. If **True** it is returned an aggregated score for the partition is returned, otherwise individual-community ones. Default **True**.
    :return: If **summary==True** a FitnessResult object, otherwise a list of floats.

    Example:

    >>> from cdlib.algorithms import louvain
    >>> from cdlib import evaluation
    >>> g = nx.karate_club_graph()
    >>> communities = louvain(g)
    >>> scd = evaluation.avg_distance(g,communities)
    """

    return __quality_indexes(graph, communities,
                             lambda graph, coms: nx.average_shortest_path_length(nx.subgraph(graph, coms)), **kwargs) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:23,代码来源:fitness.py

示例2: _max_common_subgraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def _max_common_subgraph(GA, GB, pairings):
    matches = dict([(i, j) for i, j in enumerate(pairings)])
    node_ids = []
    for i, j in GA.edges():
        ii = matches[i]
        jj = matches[j]
        li = GA.node[i]['label']
        lii = GB.node[ii]['label']
        lj = GA.node[j]['label']
        ljj = GB.node[jj]['label']
        if ((ii, jj) in GB.edges() or (jj, ii) in GB.edges()) and li == lii and lj == ljj:
            node_ids.append(ii)
            node_ids.append(jj)
    G = nx.subgraph(GB, node_ids)
    cc = nx.connected_components(G)
    return cc, G 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:18,代码来源:__init__.py

示例3: _create_subgraph_plot

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def _create_subgraph_plot(event, dna_helix_graph: nx.DiGraph):
    mouseevent = event.mouseevent
    if not mouseevent.dblclick or mouseevent.button != 1:
        return

    logger = logging.getLogger(__name__)
    nucleotide_name = event.artist.get_label().split(":")[-1]
    nucleotide = _get_nucleotide_by_name(nucleotide_name, dna_helix_graph)
    logger.info("Create subgraph plot for %s", nucleotide_name)
    figure, subplot = _create_figure_with_subplot()
    figure.suptitle("Subgraph of nucleotide {}".format(nucleotide_name))

    nucleotide_with_neighbors_subgraph = _get_nucleotide_subgraph(
        dna_helix_graph, nucleotide)
    draw_dna_helix_on_subplot(
        nucleotide_with_neighbors_subgraph, subplot, verbosity=1)
    _draw_click_instructions(subplot, doubleclick=False)
    plt.draw()
    logger.info("Done!") 
开发者ID:audi,项目名称:nucleus7,代码行数:21,代码来源:vis_utils.py

示例4: _draw_click_instructions

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def _draw_click_instructions(subplot: plt_axes.Subplot,
                             doubleclick=True, singleclck=True):
    instruction_texts = list()
    instruction_texts.append("Interactive instructions:")
    if singleclck:
        instruction_texts.append(
            "Click once on nucleotide to see its information")
    if doubleclick:
        instruction_texts.append(
            "Make double clock on nucleotide to cut the subgraph with its "
            "incoming and outgoing nucleotides in new figure")

    instruction_text = "\n".join(instruction_texts)
    subplot.annotate(
        instruction_text, (0.5, 0.01), xycoords="figure fraction",
        ha="center", va="bottom", ma="left",
        bbox=dict(facecolor='white', edgecolor='blue', pad=5.0)) 
开发者ID:audi,项目名称:nucleus7,代码行数:19,代码来源:vis_utils.py

示例5: __quality_indexes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def __quality_indexes(graph, communities, scoring_function, summary=True):
    """

    :param graph: NetworkX/igraph graph
    :param communities: NodeClustering object
    :param summary: boolean. If **True** it is returned an aggregated score for the partition is returned, otherwise individual-communitys ones. Default **True**.
    :return: If **summary==True** a FitnessResult object, otherwise a list of floats.

    """

    graph = convert_graph_formats(graph, nx.Graph)
    values = []
    for com in communities.communities:
        community = nx.subgraph(graph, com)
        if scoring_function in [pq.PartitionQuality.average_internal_degree, pq.PartitionQuality.internal_edge_density,
                                pq.PartitionQuality.triangle_participation_ratio, pq.PartitionQuality.edges_inside,
                                pq.PartitionQuality.fraction_over_median_degree]:
            values.append(scoring_function(community))
        else:
            values.append(scoring_function(graph, community))

    if summary:
        return FitnessResult(min=min(values), max=max(values), score=np.mean(values), std=np.std(values))
    return values 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:26,代码来源:fitness.py

示例6: scaled_density

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def scaled_density(graph, communities, **kwargs):
    """Scaled density.

    The scaled density of a community is defined as the ratio of the community density w.r.t. the complete graph density.

    :param graph: a networkx/igraph object
    :param communities: NodeClustering object
    :param summary: boolean. If **True** it is returned an aggregated score for the partition is returned, otherwise individual-community ones. Default **True**.
    :return: If **summary==True** a FitnessResult object, otherwise a list of floats.

    Example:

    >>> from cdlib.algorithms import louvain
    >>> from cdlib import evaluation
    >>> g = nx.karate_club_graph()
    >>> communities = louvain(g)
    >>> scd = evaluation.scaled_density(g,communities)
    """

    return __quality_indexes(graph, communities,
                             lambda graph, coms: nx.density(nx.subgraph(graph, coms)) / nx.density(graph), **kwargs) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:23,代码来源:fitness.py

示例7: hub_dominance

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def hub_dominance(graph, communities, **kwargs):
    """Hub dominance.

    The hub dominance of a community is defined as the ratio of the degree of its most connected node w.r.t. the theoretically maximal degree within the community.

    :param graph: a networkx/igraph object
    :param communities: NodeClustering object
    :param summary: boolean. If **True** it is returned an aggregated score for the partition is returned, otherwise individual-community ones. Default **True**.
    :return: If **summary==True** a FitnessResult object, otherwise a list of floats.

    Example:

    >>> from cdlib.algorithms import louvain
    >>> from cdlib import evaluation
    >>> g = nx.karate_club_graph()
    >>> communities = louvain(g)
    >>> scd = evaluation.hub_dominance(g,communities)
    """

    return __quality_indexes(graph, communities,
                             lambda graph, coms: max([x[1] for x in
                                                      list(nx.degree(nx.subgraph(graph, coms)))]) / (len(coms) - 1),
                             **kwargs) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:25,代码来源:fitness.py

示例8: avg_transitivity

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def avg_transitivity(graph, communities, **kwargs):
    """Average transitivity.

    The average transitivity of a community is defined the as the average clustering coefficient of its nodes w.r.t. their connection within the community itself.

    :param graph: a networkx/igraph object
    :param communities: NodeClustering object
    :param summary: boolean. If **True** it is returned an aggregated score for the partition is returned, otherwise individual-community ones. Default **True**.
    :return: If **summary==True** a FitnessResult object, otherwise a list of floats.

    Example:

    >>> from cdlib.algorithms import louvain
    >>> from cdlib import evaluation
    >>> g = nx.karate_club_graph()
    >>> communities = louvain(g)
    >>> scd = evaluation.avg_transitivity(g,communities)
    """

    return __quality_indexes(graph, communities,
                             lambda graph, coms: nx.average_clustering(nx.subgraph(graph, coms)),
                             **kwargs) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:24,代码来源:fitness.py

示例9: test_multiple

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def test_multiple():
    # Verify that we can use the graph matcher multiple times
    edges = [('A','B'),('B','A'),('B','C')]
    for g1,g2 in [(nx.Graph(),nx.Graph()), (nx.DiGraph(),nx.DiGraph())]:
        g1.add_edges_from(edges)
        g2.add_edges_from(edges)
        g3 = nx.subgraph(g2, ['A','B'])
        if not g1.is_directed():
            gmA = iso.GraphMatcher(g1,g2)
            gmB = iso.GraphMatcher(g1,g3)
        else:
            gmA = iso.DiGraphMatcher(g1,g2)
            gmB = iso.DiGraphMatcher(g1,g3)
        assert_true(gmA.is_isomorphic())
        g2.remove_node('C')
        assert_true(gmA.subgraph_is_isomorphic())
        assert_true(gmB.subgraph_is_isomorphic())
#        for m in [gmB.mapping, gmB.mapping]:
#            assert_true(m['A'] == 'A')
#            assert_true(m['B'] == 'B')
#            assert_true('C' not in m) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:23,代码来源:test_isomorphvf2.py

示例10: test_multiple

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def test_multiple():
    # Verify that we can use the graph matcher multiple times
    edges = [('A', 'B'), ('B', 'A'), ('B', 'C')]
    for g1, g2 in [(nx.Graph(), nx.Graph()), (nx.DiGraph(), nx.DiGraph())]:
        g1.add_edges_from(edges)
        g2.add_edges_from(edges)
        g3 = nx.subgraph(g2, ['A', 'B'])
        if not g1.is_directed():
            gmA = iso.GraphMatcher(g1, g2)
            gmB = iso.GraphMatcher(g1, g3)
        else:
            gmA = iso.DiGraphMatcher(g1, g2)
            gmB = iso.DiGraphMatcher(g1, g3)
        assert_true(gmA.is_isomorphic())
        g2.remove_node('C')
        if not g1.is_directed():
            gmA = iso.GraphMatcher(g1, g2)
        else:
            gmA = iso.DiGraphMatcher(g1, g2)
        assert_true(gmA.subgraph_is_isomorphic())
        assert_true(gmB.subgraph_is_isomorphic())
#        for m in [gmB.mapping, gmB.mapping]:
#            assert_true(m['A'] == 'A')
#            assert_true(m['B'] == 'B')
#            assert_true('C' not in m) 
开发者ID:holzschu,项目名称:Carnets,代码行数:27,代码来源:test_isomorphvf2.py

示例11: max_common_subgraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def max_common_subgraph(GA, GB, pairings):
    cc, G = _max_common_subgraph(GA, GB, pairings)
    len_ccs = [(len(ci), ci) for ci in cc]
    if not len_ccs:
        return None
    n_cc, max_cc_ids = max(len_ccs)
    max_cc = nx.subgraph(G, max_cc_ids)
    return max_cc 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:10,代码来源:__init__.py

示例12: max_common_subgraphs

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def max_common_subgraphs(GA, GB, pairings):
    cc, G = _max_common_subgraph(GA, GB, pairings)
    cc_graphs = [nx.subgraph(G, ci) for ci in cc]
    return cc_graphs 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:6,代码来源:__init__.py

示例13: _get_nucleotide_subgraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def _get_nucleotide_subgraph(dna_helix_graph: nx.DiGraph, nucleotide):
    predecessors = list(dna_helix_graph.predecessors(nucleotide))
    successors = list(dna_helix_graph.successors(nucleotide))
    neighbors_with_nucleotide = predecessors + [nucleotide] + successors
    return nx.subgraph(dna_helix_graph, neighbors_with_nucleotide) 
开发者ID:audi,项目名称:nucleus7,代码行数:7,代码来源:vis_utils.py

示例14: filter_recipe_dag

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def filter_recipe_dag(dag, include, exclude):
    """Reduces **dag** to packages in **names** and their requirements"""
    nodes = set()
    for recipe in dag:
        if (recipe not in nodes
            and any(fnmatch(recipe.reldir, p) for p in include)
            and not any(fnmatch(recipe.reldir, p) for p in exclude)):
            nodes.add(recipe)
            nodes |= nx.ancestors(dag, recipe)
    return nx.subgraph(dag, nodes) 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:12,代码来源:graph.py

示例15: filter

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import subgraph [as 别名]
def filter(dag, packages):
    nodes = set()
    for package in packages:
        if package in nodes:
            continue  # already got all ancestors
        nodes.add(package)
        try:
            nodes |= nx.ancestors(dag, package)
        except nx.exception.NetworkXError:
            if package not in nx.nodes(dag):
                logger.error("Can't find %s in dag", package)
            else:
                raise

    return nx.subgraph(dag, nodes) 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:17,代码来源:graph.py


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