fa2

Fastest Gephi's ForceAtlas2 graph layout algorithm implemented for Python and NetworkX

https://github.com/bhargavchippada/forceatlas2

Science Score: 46.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: plos.org
  • Committers with academic emails
    1 of 8 committers (12.5%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.2%) to scientific vocabulary

Keywords

force-directed-graph force-layout forceatlas2 graph networkx python
Last synced: 6 months ago · JSON representation

Repository

Fastest Gephi's ForceAtlas2 graph layout algorithm implemented for Python and NetworkX

Basic Info
  • Host: GitHub
  • Owner: bhargavchippada
  • License: gpl-3.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 831 KB
Statistics
  • Stars: 298
  • Watchers: 9
  • Forks: 87
  • Open Issues: 28
  • Releases: 5
Topics
force-directed-graph force-layout forceatlas2 graph networkx python
Created over 8 years ago · Last pushed almost 2 years ago
Metadata Files
Readme License

README.md

ForceAtlas2 for Python

A port of Gephi's Force Atlas 2 layout algorithm to Python 2 and Python 3 (with a wrapper for NetworkX and igraph). This is the fastest python implementation available with most of the features complete. It also supports Barnes Hut approximation for maximum speedup.

ForceAtlas2 is a very fast layout algorithm for force-directed graphs. It's used to spatialize a weighted undirected graph in 2D (Edge weight defines the strength of the connection). The implementation is based on this paper and the corresponding gephi-java-code. Its really quick compared to the fruchterman reingold algorithm (spring layout) of networkx and scales well to high number of nodes (>10000).

Spatialize a random Geometric Graph

Geometric Graph

Installation

Install from pip:

pip install fa2

To build and install run from source:

python setup.py install

Cython is highly recommended if you are buidling from source as it will speed up by a factor of 10-100x depending on the graph

Dependencies

  • numpy (adjacency matrix as complete matrix)
  • scipy (adjacency matrix as sparse matrix)
  • tqdm (progressbar)
  • Cython (10-100x speedup)
  • networkx (To use the NetworkX wrapper function, you obviously need NetworkX)
  • python-igraph (To use the igraph wrapper)

Spatialize a 2D Grid

Grid Graph

Usage

from fa2 import ForceAtlas2

Create a ForceAtlas2 object with the appropriate settings. ForceAtlas2 class contains three important methods: ```python 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

python forceatlas2networkxlayout(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

python forceatlas2igraphlayout(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

``` Below is an example usage. You can also see the feature settings of ForceAtlas2 class.

```python import networkx as nx from fa2 import ForceAtlas2 import matplotlib.pyplot as plt

G = nx.randomgeometricgraph(400, 0.2)

forceatlas2 = ForceAtlas2( # Behavior alternatives outboundAttractionDistribution=True, # Dissuade hubs linLogMode=False, # NOT IMPLEMENTED adjustSizes=False, # Prevent overlap (NOT IMPLEMENTED) edgeWeightInfluence=1.0,

                    # Performance
                    jitterTolerance=1.0,  # Tolerance
                    barnesHutOptimize=True,
                    barnesHutTheta=1.2,
                    multiThreaded=False,  # NOT IMPLEMENTED

                    # Tuning
                    scalingRatio=2.0,
                    strongGravityMode=False,
                    gravity=1.0,

                    # Log
                    verbose=True)

positions = forceatlas2.forceatlas2networkxlayout(G, pos=None, iterations=2000) nx.drawnetworkxnodes(G, positions, nodesize=20, withlabels=False, nodecolor="blue", alpha=0.4) nx.drawnetworkxedges(G, positions, edgecolor="green", alpha=0.05) plt.axis('off') plt.show()

equivalently

import igraph G = igraph.Graph.TupleList(G.edges(), directed=False) layout = forceatlas2.forceatlas2igraphlayout(G, pos=None, iterations=2000) igraph.plot(G, layout).show() ``` You can also take a look at forceatlas2.py file for understanding the ForceAtlas2 class and its functions better.

