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


Python networkx.weakly_connected_components方法代码示例

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


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

示例1: plot_wcc_distribution

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def plot_wcc_distribution(_g, _plot_img):
    """Plot weakly connected components size distributions
    :param _g: Transaction graph
    :param _plot_img: WCC size distribution image (log-log plot)
    :return:
    """
    all_wcc = nx.weakly_connected_components(_g)
    wcc_sizes = Counter([len(wcc) for wcc in all_wcc])
    size_seq = sorted(wcc_sizes.keys())
    size_hist = [wcc_sizes[x] for x in size_seq]

    plt.figure(figsize=(16, 12))
    plt.clf()
    plt.loglog(size_seq, size_hist, 'ro-')
    plt.title("WCC Size Distribution")
    plt.xlabel("Size")
    plt.ylabel("Number of WCCs")
    plt.savefig(_plot_img) 
开发者ID:IBM,项目名称:AMLSim,代码行数:20,代码来源:plot_distributions.py

示例2: left_outer_join

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def left_outer_join(g, h) -> None:
    """Only add components from the ``h`` that are touching ``g``.

    Algorithm:

    1. Identify all weakly connected components in ``h``
    2. Add those that have an intersection with the ``g``

    :param BELGraph g: A BEL graph
    :param BELGraph h: A BEL graph

    Example usage:

    >>> import pybel
    >>> g = pybel.from_bel_script('...')
    >>> h = pybel.from_bel_script('...')
    >>> left_outer_join(g, h)
    """
    g_nodes = set(g)
    for comp in nx.weakly_connected_components(h):
        if g_nodes.intersection(comp):
            h_subgraph = subgraph(h, comp)
            left_full_join(g, h_subgraph) 
开发者ID:pybel,项目名称:pybel,代码行数:25,代码来源:operations.py

示例3: number_weakly_connected_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def number_weakly_connected_components(G):
    """Return the number of weakly connected components in G.

    Parameters
    ----------
    G : NetworkX graph
        A directed graph.

    Returns
    -------
    n : integer
        Number of weakly connected components

    See Also
    --------
    connected_components

    Notes
    -----
    For directed graphs only.

    """
    return len(list(weakly_connected_components(G))) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:25,代码来源:weakly_connected.py

示例4: get_largest_component

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def get_largest_component(graph: BELGraph) -> BELGraph:
    """Get the giant component of a graph.

    :param graph: A BEL graph
    """
    biggest_component_nodes = max(nx.weakly_connected_components(graph), key=len)
    return subgraph(graph, biggest_component_nodes) 
开发者ID:pybel,项目名称:pybel,代码行数:9,代码来源:utils.py

示例5: getNetProp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def getNetProp(inGraph):
    '''
    Function to compute properties
    of a given network.
    '''

    # number of weakly connected components in 
    # reference network
    numCC = len(list(nx.weakly_connected_components(inGraph)))
    
    # number of feedback loop 
    # in reference network
    allCyc = nx.simple_cycles(inGraph)
    cycSet = set()
    for cyc in allCyc:
        if len(cyc) == 3:
            cycSet.add(frozenset(cyc))
    
    numFB = len(cycSet)
    
    # number of feedfwd loops
    # in reference network
    allPaths = []
    allPathsSet = set()   
    for u,v in inGraph.edges():
        allPaths = nx.all_simple_paths(inGraph, u, v, cutoff=2)
        for p in allPaths:
            if len(p) >  2:
                allPathsSet.add(frozenset(p))
                
    numFF= len(allPathsSet)
    
    
    # number of mutual interactions
    numMI = 0.0
    for u,v in inGraph.edges():
        if (v,u) in inGraph.edges():
            numMI += 0.5

    return numCC, numFB, numFF, numMI 
开发者ID:Murali-group,项目名称:Beeline,代码行数:42,代码来源:computePathStats.py

示例6: _remove_non_return_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def _remove_non_return_edges(self):
        """
        Remove those return_from_call edges that actually do not return due to
        calling some not-returning functions.
        :return: None
        """
        for func in self.kb.functions.values():
            graph = func.transition_graph
            all_return_edges = [(u, v) for (u, v, data) in graph.edges(data=True) if data['type'] == 'return_from_call']
            for return_from_call_edge in all_return_edges:
                callsite_block_addr, return_to_addr = return_from_call_edge
                call_func_addr = func.get_call_target(callsite_block_addr)
                if call_func_addr is None:
                    continue

                call_func = self.kb.functions.function(call_func_addr)
                if call_func is None:
                    # Weird...
                    continue

                if call_func.returning is False:
                    # Remove that edge!
                    graph.remove_edge(call_func_addr, return_to_addr)
                    # Remove the edge in CFG
                    nodes = self.get_all_nodes(callsite_block_addr)
                    for n in nodes:
                        successors = self.get_successors_and_jumpkind(n, excluding_fakeret=False)
                        for successor, jumpkind in successors:
                            if jumpkind == 'Ijk_FakeRet' and successor.addr == return_to_addr:
                                self.remove_edge(n, successor)

                                # Remove all dangling nodes
                                # wcc = list(networkx.weakly_connected_components(graph))
                                # for nodes in wcc:
                                #    if func.startpoint not in nodes:
                                #        graph.remove_nodes_from(nodes)

    # Private methods - resolving indirect jumps 
