Esempio n. 1
0
 def test_evaluate(self):
     partitions = self.create_test_cluster_points()
     clusters = self.create_test_cluster_points()
     clusters[0].cluster_id = 2
     clusters[1].cluster_id = 2
     nmi = NormalizedMutualInformation()
     self.assertEqual(nmi.evaluate(clusters, partitions), 0)
Esempio n. 2
0
 def test_mutual_information(self):
     partitions = self.create_test_cluster_points()
     clusters = self.create_test_cluster_points()
     clusters[0].cluster_id = 2
     nmi = NormalizedMutualInformation()
     self.assertEqual(nmi.mutual_information(clusters, partitions),
                      0.17441604792151594)
Esempio n. 3
0
 def test_information_term(self):
     partitions = self.create_test_cluster_points()
     clusters = self.create_test_cluster_points()
     clusters[0].cluster_id = 2
     nmi = NormalizedMutualInformation()
     self.assertEqual(nmi.information_term(clusters, partitions, 1, 1),
                      0.13515503603605478)
     self.assertEqual(nmi.information_term(clusters, partitions, 1, 2), 0)
     self.assertEqual(nmi.information_term(clusters, partitions, 2, 1),
                      -0.09589402415059363)
     self.assertEqual(nmi.information_term(clusters, partitions, 2, 2),
                      0.13515503603605478)
Esempio n. 4
0
 def test_joint_probability(self):
     partitions = self.create_test_cluster_points()
     clusters = self.create_test_cluster_points()
     clusters[0].cluster_id = 2
     nmi = NormalizedMutualInformation()
     self.assertEqual(nmi.joint_probability(partitions, clusters, 1, 1),
                      1 / 3)
     self.assertEqual(nmi.joint_probability(partitions, clusters, 1, 2),
                      1 / 3)
     self.assertEqual(nmi.joint_probability(partitions, clusters, 2, 1),
                      0 / 3)
     self.assertEqual(nmi.joint_probability(partitions, clusters, 2, 2),
                      1 / 3)
Esempio n. 5
0
 def test_cluster_probability(self):
     points = self.create_test_cluster_points()
     nmi = NormalizedMutualInformation()
     self.assertEqual(nmi.cluster_probability(points, 1), 2 / 3)
     self.assertEqual(nmi.cluster_probability(points, 2), 1 / 3)
Esempio n. 6
0
 def test_entropy_of_clustering(self):
     points = self.create_test_cluster_points()
     self.assertEqual(
         NormalizedMutualInformation().entropy_of_clustering(points),
         0.6365141682948128)
Esempio n. 7
0
 def test_evaluate_perfect_match(self):
     partitions = self.create_test_cluster_points()
     clusters = self.create_test_cluster_points()
     nmi = NormalizedMutualInformation()
     self.assertEqual(nmi.evaluate(clusters, partitions), 1)