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个节点)。
将随机几何图形空间化
安装
从PIP安装:
pip install fa2
要生成和安装,请从源代码运行:
python setup.py install
cython是强烈推荐的,如果您是从源代码构建的,因为它将根据图表加速10-100倍
将二维网格空间化 来自FA2导入力LAS2
使用适当的设置创建ForceAtlas2对象。forceAtlas2类包含三个重要方法: 下面是一个使用示例。您还可以看到forceatlas2类的功能设置。 您还可以查看forceatlas2.py文件,以便更好地理解forceatlas2类及其函数。 您将在源代码中找到所有文档 我们非常欢迎您的贡献。请提交请求并成为合作者。 这些文件主要基于gephi、git修订版2b9a7c8和max shinn的算法python端口中包含的java文件。这里我包括这些文件的版权信息:依赖性
用法
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
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()
功能已完成
文档
贡献者
版权所有
Copyright (C) 2017 Bhargav Chippada bhargavchippada19@gmail.com.
Licensed under the GNU GPLv3.
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>
推荐PyPI第三方库