Exemple #1
0
    def from_dic(cls, clustering_dic):
        """
        Creates a clustering from a clustering dictionary describing it (as reverse operation of
        'to_dic').
        """
        clusters_dic = clustering_dic["clusters"];
        clusters = []
        for cluster_dic in clusters_dic:
            clusters.append(Cluster.from_dic(cluster_dic))

        return Clustering(clusters)
Exemple #2
0
 def test_calculate_biased_medoid_scenario(self):
     cluster = Cluster.from_dic({
                                 "prototype": 28,
                                 "elements": "0:46, 49, 51, 53, 57:58, 62:67",
                                 "id": "cluster_0"
     })
     matrix = CondensedMatrix(list(numpy.asfarray(numpy.load(os.path.join(test_data.__path__[0],"matrix.npy")))))
     self.assertEqual(cluster.prototype, cluster.calculate_medoid(matrix))
     
     cluster = Cluster.from_dic({
                             "prototype": 54,
                             "elements": "0:117, 119:135, 138:139, 141, 143, 145:146, 148:150, 153, 155:156, 167:168, 170:172, 175, 177, 190, 193, 212, 215, 234",
                             "id": "cluster_0"
                         })
     self.assertEqual(cluster.prototype, cluster.calculate_medoid(matrix))
     
     cluster = Cluster.from_dic({
                     "prototype": 1604,
                     "elements": "224, 290, 312, 334, 378, 422, 444, 466, 468, 488, 504, 526, 645, 782, 799, 821, 843, 953, 1208, 1254, 1276, 1291, 1313, 1320, 1357, 1445, 1450, 1467, 1472, 1489, 1494, 1516, 1538, 1560, 1582, 1591, 1604, 1613, 1626, 1635, 1671, 1693, 1767, 1789, 1811, 1833, 1841, 1855, 1877, 1899, 1921, 1943, 1965, 2007, 2049, 2070, 2091, 2112, 2203",
                     "id": "cluster_18"
                 })
     self.assertEqual(cluster.prototype, cluster.calculate_medoid(matrix))
Exemple #3
0
 def test_from_dic(self):
     clusters = [
                 {
                     "prototype": 400,
                     "elements": "400:410, 0, 1 ,2,3"
                 },
                 {
                     "prototype": 500,
                     "elements": "4,500:510, 5, 6:10, 11"
                 }
             ]
      
     expected_elements =[
                         [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 0, 1, 2, 3],
                         [4, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 5, 6, 7, 8, 9, 10, 11]
                         ]
      
     for i in range(len(clusters)):
         self.assertEqual(Cluster.from_dic(clusters[i]).all_elements, expected_elements[i])