开发者ID:angr,项目名称:angr,代码行数:40,代码来源:cfg_emulated.py

示例7: nodes_disconnected_from

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def nodes_disconnected_from(self, node_id):
        """Find nodes disconnected from the input node."""
        components = nx.weakly_connected_components(
            self._graph)

        disconnected_components = []
        for comp in components:
            if node_id not in comp:
                disconnected_components.append(comp)
        return set([
            n
            for comp in disconnected_components
            for n in comp
        ]) 
开发者ID:Kappa-Dev,项目名称:ReGraph,代码行数:16,代码来源:graphs.py

示例8: separate_disconnected_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def separate_disconnected_components(self, sort=False):
        """Separate disconnected components into distinct ScaffoldGraph objects.

        Parameters
        ----------
        sort : (bool, optional (default=False)) If True sort components in descending order according
            to the number of nodes in the subgraph.
        """
        components = []
        for c in nx.weakly_connected_components(self):
            components.append(self.subgraph(c).copy())
        if sort:
            return sorted(components, key=len, reverse=True)
        return components 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:16,代码来源:graph.py

示例9: biggest_connected_subgraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def biggest_connected_subgraph(G):
    if G.is_directed():
        comps = nx.weakly_connected_components(G)
    else:
        comps = nx.connected_components(G)
    biggest = max(comps, key=len)
    return G.subgraph(biggest) 
开发者ID:mattbierbaum,项目名称:arxiv-public-datasets,代码行数:9,代码来源:intra_citation.py

示例10: is_weakly_connected

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def is_weakly_connected(G):
    """Test directed graph for weak connectivity.

    A directed graph is weakly connected if, and only if, the graph
    is connected when the direction of the edge between nodes is ignored.

    Parameters
    ----------
    G : NetworkX Graph
        A directed graph.

    Returns
    -------
    connected : bool
        True if the graph is weakly connected, False otherwise.

    See Also
    --------
    is_strongly_connected
    is_semiconnected
    is_connected

    Notes
    -----
    For directed graphs only.

    """
    if len(G) == 0:
        raise nx.NetworkXPointlessConcept(
            """Connectivity is undefined for the null graph.""")

    return len(list(weakly_connected_components(G))[0]) == len(G) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:34,代码来源:weakly_connected.py

示例11: test_weakly_connected_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def test_weakly_connected_components(self):
        for G, C in self.gc:
            U = G.to_undirected()
            w = {frozenset(g) for g in nx.weakly_connected_components(G)}
            c = {frozenset(g) for g in nx.connected_components(U)}
            assert_equal(w, c) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:8,代码来源:test_weakly_connected.py

示例12: connected_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def connected_components(self):
        if not self.directed:
            return nx.connected_components(self.__graph)
        else:
            return nx.weakly_connected_components(self.__graph) 
开发者ID:funkey,项目名称:gunpowder,代码行数:7,代码来源:graph.py

示例13: number_weakly_connected_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def number_weakly_connected_components(G):
    """Returns the number of weakly connected components in G.

    Parameters
    ----------
    G : NetworkX graph
        A directed graph.

    Returns
    -------
    n : integer
        Number of weakly connected components

    Raises
    ------
    NetworkXNotImplemented:
        If G is undirected.

    See Also
    --------
    weakly_connected_components
    number_connected_components
    number_strongly_connected_components

    Notes
    -----
    For directed graphs only.

    """
    return sum(1 for wcc in weakly_connected_components(G)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:32,代码来源:weakly_connected.py

示例14: weakly_connected_component_subgraphs

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def weakly_connected_component_subgraphs(G, copy=True):
    """DEPRECATED: Use ``(G.subgraph(c) for c in weakly_connected_components(G))``

           Or ``(G.subgraph(c).copy() for c in weakly_connected_components(G))``
    """
    msg = "weakly_connected_component_subgraphs is deprecated and will be removed in 2.2" \
        "use (G.subgraph(c).copy() for c in weakly_connected_components(G))"
    _warnings.warn(msg, DeprecationWarning)
    for c in weakly_connected_components(G):
        if copy:
            yield G.subgraph(c).copy()
        else:
            yield G.subgraph(c) 
开发者ID:holzschu,项目名称:Carnets,代码行数:15,代码来源:weakly_connected.py

示例15: test_connected_raise

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import weakly_connected_components [as 别名]
def test_connected_raise(self):
        G = nx.Graph()
        assert_raises(NetworkXNotImplemented, nx.weakly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.number_weakly_connected_components, G)
        assert_raises(NetworkXNotImplemented, nx.is_weakly_connected, G)
        # deprecated
        assert_raises(NetworkXNotImplemented, nx.weakly_connected_component_subgraphs, G) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_weakly_connected.py


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