def test_ordering_on(self, data): def p(val, obj=None): self.assert_(val >= 0 and val <= 100) self.assertIsInstance(val, float) matrix = instance_distance_matrix(data, Euclidean(), progress_callback=p) root1 = HierarchicalClustering(matrix, progress_callback=p) root2 = hier.clone(root1) order_leaves_py(root1, matrix, progress_callback=p) order_leaves_cpp(root2, matrix, progress_callback=p) def score(mapping): sum = 0.0 for i in range(matrix.dim - 1): sum += matrix[mapping[i], mapping[i + 1]] return sum # Slight differences are possible due to the float/double precision. self.assertAlmostEqual(score(root1.mapping), score(root2.mapping), places=3)
def test_clone(self): cloned_cluster = hier.clone(self.cluster) self.assertTrue(self.cluster.mapping.objects is cloned_cluster.mapping.objects) self.assertEqual(self.cluster.mapping, cloned_cluster.mapping) self.assertEqual(list(self.cluster), list(cloned_cluster))
def test_clone(self): cloned_cluster = hier.clone(self.cluster) self.assertTrue( self.cluster.mapping.objects is cloned_cluster.mapping.objects) self.assertEqual(self.cluster.mapping, cloned_cluster.mapping) self.assertEqual(list(self.cluster), list(cloned_cluster))