def __do_one_iteration(self,remaining_nodes,cutoff): (node,len_neigh) = self.condensed_matrix.choose_node_with_higher_cardinality(remaining_nodes,cutoff) #@UnusedVariable neighbours = self.condensed_matrix.get_neighbors_for_node(node,remaining_nodes,cutoff) cluster_tuple = (node, neighbours) cluster = cluster_from_tuple(cluster_tuple) eliminate_cluster_from_node_list(remaining_nodes,cluster) return cluster
def test_eliminate_cluster(self): cluster = cluster_from_tuple((4,[2,3,5,7,9])) nodes = range(15) nodes_left = [0,1,6,8,10,11,12,13,14] eliminate_cluster_from_node_list(nodes, cluster) nodes_left.sort() for i in range(len(nodes)): self.assertEqual(nodes[i],nodes_left[i])
def __do_one_iteration(self, remaining_nodes, cutoff): (node, len_neigh ) = self.condensed_matrix.choose_node_with_higher_cardinality( remaining_nodes, cutoff) #@UnusedVariable neighbours = self.condensed_matrix.get_neighbors_for_node( node, remaining_nodes, cutoff) cluster_tuple = (node, neighbours) cluster = cluster_from_tuple(cluster_tuple) eliminate_cluster_from_node_list(remaining_nodes, cluster) return cluster
def __do_one_iteration(self,remaining_nodes,cutoff): """ IMPORTANT: Prototype and medoid may not be the same element (ex @ http://www.jstatsoft.org/v01/i04/paper). """ (node,len_neigh) = self.condensed_matrix.choose_node_with_higher_cardinality(remaining_nodes,cutoff) #@UnusedVariable neighbours = self.condensed_matrix.get_neighbors_for_node(node,remaining_nodes,cutoff) cluster_tuple = (node, neighbours) cluster = cluster_from_tuple(cluster_tuple) eliminate_cluster_from_node_list(remaining_nodes,cluster) return cluster
def __do_one_iteration(self, remaining_nodes, cutoff): """ IMPORTANT: Prototype and medoid may not be the same element (ex @ http://www.jstatsoft.org/v01/i04/paper). """ (node, len_neigh ) = self.condensed_matrix.choose_node_with_higher_cardinality( remaining_nodes, cutoff) #@UnusedVariable neighbours = self.condensed_matrix.get_neighbors_for_node( node, remaining_nodes, cutoff) cluster_tuple = (node, neighbours) cluster = cluster_from_tuple(cluster_tuple) eliminate_cluster_from_node_list(remaining_nodes, cluster) return cluster
def test_cluster_from_tuple(self): cluster_tuple = (1,[16,17,18]) expected_cluster = Cluster(1,[1,16,17,18]) cluster = cluster_from_tuple(cluster_tuple) self.assertEquals(expected_cluster,cluster)
def test_get_sizes(self): myclusters = [] for c in test_data.clusters: myclusters.append(cluster_from_tuple(c)) sizes = [5,4,4,4,3] numpy.testing.assert_array_equal(sizes, get_cluster_sizes(myclusters)[1], "Cluster sizes are different")