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

scipy-svn@scip... scipy-svn@scip...
Fri Nov 7 15:49:56 CST 2008


Author: damian.eads
Date: 2008-11-07 15:48:41 -0600 (Fri, 07 Nov 2008)
New Revision: 5018

Added:
   trunk/scipy/cluster/tests/linkage-Q-average.txt
   trunk/scipy/cluster/tests/linkage-Q-centroid.txt
   trunk/scipy/cluster/tests/linkage-Q-complete.txt
   trunk/scipy/cluster/tests/linkage-Q-median.txt
   trunk/scipy/cluster/tests/linkage-Q-single.txt
   trunk/scipy/cluster/tests/linkage-Q-ward.txt
   trunk/scipy/cluster/tests/linkage-Q-weighted.txt
Modified:
   trunk/scipy/cluster/tests/test_hierarchy.py
Log:
Added more tests for linkage functions.

Added: trunk/scipy/cluster/tests/linkage-Q-average.txt
===================================================================
--- trunk/scipy/cluster/tests/linkage-Q-average.txt	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/linkage-Q-average.txt	2008-11-07 21:48:41 UTC (rev 5018)
@@ -0,0 +1,29 @@
+   1.1000000e+01   1.8000000e+01   6.3937355e-02
+   1.4000000e+01   2.0000000e+01   1.7716924e-01
+   2.6000000e+01   2.7000000e+01   1.9481726e-01
+   2.0000000e+00   3.0000000e+00   2.4887981e-01
+   2.2000000e+01   2.3000000e+01   2.7739218e-01
+   7.0000000e+00   9.0000000e+00   3.0440560e-01
+   2.9000000e+01   3.3000000e+01   3.5174379e-01
+   6.0000000e+00   3.4000000e+01   3.5532162e-01
+   1.3000000e+01   3.2000000e+01   3.6158453e-01
+   1.5000000e+01   3.1000000e+01   3.7715616e-01
+   1.7000000e+01   1.9000000e+01   4.1203984e-01
+   2.4000000e+01   3.7000000e+01   4.2046824e-01
+   4.0000000e+00   3.6000000e+01   4.2863303e-01
+   1.0000000e+00   5.0000000e+00   4.8198330e-01
+   1.0000000e+01   3.8000000e+01   4.9787637e-01
+   4.0000000e+01   4.1000000e+01   5.2994677e-01
+   1.2000000e+01   3.9000000e+01   5.7421684e-01
+   2.5000000e+01   2.8000000e+01   6.2656347e-01
+   3.5000000e+01   4.2000000e+01   6.4347240e-01
+   4.6000000e+01   4.7000000e+01   6.8297315e-01
+   4.3000000e+01   4.5000000e+01   6.9186391e-01
+   8.0000000e+00   4.4000000e+01   7.4416964e-01
+   2.1000000e+01   3.0000000e+01   7.5491453e-01
+   1.6000000e+01   5.0000000e+01   8.1859847e-01
+   4.9000000e+01   5.3000000e+01   8.5939683e-01
+   5.1000000e+01   5.2000000e+01   8.7992146e-01
+   4.8000000e+01   5.5000000e+01   8.9017230e-01
+   5.4000000e+01   5.6000000e+01   2.0198221e+00
+   5.7000000e+01   5.8000000e+01   3.2920100e+00

