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


Python DiGraph.to_undirected方法代码示例

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


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

示例1: network_properties

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import to_undirected [as 别名]
def network_properties(network : nx.DiGraph,
                       in_degree_threshold : float = -1,
                       pagerank_threshold : float = -1,
                       damping : float = 0.85,
                       spectral_offset : float = 0.5)\
        -> (pd.DataFrame, sparse.spmatrix):
    conn = max(nx.connected_components(network.to_undirected()), key=len)
    conn = nx.subgraph(network, conn)
    pr = compute_pagerank(conn, damping=damping)
    names = nx.nodes(conn)
    indeg = [conn.in_degree(n) for n in names]
    odeg = [conn.out_degree(n) for n in names]
    description = [conn.node[n].get('description', n) for n in names]
    x, y, z, Adj, aff_names = node_coordinates(conn, nodelist=names,
                                               offset=spectral_offset)
    data = {'id': names,
            'in_degree': indeg,
            'out_degree': odeg,
            'pagerank': pr,
            'affinity_x': x,
            'affinity_y': y,
            'processing_depth': z,
            'description': description}
    df = pd.DataFrame(data, index=names)
    df = df[df['pagerank'] > pagerank_threshold / len(names)]
    df = df[df['in_degree'] > in_degree_threshold]
    return df, Adj
开发者ID:jni,项目名称:prin,代码行数:29,代码来源:plot.py

示例2: __getitem__

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import to_undirected [as 别名]
    def __getitem__(self, n):
        """Get clustering status after `n` iterations

        Parameters
        ----------
        n : int
            Number of iterations

        Returns
        -------
        annotation : Annotation
            Clustering status after `n` iterations

        """

        # support for history[-1], history[-2]
        # i = -1 ==> after last iteration
        # i = -2 ==> after penultimate iteration
        # ... etc ...
        if n < 0:
            n = len(self) + 1 + n

        # dendrogram stored as directed graph
        # cluster1 --> cluster2 means cluster1 was merged into cluster2
        g = DiGraph()

        # i = 0 ==> starting point
        # i = 1 ==> after first iteration
        # i = 2 ==> aftr second iterations
        # ... etc ...

        for i, iteration in enumerate(self.iterations):
            if i+1 > n:
                break
            for cluster in iteration.merge:
                if cluster == iteration.into:
                    continue
                g.add_edge(cluster, iteration.into)

        # any cluster is mapped to the last cluster in its topologically
        # ordered connected component
        mapping = {}
        for clusters in connected_components(g.to_undirected()):
            clusters = topological_sort(g, nbunch=clusters, reverse=True)
            for cluster in clusters[1:]:
                mapping[cluster] = clusters[0]

        # actual mapping
        return self.starting_point.translate(mapping)
开发者ID:pyannote,项目名称:pyannote-algorithms,代码行数:51,代码来源:history.py


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