Exemple #1
0
 def test_subsample(self):
     calculator = MeanMinimumDistanceCalculator(10)
     self.assertEqual( 14.5, calculator.subsample(10,20,  [4,6,3,24,7,12,9,17,20,43]))
     # If the percent gives less than 1 element, we use 1
     self.assertEqual( 43,  calculator.subsample(10,5,  [4,6,3,24,7,12,9,17,20,43]))
     # If the list has no elements, returns 0
     self.assertEqual( 0,  calculator.subsample(10,20,  []))
Exemple #2
0
 def test_subsampled_mean_min_dist(self):
     calculator = MeanMinimumDistanceCalculator(10)
     clusters = [Cluster(None, elements=[0,1,2]),
                 Cluster(None, elements=[3,4])]
     triangle = [ 1., 2., 3., 4., 
                      5., 6., 7., 
                          8., 9., 
                             10.]
     distances =  CondensedMatrix( triangle )
     self.assertEqual((8.0, 6.0),calculator.subsampled_mean_min_dist(clusters[0], clusters[1],  20, distances))
Exemple #3
0
 def test_mini_evaluation(self):
     calculator = MeanMinimumDistanceCalculator(10)
     clusters = [
         Cluster(None, elements=[0, 1, 2]),
         Cluster(None, elements=[3, 4])
     ]
     triangle = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]
     distances = CondensedMatrix(triangle)
     clustering = Clustering(clusters)
     self.assertEqual(7.0, calculator.evaluate(clustering, distances, 20))
Exemple #4
0
 def test_mini_evaluation(self):
     calculator = MeanMinimumDistanceCalculator(10)
     clusters = [Cluster(None, elements=[0,1,2]),
                 Cluster(None, elements=[3,4])]
     triangle = [ 1., 2., 3., 4., 
                      5., 6., 7., 
                          8., 9., 
                             10.]
     distances =  CondensedMatrix( triangle )
     clustering = Clustering(clusters)
     self.assertEqual(7.0, calculator.evaluate(clustering,distances,20))
Exemple #5
0
 def test_subsample(self):
     calculator = MeanMinimumDistanceCalculator(10)
     self.assertEqual(
         14.5,
         calculator.subsample(10, 20, [4, 6, 3, 24, 7, 12, 9, 17, 20, 43]))
     # If the percent gives less than 1 element, we use 1
     self.assertEqual(
         43, calculator.subsample(10, 5,
                                  [4, 6, 3, 24, 7, 12, 9, 17, 20, 43]))
     # If the list has no elements, returns 0
     self.assertEqual(0, calculator.subsample(10, 20, []))
Exemple #6
0
 def test_subsampled_mean_min_dist(self):
     calculator = MeanMinimumDistanceCalculator(10)
     clusters = [
         Cluster(None, elements=[0, 1, 2]),
         Cluster(None, elements=[3, 4])
     ]
     triangle = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]
     distances = CondensedMatrix(triangle)
     self.assertEqual(
         (8.0, 6.0),
         calculator.subsampled_mean_min_dist(clusters[0], clusters[1], 20,
                                             distances))
Exemple #7
0
 def test_full_run(self):
     condensed_matrix = CondensedMatrix(matrix)
     cmax = condensed_matrix.calculateMax()
     alg = RandomAlgorithm.RandomClusteringAlgorithm(condensed_matrix)
     values = []
     calculator =  MeanMinimumDistanceCalculator(10)
     for i in range(2,20):
         clustering = alg.perform_clustering({
                                              "max_num_of_clusters":-1, 
                                              "num_clusters":i
                                              })
         values.append( calculator.evaluate(clustering, condensed_matrix, 30))
     self.assertTrue(max(values) < cmax)
Exemple #8
0
 def test_get_min_distances(self):
     distances =  CondensedMatrix( [ 1., 2., 3., 4.,
                                         5., 6., 7., 
                                             8., 9., 
                                                10.])
     clusters = [Cluster(None, elements=[0,1,2]),
                 Cluster(None, elements=[3,4])]
     
     calculator = MeanMinimumDistanceCalculator(10)
     
     min_dists, mean = calculator.get_mean_and_min_distances(clusters[0], clusters[1], distances)
     self.assertItemsEqual( [3.0, 6.0, 8.0], min_dists)
     self.assertAlmostEquals(12.33,mean,2)
Exemple #9
0
    def test_get_min_distances(self):
        distances = CondensedMatrix([1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
        clusters = [
            Cluster(None, elements=[0, 1, 2]),
            Cluster(None, elements=[3, 4])
        ]

        calculator = MeanMinimumDistanceCalculator(10)

        min_dists, mean = calculator.get_mean_and_min_distances(
            clusters[0], clusters[1], distances)
        self.assertItemsEqual([3.0, 6.0, 8.0], min_dists)
        self.assertAlmostEquals(12.33, mean, 2)
Exemple #10
0
 def test_full_run(self):
     condensed_matrix = CondensedMatrix(matrix)
     cmax = condensed_matrix.calculateMax()
     alg = RandomAlgorithm.RandomClusteringAlgorithm(condensed_matrix)
     values = []
     calculator = MeanMinimumDistanceCalculator(10)
     for i in range(2, 20):
         clustering = alg.perform_clustering({
             "max_num_of_clusters": -1,
             "num_clusters": i
         })
         values.append(calculator.evaluate(clustering, condensed_matrix,
                                           30))
     self.assertTrue(max(values) < cmax)
Exemple #11
0
 def test_get_distances_less_than_mean(self):
     calculator = MeanMinimumDistanceCalculator(10)
     self.assertItemsEqual(range(51), calculator.get_distances_less_than_mean(range(100),50))
Exemple #12
0
 def test_get_distances_less_than_mean(self):
     calculator = MeanMinimumDistanceCalculator(10)
     self.assertItemsEqual(
         range(51), calculator.get_distances_less_than_mean(range(100), 50))