Added: trunk/scipy/cluster/tests/linkage-Q-centroid.txt
===================================================================
--- trunk/scipy/cluster/tests/linkage-Q-centroid.txt	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/linkage-Q-centroid.txt	2008-11-07 21:48:41 UTC (rev 5018)
@@ -0,0 +1,29 @@
+   1.1000000e+01   1.8000000e+01   6.3937355e-02
+   1.4000000e+01   2.0000000e+01   1.7716924e-01
+   2.6000000e+01   2.7000000e+01   1.9481726e-01
+   2.0000000e+00   3.0000000e+00   2.4887981e-01
+   2.2000000e+01   2.3000000e+01   2.7739218e-01
+   7.0000000e+00   9.0000000e+00   3.0440560e-01
+   6.0000000e+00   3.4000000e+01   3.3746118e-01
+   2.9000000e+01   3.3000000e+01   3.4067653e-01
+   1.3000000e+01   3.2000000e+01   3.5113828e-01
+   1.5000000e+01   3.9000000e+01   3.3976558e-01
+   2.4000000e+01   3.8000000e+01   3.9064620e-01
+   4.0000000e+00   3.6000000e+01   4.0386341e-01
+   1.7000000e+01   1.9000000e+01   4.1203984e-01
+   1.0000000e+01   3.7000000e+01   4.6647208e-01
+   3.1000000e+01   4.3000000e+01   4.7930518e-01
+   1.0000000e+00   5.0000000e+00   4.8198330e-01
+   4.0000000e+01   4.5000000e+01   5.2671920e-01
+   3.5000000e+01   4.1000000e+01   5.9378517e-01
+   2.5000000e+01   2.8000000e+01   6.2656347e-01
+   4.2000000e+01   4.4000000e+01   6.2815954e-01
+   8.0000000e+00   4.6000000e+01   7.1857916e-01
+   5.0000000e+01   5.1000000e+01   7.0424537e-01
+   1.2000000e+01   4.7000000e+01   7.2968219e-01
+   1.6000000e+01   5.3000000e+01   7.1788349e-01
+   3.0000000e+01   4.9000000e+01   7.5478395e-01
+   4.8000000e+01   5.5000000e+01   7.0355234e-01
+   2.1000000e+01   5.6000000e+01   7.3561818e-01
+   5.2000000e+01   5.4000000e+01   1.9510405e+00
+   5.7000000e+01   5.8000000e+01   3.2347576e+00

Added: trunk/scipy/cluster/tests/linkage-Q-complete.txt
===================================================================
--- trunk/scipy/cluster/tests/linkage-Q-complete.txt	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/linkage-Q-complete.txt	2008-11-07 21:48:41 UTC (rev 5018)
@@ -0,0 +1,29 @@
+   1.1000000e+01   1.8000000e+01   6.3937355e-02
+   1.4000000e+01   2.0000000e+01   1.7716924e-01
+   2.6000000e+01   2.7000000e+01   1.9481726e-01
+   2.0000000e+00   3.0000000e+00   2.4887981e-01
+   2.2000000e+01   2.3000000e+01   2.7739218e-01
+   7.0000000e+00   9.0000000e+00   3.0440560e-01
+   1.3000000e+01   3.2000000e+01   3.8163338e-01
+   2.9000000e+01   3.3000000e+01   3.9446675e-01
+   1.5000000e+01   3.1000000e+01   3.9629062e-01
+   6.0000000e+00   3.4000000e+01   4.1110592e-01
+   1.7000000e+01   1.9000000e+01   4.1203984e-01
+   2.4000000e+01   2.8000000e+01   4.5328393e-01
+   4.0000000e+00   3.6000000e+01   4.7908167e-01
+   1.0000000e+00   5.0000000e+00   4.8198330e-01
+   1.0000000e+01   4.0000000e+01   5.7813912e-01
+   3.9000000e+01   4.1000000e+01   6.4162409e-01
+   3.0000000e+01   4.2000000e+01   6.6157735e-01
+   1.2000000e+01   3.7000000e+01   7.0851770e-01
+   2.1000000e+01   3.5000000e+01   7.8597665e-01
+   1.6000000e+01   4.6000000e+01   8.3623329e-01
+   8.0000000e+00   4.5000000e+01   8.8244371e-01
+   3.8000000e+01   4.7000000e+01   9.2493420e-01
+   2.5000000e+01   4.9000000e+01   9.2757043e-01
+   4.3000000e+01   5.1000000e+01   1.0046401e+00
+   4.8000000e+01   5.0000000e+01   1.1468365e+00
+   4.4000000e+01   5.4000000e+01   1.2396527e+00
+   5.2000000e+01   5.3000000e+01   1.2958546e+00
+   5.5000000e+01   5.7000000e+01   3.0467645e+00
+   5.6000000e+01   5.8000000e+01   5.1343343e+00

Added: trunk/scipy/cluster/tests/linkage-Q-median.txt
===================================================================
--- trunk/scipy/cluster/tests/linkage-Q-median.txt	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/linkage-Q-median.txt	2008-11-07 21:48:41 UTC (rev 5018)
@@ -0,0 +1,29 @@
+   1.1000000e+01   1.8000000e+01   6.3937355e-02
+   1.4000000e+01   2.0000000e+01   1.7716924e-01
+   2.6000000e+01   2.7000000e+01   1.9481726e-01
+   2.0000000e+00   3.0000000e+00   2.4887981e-01
+   2.2000000e+01   2.3000000e+01   2.7739218e-01
+   7.0000000e+00   9.0000000e+00   3.0440560e-01
+   6.0000000e+00   3.4000000e+01   3.3746118e-01
+   2.9000000e+01   3.3000000e+01   3.4067653e-01
+   1.3000000e+01   3.2000000e+01   3.5113828e-01
+   1.5000000e+01   3.9000000e+01   3.4054836e-01
+   4.0000000e+00   3.6000000e+01   4.0386341e-01
+   2.4000000e+01   3.8000000e+01   4.1015077e-01
+   1.7000000e+01   1.9000000e+01   4.1203984e-01
+   1.0000000e+01   3.7000000e+01   4.6883527e-01
+   3.1000000e+01   4.3000000e+01   4.7930518e-01
+   4.0000000e+01   4.5000000e+01   4.7776681e-01
+   1.0000000e+00   5.0000000e+00   4.8198330e-01
+   3.5000000e+01   4.2000000e+01   5.6937028e-01
+   2.5000000e+01   2.8000000e+01   6.2656347e-01
+   8.0000000e+00   4.7000000e+01   7.1857916e-01
+   4.8000000e+01   4.9000000e+01   7.1925426e-01
+   3.0000000e+01   5.1000000e+01   6.7611684e-01
+   2.1000000e+01   5.2000000e+01   6.6632819e-01
+   4.4000000e+01   5.0000000e+01   7.2115997e-01
+   4.1000000e+01   5.4000000e+01   6.5190047e-01
+   1.6000000e+01   4.6000000e+01   7.3662916e-01
+   1.2000000e+01   5.6000000e+01   7.0941723e-01
+   5.5000000e+01   5.7000000e+01   2.1188553e+00
+   5.3000000e+01   5.8000000e+01   3.2138035e+00

Added: trunk/scipy/cluster/tests/linkage-Q-single.txt
===================================================================
--- trunk/scipy/cluster/tests/linkage-Q-single.txt	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/linkage-Q-single.txt	2008-11-07 21:48:41 UTC (rev 5018)
@@ -0,0 +1,29 @@
+   1.1000000e+01   1.8000000e+01   6.3937355e-02
+   1.4000000e+01   2.0000000e+01   1.7716924e-01
+   2.6000000e+01   2.7000000e+01   1.9481726e-01
+   2.0000000e+00   3.0000000e+00   2.4887981e-01
+   2.2000000e+01   2.3000000e+01   2.7739218e-01
+   2.4000000e+01   3.3000000e+01   2.9703742e-01
+   6.0000000e+00   3.4000000e+01   2.9953732e-01
+   7.0000000e+00   9.0000000e+00   3.0440560e-01
+   1.5000000e+01   3.2000000e+01   3.0777762e-01
+   2.9000000e+01   3.6000000e+01   3.0902082e-01
+   1.9000000e+01   3.9000000e+01   3.3102505e-01
+   1.3000000e+01   4.1000000e+01   3.4153568e-01
+   3.1000000e+01   4.2000000e+01   3.5802170e-01
+   3.7000000e+01   3.8000000e+01   3.6459874e-01
+   4.0000000e+00   4.4000000e+01   3.7818440e-01
+   1.0000000e+01   4.5000000e+01   4.0129405e-01
+   1.7000000e+01   4.3000000e+01   4.1203984e-01
+   1.2000000e+01   4.7000000e+01   4.4459698e-01
+   2.8000000e+01   4.0000000e+01   4.5328393e-01
+   1.0000000e+00   5.0000000e+00   4.8198330e-01
+   4.6000000e+01   5.0000000e+01   5.0546088e-01
+   3.5000000e+01   4.9000000e+01   5.0591731e-01
+   3.0000000e+01   5.2000000e+01   5.9356257e-01
+   8.0000000e+00   5.1000000e+01   6.0048760e-01
+   2.5000000e+01   5.3000000e+01   6.2656347e-01
+   1.6000000e+01   4.8000000e+01   6.5449319e-01
+   2.1000000e+01   5.5000000e+01   7.0629051e-01
+   5.4000000e+01   5.6000000e+01   1.0267612e+00
+   5.7000000e+01   5.8000000e+01   1.2085488e+00

