?? ex3_kcluster
字號:
#!/usr/perl/perl580/bin/perl -wuse Algorithm::Cluster qw/kcluster/;use strict;my $weight1 = [ 1,1 ];my $data1 = [ [ 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 $mask1 = [ [ 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 $data2 = [ [ 1.1, 2.2, 3.3, 4.4, 5.5, ], [ 3.1, 3.2, 1.3, 2.4, 1.5, ], [ 4.1, 2.2, 0.3, 5.4, 0.5, ], [ 12.1, 2.0, 0.0, 5.0, 0.0, ], ];my $mask2 = [ [ 1, 1, 1, 1, 1, ], [ 1, 1, 1, 1, 1, ], [ 1, 1, 1, 1, 1, ], [ 1, 1, 1, 1, 1, ], ];my $weight2 = [ 1,1,1,1,1 ];my %params = ( nclusters => 3, transpose => 0, npass => 100, method => 'a', dist => 'e',);my ($clusters, $centroids, $error, $found);my ($i);$i=0;($clusters, $centroids, $error, $found) = kcluster( %params, data => $data1, mask => $mask1, weight => $weight1,);printf("\n");printf("Clustering first data set:\n\n");$i=0;foreach(@{$centroids}) { printf("Cluster %d: centroid: (", $i++); foreach(@{$_}) { printf("%7.3f ",$_); } printf(")\n");}printf("\n");$i=0;foreach(@{$clusters}) { printf("Gene %2d belongs to cluster %2d\n",$i++,$_);}printf("\n");printf("Within-cluster sum of distances is %f\n", $error);printf("\n");printf("Clustering second data set:\n\n");($clusters, $centroids, $error, $found) = kcluster( %params, data => $data2, mask => $mask2, weight => $weight2,);$i=0;foreach(@{$centroids}) { printf("Cluster %d: centroid: (", $i++); foreach(@{$_}) { printf("%7.3f ",$_); } printf(")\n");}printf("\n");$i=0;foreach(@{$clusters}) { printf("Gene %2d belongs to cluster %2d\n",$i++,$_);}printf("\n");printf("Within-cluster sum of distances is %f\n", $error);printf("\n");__END__
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -