python(和networkx)最快的forceatlas2算法

fa2的Python项目详细描述


python的forceatlas2

gephi的force atlas 2布局算法到python 2和python 3的端口(带有networkx和igraph的包装)。这是最快的python实现,大多数功能都已完成。它还支持巴尼斯HUT近似最大加速。

forceatlas2是一种非常快速的有向图布局算法。它用于在二维空间化一个加权无向图(边权重定义连接的强度)。实现基于这个paper和相应的gephi-java-code。与NetworkX的Fruchterman Reingold算法(Spring布局)相比,它的速度非常快,并且可以很好地扩展到大量节点(10000个节点)。

将随机几何图形空间化

Geometric Graph

安装

从PIP安装:

pip install fa2

要生成和安装,请从源代码运行:

python setup.py install

cython是强烈推荐的,如果您是从源代码构建的,因为它将根据图表加速10-100倍

依赖性

  • numpy(邻接矩阵作为完整矩阵)
  • scipy(邻接矩阵作为稀疏矩阵)
  • TQM(进度条)
  • cython(10-100倍加速)
  • networkx(要使用networkx包装函数,显然需要networkx)
  • python igraph(使用igraph包装)

将二维网格空间化

Grid Graph

用法

来自FA2导入力LAS2

使用适当的设置创建ForceAtlas2对象。forceAtlas2类包含三个重要方法:

forceatlas2(G,pos,iterations)# G is a graph in 2D numpy ndarray format (or) scipy sparse matrix format. You can set the edge weights (> 0) in the matrix# pos is a numpy array (Nx2) of initial positions of nodes# iterations is num of iterations to run the algorithm# returns a list of (x,y) pairs for each node's final position
forceatlas2_networkx_layout(G,pos,iterations)# G is a networkx graph. Edge weights can be set (if required) in the Networkx graph# pos is a dictionary, as in networkx# iterations is num of iterations to run the algorithm# returns a dictionary of node positions (2D X-Y tuples) indexed by the node name
forceatlas2_igraph_layout(G,pos,iterations,weight_attr)# G is an igraph graph# pos is a numpy array (Nx2) or list of initial positions of nodes (see that the indexing matches igraph node index)# iterations is num of iterations to run the algorithm# weight_attr denotes the weight attribute's name in G.es, None by default# returns an igraph layout

下面是一个使用示例。您还可以看到forceatlas2类的功能设置。

importnetworkxasnxfromfa2importForceAtlas2importmatplotlib.pyplotaspltG=nx.random_geometric_graph(400,0.2)forceatlas2=ForceAtlas2(# Behavior alternativesoutboundAttractionDistribution=True,# Dissuade hubslinLogMode=False,# NOT IMPLEMENTEDadjustSizes=False,# Prevent overlap (NOT IMPLEMENTED)edgeWeightInfluence=1.0,# PerformancejitterTolerance=1.0,# TolerancebarnesHutOptimize=True,barnesHutTheta=1.2,multiThreaded=False,# NOT IMPLEMENTED# TuningscalingRatio=2.0,strongGravityMode=False,gravity=1.0,# Logverbose=True)positions=forceatlas2.forceatlas2_networkx_layout(G,pos=None,iterations=2000)nx.draw_networkx_nodes(G,positions,node_size=20,with_labels=False,node_color="blue",alpha=0.4)nx.draw_networkx_edges(G,positions,edge_color="green",alpha=0.05)plt.axis('off')plt.show()# equivalentlyimportigraphG=igraph.Graph.TupleList(G.edges(),directed=False)layout=forceatlas2.forceatlas2_igraph_layout(G,pos=None,iterations=2000)igraph.plot(G,layout).show()

您还可以查看forceatlas2.py文件,以便更好地理解forceatlas2类及其函数。

功能已完成

    :巴尼斯HUT优化,N 2</SUP>复杂性到n.Ln(n)
  • gravity:将节点吸引到中心。防止岛屿漂移
  • 劝阻集线器:沿出站边缘分布吸引力。集线器吸引较少,因此被推向边界
  • scalingratio:你想要多少排斥力。“更多”使图形更稀疏
  • strong重力模式:更强的重力视图
  • jittertolerance:允许多少摆动。以上1人气馁。更低的速度和更高的精度
  • verbose:显示已完成迭代的进度条。此外,还显示了不同力计算所用的时间
  • edgeweightinfluence:对边权重的影响程度。0表示“无影响”,1表示“正常”

文档

您将在源代码中找到所有文档

贡献者

我们非常欢迎您的贡献。请提交请求并成为合作者。

版权所有

Copyright (C) 2017 Bhargav Chippada bhargavchippada19@gmail.com.
Licensed under the GNU GPLv3.

这些文件主要基于gephi、git修订版2b9a7c8和max shinn的算法python端口中包含的java文件。这里我包括这些文件的版权信息:

Copyright 2008-2011 Gephi
Authors : Mathieu Jacomy <mathieu.jacomy@gmail.com>
Website : http://www.gephi.org
Copyright 2011 Gephi Consortium. All rights reserved.
Portions Copyrighted 2011 Gephi Consortium.
The contents of this file are subject to the terms of either the
GNU General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with
the License.

<https://github.com/mwshinn/forceatlas2-python>
Copyright 2016 Max Shinn <mws41@cam.ac.uk>
Available under the GPLv3

Also, thanks to Eugene Bosiakov <https://github.com/bosiakov/fa2l>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何解析大型SOAP响应   java如何在ionic 3应用程序屏幕上设置自定义微调器   java如何在没有GPU的情况下运行libGDX headless,但仍然渲染帧?   java SpringBoot项目部署到服务器时发生异常   java Firestore:检查文档中的值是否存在   从其他类填充数组时出现java未识别的NullPointerException   java BouncyCastle最后一个字节解密问题   java使用属性将ListMultimap<Object,Object>写入和读取到文件   从jar执行程序时的java动态加载问题   java比较泛型类型(使用nodes私有类在LinkedList的上下文中扩展vs实现)   使用java编程的版本控制   java如何强制文本转到面板的按钮?   安全编码用户分层java   java将数字格式化为货币   使用printf的java格式化表   java如何使用LiveData更新RecyclerView示例:SeenCounter、CommentCounter、LikeCounter   数组逻辑OR和模运算符在Java中表现异常   java需要分别管理/集成32位和64位JVM运行的两个JAR