Algorithm-MCL
view release on metacpan or search on metacpan
lib/Algorithm/MCL.pm view on Meta::CPAN
my $ref5 = [];
my $mcl1 = Algorithm::MCL->new();
# create graph by adding edges
$mcl1->addEdge($obj1, $ref2);
$mcl1->addEdge($obj1, $ref3);
$mcl1->addEdge($ref2, $ref3);
$mcl1->addEdge($ref3, $ref4);
$mcl1->addEdge($ref4, $ref5);
# run MCL algorithm on created graph
my $clusters1 = $mcl1->run();
# get clusters
foreach my $cluster ( @$clusters1 ) {
print "Cluster size: ". scalar @$cluster. "\n";
}
####################################
my $val1 = \"aaa";
my $val2 = \"bbb";
my $val3 = \"ccc";
my $val4 = \"ddd";
my $val5 = \"eee";
my $mcl2 = Algorithm::MCL->new();
$mcl2->addEdge($val1, $val2);
$mcl2->addEdge($val1, $val3);
$mcl2->addEdge($val2, $val3);
$mcl2->addEdge($val3, $val4);
$mcl2->addEdge($val4, $val5);
my $clusters2 = $mcl2->run();
foreach my $cluster ( @$clusters2 ) {
print "Found Cluster\n";
foreach my $vertex ( @$cluster ) {
print " Cluster element: $$vertex \n";
}
}
=head1 DESCRIPTION
This module is perl implementation of Markov Cluster Algorithm (MCL) based on Perl Data Language (PDL).
MCL is algorithm of finding clusters of vertices in graph. More information about MCL can be found at L<http://micans.org/mcl/>. There is also perl script implementing MCL - minimcl L<http://www.micans.org/mcl/scripts/minimcl>.
This module try to solve two problems:
=over 2
=item *
easy integration MCL in perl scripts and modules. Algorithm::MCL accept references as input and every reference will be found later in some cluster.
=item *
performance and scale. Algorithm::MCL use Perl Data Language for most of its processing and should run very fast on very big clusters. Main Algorithm::MCL procedures are written with "pdlpp".
=back
=head1 METHODS
=head2 new()
create new Algorithm::MCL object that accumulate graph edges and process data.
=head2 addEdge($ref1, $ref2, $distance)
add new edge to graph. first two parameters are reference to vertex objects. third parameter is "connection strength measurement" between vetices. "connection strength measurement" should be number between 0 and 1, higher number means stronger connec...
=head2 run()
apply MCL algorithm on graph. return reference to array that every element is reference to cluser array.
=head1 AUTHOR
Pinkhas Nisanov <pinkhas@nisanov.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Pinkhas Nisanov.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__DATA__
__Pdlpp__
pp_def('getClustersIndex',
Pars => 'a(m, n); [o]idxs(m);',
Code => q{
int ii;
int m_size = $SIZE(m);
for (ii=0; ii<m_size; ii++) {
int clFlag = 0;
if ($a(m=>ii, n=>ii) > 0) {
clFlag = 1;
}
$idxs(m=>ii) = clFlag;
}
}
);
pp_def('addLoops',
Pars => 'a(m, n);',
Code => q{
int ii;
int m_size = $SIZE(m);
int n_size = $SIZE(n);
for (ii=0; ii<m_size; ii++) {
int jj;
double vmax;
vmax = 0;
for (jj=0; jj<n_size; jj++) {
if ($a(m=>ii,n=>jj) > vmax) {
vmax = $a(m=>ii, n=>jj);
}
( run in 1.605 second using v1.01-cache-2.11-cpan-524268b4103 )