Using age-cda for Community Detection in Apache AGE with python
Moontasir Mahmood
Posted on May 7, 2023
Community detection is a popular graph analysis technique used to identify groups of nodes in a network that are densely connected with each other but sparsely connected to other groups. Community detection has numerous applications, such as identifying groups of people with similar interests in social networks, finding clusters of related proteins in biological networks, and identifying clusters of related websites in web link networks.
Here, we will be discussing how to install and use the age-cda Python package for community detection in the AGE graph database.
Installation
Install via PIP
You can install the age-cda package using pip, which is the easiest way to install Python packages.
pip install age-cda
Build from Source
To build age-cda from source, you need to first install libeigen3-dev. You can install it on Ubuntu/Debian based systems using the following command:
sudo apt-get update
sudo apt-get install libeigen3-dev
Next, clone the Community-Detection-Modularity repository from Github, navigate to the directory, and run the following command:
python setup.py install
You also need to configure the GNU Scientific Library (GSL). You can follow the instructions in this tutorial to configure GSL on your system.
Unit Test
You can run the unit tests using the following command:
python -m unittest test_community.py
Instruction
Import
To use age-cda in your Python project, import the Graph class from the age_cda package as shown below:
from age_cda import Graph
Create Graph
To create a graph, you need to pass two arguments to the Graph class constructor:
- Nodes: A list of nodes in the graph.
- Edges: A 2D list of edges in the graph represented as an adjacency list.
nodes = [0, 1, 2, 3, 4, 5]
edges = [[0, 1], [0, 2], [1, 2], [2, 3], [3, 4], [3, 5], [4, 5]]
g = Graph.Graph()
g.createGraph(nodes, edges)
Generate Community Assignment
To generate the community assignments, simply call the get_community() method on the graph object.
res = g.get_community()
Output Format
The get_community() method returns a list of communities, where each community is represented as a list of nodes.
[[3,4,5],[0,1,2]]
Each community is a list of nodes that belong to the community.
Conclusion
Now you can use the python AGE driver to get all nodes and edges get the desired community. In this blog, we learned how to use age-cda
for community detection in Python. We covered the installation process and provided examples of how to create a graph and generate community assignments. With age-cda, you can easily analyze the structure of graphs and identify communities of nodes that are highly interconnected.
Posted on May 7, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.