#!/usr/perl/perl580/bin/perl 

use Algorithm::Cluster;

$^W = 1;
use strict;
use warnings "Algorithm::Cluster";

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 ],
    [ 5.7, 5.9 ],
    [ 3.1, 3.3 ],
    [ 5.4, 5.3 ],
    [ 5.1, 5.5 ],
    [ 5.0, 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 ],
    [ 1, 1 ],
    [ 1, 1 ],
];

my $clusterA = [ 0, 1, 2, 3 ];
my $clusterB = [ 4, 5, 6, 7 ];
my $clusterC = [ 8 ];

my %params = (
    transpose =>         0,
    method    =>       'a',
    dist      =>       'e',
);

my ($distance);

$distance = Algorithm::Cluster::clusterdistance(
    %params,
    data      =>    $data,
    mask      =>    $mask,
    weight    =>  $weight,
    cluster1  => $clusterA,
    cluster2  => $clusterB,
);

printf("Distance between cluster A and cluster B is %7.3f\n", $distance);

$distance = Algorithm::Cluster::clusterdistance(
    %params,
    data      =>    $data,
    mask      =>    $mask,
    weight    =>  $weight,
    cluster1  => $clusterA,
    cluster2  => $clusterC,
);

printf("Distance between cluster A and cluster C is %7.3f\n", $distance);

$distance = Algorithm::Cluster::clusterdistance(
    %params,
    data      =>    $data,
    mask      =>    $mask,
    weight    =>  $weight,
    cluster1  => $clusterB,
    cluster2  => $clusterC,
);

printf("Distance between cluster B and cluster C is %7.3f\n", $distance);

$distance = Algorithm::Cluster::clusterdistance(
    %params,
    data      =>    $data,
    mask      =>    $mask,
    weight    =>  $weight,
    cluster1  => $clusterA,
    cluster2  =>         5,
);

printf("Distance between cluster A and item 5 is %7.3f\n", $distance);

$distance = Algorithm::Cluster::clusterdistance(
    %params,
    data      =>    $data,
    mask      =>    $mask,
    weight    =>  $weight,
    cluster1  =>         1,
    cluster2  => $clusterC,
);

printf("Distance between cluster C and item 1 is %7.3f\n", $distance);

$distance = Algorithm::Cluster::clusterdistance(
    %params,
    data      =>    $data,
    mask      =>    $mask,
    weight    =>  $weight,
    cluster1  =>         1,
    cluster2  =>         6,
);

printf("Distance between item 1 and item 6 is %7.3f\n", $distance);

__END__