Features Completed

  • barnesHutOptimize: Barnes Hut optimization, n2 complexity to n.ln(n)
  • gravity: Attracts nodes to the center. Prevents islands from drifting away
  • Dissuade Hubs: Distributes attraction along outbound edges. Hubs attract less and thus are pushed to the borders
  • scalingRatio: How much repulsion you want. More makes a more sparse graph
  • strongGravityMode: A stronger gravity view
  • jitterTolerance: How much swinging you allow. Above 1 discouraged. Lower gives less speed and more precision
  • verbose: Shows a progressbar of iterations completed. Also, shows time taken for different force computations
  • edgeWeightInfluence: How much influence you give to the edges weight. 0 is "no influence" and 1 is "normal"

Documentation

You will find all the documentation in the source code

Contributors

Contributions are highly welcome. Please submit your pull requests and become a collaborator.

Copyright

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

The files are heavily based on the java files included in Gephi, git revision 2b9a7c8 and Max Shinn's port to python of the algorithm. Here I include the copyright information from those files:

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>

Owner

  • Name: Bhargav Chippada
  • Login: bhargavchippada
  • Kind: user
  • Location: Mountainview, US
  • Company: Masters @ UMass-Amherst

I graduated from IIT Bombay in 2016, specializing in Computer Science. I love science, math, and artificial intelligence. Experience @ GOOGL, MSFT, AMZN, OLA

GitHub Events

Total
  • Issues event: 1
  • Watch event: 18
  • Issue comment event: 4
  • Pull request event: 2
  • Fork event: 9
Last Year
  • Issues event: 1
  • Watch event: 18
  • Issue comment event: 4
  • Pull request event: 2
  • Fork event: 9

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 45
  • Total Committers: 8
  • Avg Commits per committer: 5.625
  • Development Distribution Score (DDS): 0.489
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Bhargav Chippada b****9@g****m 23
Bhargav Chippada b****9@g****m 12
Gökcen Eraslan g****n@g****m 3
Bence Nagy b****e@u****e 2
Quentin Petit p****1@g****m 2
Nicolas ELIE n****e@c****r 1
Rob Reynolds r****p@u****m 1
Victor Benichoux v****x@c****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 32
  • Total pull requests: 21
  • Average time to close issues: 6 months
  • Average time to close pull requests: 9 months
  • Total issue authors: 32
  • Total pull request authors: 17
  • Average comments per issue: 2.78
  • Average comments per pull request: 1.38
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 4
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • tarikaltuncu (1)
  • jakirkham (1)
  • satrio-yudhoatmojo (1)
  • uros-r (1)
  • spmp (1)
  • YourGc (1)
  • jnboehm (1)
  • Make42 (1)
  • valentinlemaire (1)
  • jeiros (1)
  • vrk7bp (1)
  • clyang (1)
  • jim-bo (1)
  • filannim (1)
  • maximilianh (1)
Pull Request Authors
  • victorbenichoux (2)
  • maxipeschke (2)
  • underyx (2)
  • gaardhus (2)
  • KanHarI (2)
  • matteoacrossi (1)
  • nicolaselie (1)
  • Zhouuuuu5 (1)
  • beyondbeneath (1)
  • davidtweddell (1)
  • cvanelteren (1)
  • reynoldsnlp (1)
  • KKcorps (1)
  • petitquentin (1)
  • uros-r (1)
Top Labels
Issue Labels
enhancement (5) question (4) bug (2) meta (1) help wanted (1)
Pull Request Labels
enhancement (5) bug (1)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 981 last-month
  • Total docker downloads: 1,663
  • Total dependent packages: 7
    (may contain duplicates)
  • Total dependent repositories: 284
    (may contain duplicates)
  • Total versions: 5
  • Total maintainers: 1
pypi.org: fa2

The fastest ForceAtlas2 algorithm for Python (and NetworkX)

  • Versions: 4
  • Dependent Packages: 7
  • Dependent Repositories: 282
  • Downloads: 981 Last month
  • Docker Downloads: 1,663
Rankings
Dependent repos count: 0.9%
Dependent packages count: 1.6%
Docker downloads count: 2.1%
Average: 3.4%
Stargazers count: 4.0%
Forks count: 5.1%
Downloads: 6.9%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: fa2
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 2
Rankings
Dependent repos count: 20.2%
Forks count: 23.1%
Stargazers count: 24.7%
Average: 29.9%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

setup.py pypi
  • numpy *
  • scipy *
  • tqdm *