Algorithm-Cluster
view release on metacpan or search on metacpan
perl/t/16_pca.t view on Meta::CPAN
use Test::More tests => 74;
use lib '../blib/lib','../blib/arch';
use_ok ("Algorithm::Cluster");
require_ok ("Algorithm::Cluster");
use warnings;
#########################
#------------------------------------------------------
# Tests
#
my ($mean, $coordinates, $pc, $eigenvalues);
my $data1 = [
[ 3.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 $data2 = [
[ 2.3, 4.5, 1.2, 6.7, 5.3, 7.1],
[ 1.3, 6.5, 2.2, 5.7, 6.2, 9.1],
[ 3.2, 7.2, 3.2, 7.4, 7.3, 8.9],
[ 4.2, 5.2, 9.2, 4.4, 6.3, 7.2],
];
($mean, $coordinates, $pc, $eigenvalues) = Algorithm::Cluster::pca($data1);
is (sprintf("%7.4f", $mean->[0]), " 3.5462");
is (sprintf("%7.4f", $mean->[1]), " 3.5308");
is (sprintf("%7.4f", $coordinates->[0][0]), " 2.0323");
is (sprintf("%7.4f", $coordinates->[0][1]), " 1.2252");
is (sprintf("%7.4f", $coordinates->[1][0]), " 3.0937");
is (sprintf("%7.4f", $coordinates->[1][1]), "-0.1065");
is (sprintf("%7.4f", $coordinates->[2][0]), " 3.1453");
is (sprintf("%7.4f", $coordinates->[2][1]), "-0.4633");
is (sprintf("%7.4f", $coordinates->[3][0]), " 2.5440");
is (sprintf("%7.4f", $coordinates->[3][1]), " 0.2063");
is (sprintf("%7.4f", $coordinates->[4][0]), " 2.4468");
is (sprintf("%7.4f", $coordinates->[4][1]), "-0.2841");
is (sprintf("%7.4f", $coordinates->[5][0]), " 2.4468");
is (sprintf("%7.4f", $coordinates->[5][1]), "-0.2841");
is (sprintf("%7.4f", $coordinates->[6][0]), "-3.2019");
is (sprintf("%7.4f", $coordinates->[6][1]), " 0.0197");
is (sprintf("%7.4f", $coordinates->[7][0]), "-3.2019");
is (sprintf("%7.4f", $coordinates->[7][1]), " 0.0197");
is (sprintf("%7.4f", $coordinates->[8][0]), " 0.4698");
( run in 0.932 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )