[Scipy-svn] r5021 - trunk/scipy/cluster/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Nov 7 17:46:49 EST 2008


Author: damian.eads
Date: 2008-11-07 16:46:45 -0600 (Fri, 07 Nov 2008)
New Revision: 5021

Modified:
   trunk/scipy/cluster/tests/test_hierarchy.py
Log:
Added test to leaders function.

Modified: trunk/scipy/cluster/tests/test_hierarchy.py
===================================================================
--- trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-07 22:14:00 UTC (rev 5020)
+++ trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-07 22:46:45 UTC (rev 5021)
@@ -38,7 +38,7 @@
 import numpy as np
 from numpy.testing import *
 
-from scipy.cluster.hierarchy import linkage, from_mlab_linkage, to_mlab_linkage, numobs_linkage, inconsistent, cophenet, from_mlab_linkage, fclusterdata, fcluster, is_isomorphic, single, complete, average, weighted, centroid, median, ward
+from scipy.cluster.hierarchy import linkage, from_mlab_linkage, to_mlab_linkage, numobs_linkage, inconsistent, cophenet, from_mlab_linkage, fclusterdata, fcluster, is_isomorphic, single, complete, average, weighted, centroid, median, ward, leaders
 from scipy.spatial.distance import squareform, pdist, numobs_dm, numobs_y
 
 _tdist = np.array([[0,    662,  877,  255,  412,  996],
@@ -298,7 +298,7 @@
     # with single linkage and Q data set
 
     def test_single_inconsistent_tdist_1(self):
-        "Testing inconsistency matrix calculation (depth=1) on a weighted linkage."
+        "Testing inconsistency matrix calculation (depth=1, dataset=Q) with single linkage."
         X = eo['Q-X']
         Z = linkage(X, 'single', 'euclidean')
         R = inconsistent(Z, 1)
@@ -308,7 +308,7 @@
         self.failUnless(within_tol(R, Rright, eps))
 
     def test_single_inconsistent_tdist_2(self):
-        "Testing inconsistency matrix calculation (depth=2) on a weighted linkage."
+        "Testing inconsistency matrix calculation (depth=2, dataset=Q) with single linkage."
         X = eo['Q-X']
         Z = linkage(X, 'single', 'euclidean')
         R = inconsistent(Z, 2)
@@ -318,7 +318,7 @@
         self.failUnless(within_tol(R, Rright, eps))
 
     def test_single_inconsistent_tdist_3(self):
-        "Testing inconsistency matrix calculation (depth=3) on a weighted linkage."
+        "Testing inconsistency matrix calculation (depth=3, dataset=Q) with single linkage."
         X = eo['Q-X']
         Z = linkage(X, 'single', 'euclidean')
         R = inconsistent(Z, 3)
@@ -328,7 +328,7 @@
         self.failUnless(within_tol(R, Rright, eps))
 
     def test_single_inconsistent_tdist_4(self):
-        "Testing inconsistency matrix calculation (depth=4) on a weighted linkage."
+        "Testing inconsistency matrix calculation (depth=4, dataset=Q) with single linkage."
         X = eo['Q-X']
         Z = linkage(X, 'single', 'euclidean')
         R = inconsistent(Z, 4)
@@ -474,6 +474,18 @@
         T = fcluster(Z, criterion='maxclust', t=4)
         self.failUnless(is_isomorphic(T, expectedT))
 
+class TestLeaders(TestCase):
+
+    def test_leaders_single(self):
+        "Tests leaders using a flat clustering generated by single linkage."
+        X = eo['Q-X']
+        Y = pdist(X)
+        Z = linkage(Y)
+        T = fcluster(Z, criterion='maxclust', t=3)
+        Lright = (np.array([53, 55, 56]), np.array([2, 3, 1]))
+        L = leaders(Z, T)
+        self.failUnless((L[0] == Lright[0]).all() and (L[1] == Lright[1]).all())
+
 def help_single_inconsistent_depth(self, i):
     Y = squareform(_tdist)
     Z = linkage(Y, 'single')




More information about the Scipy-svn mailing list