| Summary | Included libraries | Package variables | Synopsis | General documentation | Methods |
| Summary | Top |
| Clair::Network::CFNetwork |
| Package variables | Top |
| No package variables defined. |
| Included modules | Top |
| Clair::Network |
| Clair::Network::Reader::Pajek |
| Clair::Network::Writer::PajekProject |
| Inherit | Top |
| Clair::Network |
| Synopsis | Top |
| CFNetwork is a subclass of the Clair::Network. It includes the extra functionality needed to perform community finding within weighted, undirected networks. The main community finding algorithm is an implementation of the algorithm described in: A. Clauset, M. E. J. Newman and C. Moore, "Finding Community Structure in Very Large Networks," Phys. Rev. E. 70, 066111 (2004). |
| Description | Top |
| Methods | Top |
| _initialize | Description | Code |
| _join | Description | Code |
| _printInternals | Description | Code |
| add_edge | Description | Code |
| add_weighted_edge | Description | Code |
| buildFromMatrixFile | Description | Code |
| calc_k | Description | Code |
| communityFind | Description | Code |
| export2PajekProject | Description | Code |
| getConnectedComponent | Description | Code |
| getM | Description | Code |
| isConnected | Description | Code |
| new | Description | Code |
| numConnectedComponents | Description | Code |
| printEdgeWeights | Description | Code |
| printNodeLabels | Description | Code |
| printNodeValues | Description | Code |
| readFromPajek | Description | Code |
| remove_edge | Description | Code |
| remove_node | Description | Code |
| _initialize | code | next | Top |
($QR,$aR,$HR,$HM) = $cfn->initialize;Internal subroutine; there is no need for a user to call this routine, as it is only needed within the community finding algorithm. Initializes modularity table for community finding algorithm. Also calculates supporting information. |
| _join | code | prev | next | Top |
$self->_join($i,$j,$QR,$aR,$HR,$HM);The procedure that joins two communities; here, $i is absorbed by $j. Also updates $QR, $aR, $HR, and $HM to reflect the change. This procedure should only be used internally, within communityFind(). |
| _printInternals | code | prev | next | Top |
$self->_printInternals($QR,$aR,$HR,$HM);This is a debugging procedure that prints to standard output the contents of the given variables in a somewhat-readable fashion. It should not be used. |
| add_edge | code | prev | next | Top |
$cfn->add_edge($u,$v)Adds a new edge to the network, but gives a default weight of 1. Prevents creation of self-edges. |
| add_weighted_edge | code | prev | next | Top |
$cfn->add_weighted_edge($u,$v,$weight)Adds a new edge to the network, with the given weight. Prevents creation of self-edges. If the edge specified already exists in the network, its new weight is the sum of the old and $weight. However, if this new weight is negative, the edge is removed from the network completely. In this way, a network of non-negative, non-self edges can be maintained, and the weights can be easily incremented/decremented with this function. This function returns the new weight of the edge, or 0 if the new weight would be negative or if the edge specified was a self-edge. This routine also updates the m value associated with this network (that is, the sum of the weights of all edges in the network). |
| buildFromMatrixFile | code | prev | next | Top |
$cfn->buildFromMatrixFile($filename,$ignoreweights)This routine will read a symmetric adjacency matrix from a file and add those edges to the existing graph, creating nodes where necessary. If an edge between two nodes already exists, the weight in the matrix file will be added to the edge weight. |
| calc_k | code | prev | next | Top |
$k = $cfn->calc_k($u)For a given node, returns the sum of the weights of all the edges connected to it. |
| communityFind | code | prev | next | Top |
$cfn->communityFind() |
| export2PajekProject | code | prev | next | Top |
$self->export2PajekProject(partition => $partition) |
| getConnectedComponent | code | prev | next | Top |
my $subCFNetwork = $cfn->getConnectedComponent($num)This routine builds a new CFNetwork, consisting of the nodes and edges of the $num-th largest connected component of the original CFNetwork. For example, if $num == 2, the output will be a reference to a new CFNetwork object, with nodes identical to those in the 2nd largest connected component of the original, and all their internal edges. |
| getM | code | prev | next | Top |
$m = $cfn->getMReturns the sum of all the edge weights in the graph. |
| isConnected | code | prev | next | Top |
if ( $cfn->isConnected ) { ... } |
| new | code | prev | next | Top |
my $cfn = Clair::Network::CFNetwork->new() |
| numConnectedComponents | code | prev | next | Top |
$self->numConnectedComponentsReturns the number of connected components in the network. Can be time consuming for larger networks. |
| printEdgeWeights | code | prev | next | Top |
$cfn->printEdgeWeights($filename);This prints to filename a list of all the edges and their weights in the graph, one per line. The format is "source target weight". The weights are sorted by the source node id. |
| printNodeLabels | code | prev | next | Top |
$cfn->printNodeLabels($filename);This prints to filename a list of all the node labels in the graph, one per line. The labels are sorted by node id. If a node has no label, its label is listed as "undef". |
| printNodeValues | code | prev | next | Top |
$cfn->printNodeValues($filename);This prints to filename a list of all the node values in the graph, one per line. The values are sorted by node id. If a node has no value, its value is listed as "undef". |
| readFromPajek | code | prev | next | Top |
| read pajek's .net file in and build the network $network->readFromPajek("/data0/projects/cltest/CFNetwork/SampsonL.net"); |
| remove_edge | code | prev | next | Top |
$cfn->remove_edge($u,$v)This is essentially the same as the Network::remove_edge function, except that it updates the value of m associated with this network in addition to deleting the edge. This is necessary in order to maintain a valid m value in the presence of edge deletions. A running m tally is faster and easier then trying to calculate m everywhere it is needed, especially for larger networks. |
| remove_node | code | prev | next | Top |
$cfn->remove_node($id)This is essentially the same as the Network::remove_node function, except that it updates the value of m associated with this network in addition to deleting the node. This is necessary in order to maintain a valid m value in the presence of node deletions. A running m tally is faster and easier then trying to calculate m everywhere it is needed, especially for larger networks. |
| _initialize | description | prev | next | Top |
sub _initialize
{my $self = shift; my $com = shift; my %deltaQ; my %aHash; my %HHash; my @HMAX; my $m = $self->getM; my $constant = 1/(2*$m);} |
| _join | description | prev | next | Top |
sub _join
{my $self = shift; my ($i,$j,$QR,$aR,$HR,$HM) = @_; my @others = (); ## Find remaining communities other than $i, $j} |
| _printInternals | description | prev | next | Top |
sub _printInternals
{
my $self = shift;
my $QR = shift;
my $aR = shift;
my $HR = shift;
my $HM = shift;
my ($i,$j);
foreach $i ( sort {$a <=> $b} keys %{$aR} ) {
print "Community $i: a = ", $aR->{$i};
print " Maximum DQ at $HR->{$i}\n";
}
foreach $i (sort {$a <=> $b} keys %{$QR} ) {
print " DQ($i) : ";
print "Num. entries = ",scalar( keys %{$QR->{$i}} ), " : ";
foreach $j ( sort keys %{ $QR->{$i} } ) {
print " $j:";
print $QR->{$i}->{$j}, " ";
}
print "\n";
}
print "Maximum Delta Q = ", ${$HM}[0];
print " Located at = (", ${$HM}[1], ",", ${$HM}[2], ")\n";} |
| add_edge | description | prev | next | Top |
sub add_edge
{
my $self = shift;
my $u = shift;
my $v = shift;
## Assume a weight of 1} |
| add_weighted_edge | description | prev | next | Top |
sub add_weighted_edge
{
my $self = shift;
my $u = shift;
my $v = shift;
my $weight = shift;
my $graph = $self->{graph};
if( $u ne $v ) {
if( $graph->has_edge($u,$v) ) {
my $orig = $graph->get_edge_weight($u,$v);
$weight = $weight + $orig;
if( $weight < 0 ) {
$graph->delete_edge($u,$v);
$weight = 0;
$self->{mfact} = $self->{mfact} - $orig;
}
else {
$graph->set_edge_weight($u,$v,$weight);
$self->{mfact} = $self->{mfact} + $weight - $orig;
}
}
elsif ($weight >= 0 ) {
$graph->add_weighted_edge($u, $v, $weight);
$self->{mfact} = $self->{mfact} + $weight;
}
}
else { $weight = 0; }
return $weight;} |
| buildFromMatrixFile | description | prev | next | Top |
sub buildFromMatrixFile
{my $self = shift; my $file = shift; my $ignoreweights = shift; # Will read an Adjacency matrix from a file and add those edges to} |
| calc_k | description | prev | next | Top |
sub calc_k
{
my $self = shift;
my $node = shift;
my $graph = $self->{graph};
my @e = $graph->edges_at($node);
my $k = 0;
foreach ( @e ) {
#print "EDGE: ", ${$_}[0], " -- ", ${$_}[1], "\n";} |
| communityFind | description | prev | next | Top |
sub communityFind
{
my $self = shift;
my %parameters = @_;
if( exists $parameters{skip_connection_test} ) {
if( $parameters{skip_connection_test} ) {
print "Skipping internal connection test...assuming network is connected.\n";
}
else {
## Check to see if the graph is connected; if not, exit; the algorithm} |
| export2PajekProject | description | prev | next | Top |
sub export2PajekProject
{ my $self = shift;
my %parameters = @_;
my $partition = $parameters{partition};
my $export = Clair::Network::Writer::PajekProject->new();
$export->set_name($self->{name});
$export->write_network($self, $self->{name}, %parameters);} |
| getConnectedComponent | description | prev | next | Top |
sub getConnectedComponent
{
my $self = shift;
my $ccid = shift;
my $output;
my @cc = $self->{graph}->connected_components;
my $numcc = scalar( @cc );
print "\n$numcc connected components found.\n";
if( $numcc < 2 ) {
$output = $self;
}
else {
if( $ccid > $numcc ) { $ccid = $numcc; }
elsif( $ccid < 1 ) { $ccid = 1; }
my $i;
my %sizes;
for($i = 0; $i<=$#cc; $i++) {
$sizes{$i} = scalar( @{$cc[$i]} );
}
my $compIndex;
$i = 0;
foreach( sort {$sizes{$b} <=> $sizes{$a}} keys %sizes ) {
$i++;
if( $i == $ccid ) {
$compIndex = $_;
last;
}
}
## Now we know that $cc[$compIndex] is the $ccidth-largest component; make a} |
| getM | description | prev | next | Top |
sub getM
{
my $self = shift;
return $self->{mfact};} |
| isConnected | description | prev | next | Top |
sub isConnected
{
my $self = shift;
return $self->{graph}->is_connected;} |
| new | description | prev | next | Top |
sub new
{
my $class = shift;
my %parameters = @_;
my $name;
if( exists $parameters{name} ) {
$name = $parameters{name}
}
else {
$name = "CFNetwork";
}
my $graph = Graph::Undirected->new;
my $self = bless {
graph => $graph, ## All the important network data} |
| numConnectedComponents | description | prev | next | Top |
sub numConnectedComponents
{
my $self = shift;
my @cc = $self->{graph}->connected_components;
return scalar( @cc );} |
| printEdgeWeights | description | prev | next | Top |
sub printEdgeWeights
{
my $self = shift;
my $file = shift;
open(OUT, ">", $file) or die "CFNetwork:printEdgeWeights: Cannot write to specified file $file\n";
foreach ( sort {${$a}[0] <=> ${$b}[0] } $self->{graph}->edges ) {
print OUT "${$_}[0] ${$_}[1] ";
print OUT $self->get_edge_weight(${$_}[0],${$_}[1]), "\n";
}
close OUT;} |
| printNodeLabels | description | prev | next | Top |
sub printNodeLabels
{
my $self = shift;
my $file = shift;
open(OUT, ">", $file) or die "CFNetwork:printNodeLabels: Cannot write to specified file $file\n";
foreach ( sort {$a <=> $b} $self->{graph}->vertices ) {
if( $self->has_vertex_attribute($_,"label") ) {
print OUT "$_ ",$self->get_vertex_attribute($_,"label"), "\n";
}
else {
print OUT "undef\n";
}
}
close OUT;} |
| printNodeValues | description | prev | next | Top |
sub printNodeValues
{
my $self = shift;
my $file = shift;
open(OUT, ">", $file) or die "CFNetwork:printNodeValues: Cannot write to specified file $file\n";
foreach ( sort {$a <=> $b} $self->{graph}->vertices ) {
if( $self->has_vertex_attribute($_,"value") ) {
print OUT "$_ ", $self->get_vertex_attribute($_,"value"), "\n";
}
else {
print OUT "undef\n";
}
}
close OUT;} |
| readFromPajek | description | prev | next | Top |
sub readFromPajek
{my $self = shift; my $fileName = shift; my $reader = Clair::Network::Reader::Pajek->new(); my $net = $reader->read_network($fileName); #copy network} |
| remove_edge | description | prev | next | Top |
sub remove_edge
{
my $self = shift;
my $u = shift;
my $v = shift;
if( $self->has_edge($u,$v) ) {
##update m} |
| remove_node | description | prev | next | Top |
sub remove_node
{
my $self = shift;
my $id = shift;
if( $self->has_node($id) ) {
## update m Factor} |
| Description | Top |
| CFNetwork is a subclass of the Clair::Network. It includes the extra functionality needed to perform community finding within weighted, undirected networks. The main community finding algorithm is an implementation of the algorithm described in: A. Clauset, M. E. J. Newman and C. Moore, "Finding Community Structure in Very Large Networks," Phys. Rev. E. 70, 066111 (2004). |
| AUTHOR | Top |
| Ryan Roth << rmr48 AT columbia dot edu >> |
| BUGS | Top |
| None Known. |
| COPYRIGHT & LICENSE | Top |
| Copyright 2007 Ryan Roth, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |