Finding Communities in a Network
From CLAIRlib
In this tutorial, you'll use Clair::Network::CFNetwork to find the communities in the Karate Club network.
Contents |
Read the Network file
The Karate Club network is provided in GML format. Therefore, we will use Clair::Network::Reader::GML to read it.
use Clair::Network::Reader::GML;
my $reader = new Clair::Network::Reader::GML();
my $net = $reader->read_network("karate.gml");
Create Clair::Network::CFNetwork instance
Next, create an instance of Clair::Network::CFNetwork and read the network into it.
use Clair::Network::CFNetwork; my $cfn = Clair::Network::CFNetwork(); $cfn->read_network($net);
Find the communities in the network
Now, you can run the community finding algorithm.
$cfn->communityFind();
This will create a file named Karate.bestComm in the current directory. This file contains the optimal node labeling computed by the algorithm. Each line of the file has the format node community
Code
The code used in this tutorial is
#!/usr/bin/perl use Clair::Network::Reader::GML; use Clair::Network::CFNetwork;
my $reader = new Clair::Network::Reader::GML(name=>"Karate");
my $net = $reader->read_network("karate.gml");
my $cfn = new Clair::Network::CFNetwork();
$cfn->read_network($net);
$cfn->communityFind(dirname => "results");
Results
The content of Karate.bestComm after running running the code above should be something like
1 1 2 1 3 7 4 7 5 1 6 7 7 7 8 7 9 1 10 1 11 22 12 1 13 1 14 1 15 1 16 1 17 1 18 22 19 1 20 22 21 1 22 22 23 7 24 1 25 1 26 22 27 7 28 7 29 7 30 1 31 1 32 22 33 22 34 22
This means that nodes 1, 2, 5, 9, 10, 12, 13, 14, 15, 16, 17, 19, 21, 24, 25, 30, and 31 are all in the same community and so on.