Added: trunk/scipy/cluster/tests/linkage-Q-ward.txt
===================================================================
--- trunk/scipy/cluster/tests/linkage-Q-ward.txt	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/linkage-Q-ward.txt	2008-11-07 21:48:41 UTC (rev 5018)
@@ -0,0 +1,29 @@
+   1.1000000e+01   1.8000000e+01   6.3937355e-02
+   1.4000000e+01   2.0000000e+01   1.7716924e-01
+   2.6000000e+01   2.7000000e+01   1.9481726e-01
+   2.0000000e+00   3.0000000e+00   2.4887981e-01
+   2.2000000e+01   2.3000000e+01   2.7739218e-01
+   7.0000000e+00   9.0000000e+00   3.0440560e-01
+   6.0000000e+00   3.4000000e+01   3.8966661e-01
+   2.9000000e+01   3.3000000e+01   3.9337938e-01
+   1.3000000e+01   1.5000000e+01   3.9833425e-01
+   1.7000000e+01   1.9000000e+01   4.1203984e-01
+   3.2000000e+01   3.9000000e+01   4.2295183e-01
+   2.4000000e+01   2.8000000e+01   4.5328393e-01
+   4.0000000e+00   3.6000000e+01   4.6634129e-01
+   1.0000000e+00   5.0000000e+00   4.8198330e-01
+   1.0000000e+01   3.7000000e+01   5.7130929e-01
+   3.0000000e+01   4.2000000e+01   6.7688894e-01
+   3.1000000e+01   4.0000000e+01   6.7783989e-01
+   1.2000000e+01   4.1000000e+01   7.1501676e-01
+   8.0000000e+00   4.4000000e+01   8.2974374e-01
+   2.1000000e+01   2.5000000e+01   8.3155740e-01
+   1.6000000e+01   4.7000000e+01   8.6628075e-01
+   3.5000000e+01   5.0000000e+01   9.1696168e-01
+   3.8000000e+01   4.6000000e+01   1.0741259e+00
+   4.3000000e+01   4.5000000e+01   1.1631255e+00
+   4.8000000e+01   5.1000000e+01   1.3123400e+00
+   5.2000000e+01   5.3000000e+01   1.3876562e+00
+   4.9000000e+01   5.4000000e+01   1.4432735e+00
+   5.5000000e+01   5.7000000e+01   6.1697318e+00
+   5.6000000e+01   5.8000000e+01   1.1811665e+01

Added: trunk/scipy/cluster/tests/linkage-Q-weighted.txt
===================================================================
--- trunk/scipy/cluster/tests/linkage-Q-weighted.txt	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/linkage-Q-weighted.txt	2008-11-07 21:48:41 UTC (rev 5018)
@@ -0,0 +1,29 @@
+   1.1000000e+01   1.8000000e+01   6.3937355e-02
+   1.4000000e+01   2.0000000e+01   1.7716924e-01
+   2.6000000e+01   2.7000000e+01   1.9481726e-01
+   2.0000000e+00   3.0000000e+00   2.4887981e-01
+   2.2000000e+01   2.3000000e+01   2.7739218e-01
+   7.0000000e+00   9.0000000e+00   3.0440560e-01
+   2.9000000e+01   3.3000000e+01   3.5174379e-01
+   6.0000000e+00   3.4000000e+01   3.5532162e-01
+   1.3000000e+01   3.2000000e+01   3.6158453e-01
+   1.5000000e+01   3.1000000e+01   3.7715616e-01
+   1.7000000e+01   1.9000000e+01   4.1203984e-01
+   4.0000000e+00   3.6000000e+01   4.2863303e-01
+   2.4000000e+01   3.7000000e+01   4.4128967e-01
+   1.0000000e+00   5.0000000e+00   4.8198330e-01
+   1.0000000e+01   3.8000000e+01   5.0195626e-01
+   4.0000000e+01   4.1000000e+01   5.3409020e-01
+   3.9000000e+01   4.6000000e+01   6.0088461e-01
+   2.5000000e+01   2.8000000e+01   6.2656347e-01
+   3.5000000e+01   4.3000000e+01   6.2840379e-01
+   8.0000000e+00   4.4000000e+01   7.4416964e-01
+   1.2000000e+01   4.7000000e+01   7.4874549e-01
+   2.1000000e+01   3.0000000e+01   7.5491453e-01
+   4.2000000e+01   4.5000000e+01   7.8567175e-01
+   4.8000000e+01   4.9000000e+01   8.3312410e-01
+   5.2000000e+01   5.4000000e+01   8.4939549e-01
+   1.6000000e+01   5.1000000e+01   8.5308187e-01
+   5.0000000e+01   5.3000000e+01   8.6159523e-01
+   5.5000000e+01   5.6000000e+01   1.9999532e+00
+   5.7000000e+01   5.8000000e+01   3.2929087e+00

