Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > c4e10658e5dd1bdd052522bdd0ee57ae > files > 18

perl-Algorithm-Cluster-1.470.0-1mdv2010.0.i586.rpm

#!/usr/bin/perl -w

use strict;
use Algorithm::Cluster qw/distancematrix/;

my $weight =  [ 1,1 ];
                                                                                
my $data =  [
    [ 1.1, 1.2 ],
    [ 1.4, 1.3 ],
    [ 1.1, 1.5 ],
    [ 2.0, 1.5 ],
    [ 1.7, 1.9 ],
    [ 1.7, 1.9 ],
    [ 5.7, 5.9 ],
    [ 3.1, 3.3 ],
    [ 5.4, 5.3 ],
    [ 5.1, 5.5 ],
    [ 5.1, 5.2 ],
];

my $mask =  [
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
    [ 1, 1 ],
];
                                                                                

#------------------
# Define the params we want to pass to distancematrix
my %params = (
    transpose =>         0,
    dist      =>       'e',
    data      =>     $data,
    mask      =>     $mask,
    weight    =>   $weight,
);


#------------------
# Here is where we invoke the library function!
#
printf("Calculating the distance matrix\n");

my $matrix = distancematrix(%params);
#
#------------------

my $row;
my $number;

foreach $row (@{$matrix}) {
    foreach $number (@{$row}) {
        printf("%7.3f\t", $number);
    }
    printf("\n");
}