in reply to Pair-Wise Clustering
I'm not seeing the logic behind that output datastructure.
Some questions:
The way I would do this is an AoA structure, with the indexes reversed:
Thusly, $someElement = $clusters[$clusterIndex][$elementIndex];my $data = shift; my @clusters; my $elementsAlreadyUsed = []; while (my $nextCluster = findNextCluster($data, $elementsAlreadyUsed)) { push @clusters, nextCluster; } # Loop over each cluster for my $clusterID (0.. $#clusters) { print "Cluster $clusterID (#". ($clusterID +1) . ")\n"; # Print the elements contained in the cluster print "\tContains element(s): ". (join ', ', @{$clusters[$clusterID] +}) . "\n"; } sub findNextCluster { my $data = shift; my $elementsUsed = shift; # Pick first unused element to start from. # Return undef if all elements are used. # DFS or BFS over data connected to the start element; return BFSResultArrayRef($data, $startElement); }
|
|---|