Modified: trunk/scipy/cluster/tests/test_hierarchy.py
===================================================================
--- trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-07 21:26:07 UTC (rev 5017)
+++ trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-07 21:48:41 UTC (rev 5018)
@@ -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
+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.spatial.distance import squareform, pdist, numobs_dm, numobs_y
 
 _tdist = np.array([[0,    662,  877,  255,  412,  996],
@@ -76,7 +76,15 @@
               "inconsistent-weighted-tdist-depth-1.txt",
               "inconsistent-weighted-tdist-depth-2.txt",
               "inconsistent-weighted-tdist-depth-3.txt",
-              "inconsistent-weighted-tdist-depth-4.txt"]
+              "inconsistent-weighted-tdist-depth-4.txt",
+              "linkage-Q-average.txt",
+              "linkage-Q-complete.txt",
+              "linkage-Q-single.txt",
+              "linkage-Q-weighted.txt",
+              "linkage-Q-centroid.txt",
+              "linkage-Q-median.txt",
+              "linkage-Q-ward.txt"
+              ]
 
 def load_testing_files():
     for fn in _filenames:
@@ -156,6 +164,47 @@
         #print Z, expectedZ, np.abs(Z - expectedZ).max()
         self.failUnless(within_tol(Z, expectedZ, eps))
 
+    ################### linkage on Q
+    def test_linkage_single_q(self):
+        "Tests linkage(Y, 'single') on the Q data set."
+        X = eo['fclusterdata-X']
+        Z = single(X)
+        Zmlab = eo['linkage-Q-single']
+        eps = 1e-06
+        expectedZ = from_mlab_linkage(Zmlab)
+        print abs(Z-expectedZ).max()
+        self.failUnless(within_tol(Z, expectedZ, eps))
+
+    def test_linkage_complete_q(self):
+        "Tests linkage(Y, 'complete') on the Q data set."
+        X = eo['fclusterdata-X']
+        Z = complete(X)
+        Zmlab = eo['linkage-Q-complete']
+        eps = 1e-07
+        expectedZ = from_mlab_linkage(Zmlab)
+        print abs(Z-expectedZ).max()
+        self.failUnless(within_tol(Z, expectedZ, eps))
+
+    def test_linkage_centroid_q(self):
+        "Tests linkage(Y, 'centroid') on the Q data set."
+        X = eo['fclusterdata-X']
+        Z = centroid(X)
+        Zmlab = eo['linkage-Q-centroid']
+        eps = 1e-07
+        expectedZ = from_mlab_linkage(Zmlab)
+        print abs(Z-expectedZ).max()
+        self.failUnless(within_tol(Z, expectedZ, eps))
+
+    def test_linkage_weighted_q(self):
+        "Tests linkage(Y, 'weighted') on the Q data set."
+        X = eo['fclusterdata-X']
+        Z = weighted(X)
+        Zmlab = eo['linkage-Q-weighted']
+        eps = 1e-07
+        expectedZ = from_mlab_linkage(Zmlab)
+        print abs(Z-expectedZ).max()
+        self.failUnless(within_tol(Z, expectedZ, eps))
+
 class TestInconsistent(TestCase):
 
     def test_single_inconsistent_tdist(self):



More information about the Scipy-svn mailing list