[Scipy-svn] r2293 - trunk/Lib/cluster/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Oct 23 02:39:11 CDT 2006


Author: cdavid
Date: 2006-10-23 02:39:07 -0500 (Mon, 23 Oct 2006)
New Revision: 2293

Added:
   trunk/Lib/cluster/tests/test_vq.py
Log:
 cluster.vq: add a test for kmeans (copied from pyem)



Added: trunk/Lib/cluster/tests/test_vq.py
===================================================================
--- trunk/Lib/cluster/tests/test_vq.py	2006-10-20 11:05:22 UTC (rev 2292)
+++ trunk/Lib/cluster/tests/test_vq.py	2006-10-23 07:39:07 UTC (rev 2293)
@@ -0,0 +1,45 @@
+#! /usr/bin/env python
+
+# David Cournapeau
+# Last Change: Mon Oct 23 04:00 PM 2006 J
+
+# For now, just copy the tests from sandbox.pyem, so we can check that
+# kmeans works OK for trivial examples.
+
+import sys
+from numpy.testing import *
+
+import numpy as N
+
+set_package_path()
+from cluster.vq import kmeans
+restore_path()
+
+# #Optional:
+# set_local_path()
+# # import modules that are located in the same directory as this file.
+# restore_path()
+
+# Global data
+X   = N.array([[3.0, 3], [4, 3], [4, 2],
+        [9, 2], [5, 1], [6, 2], [9, 4], 
+        [5, 2], [5, 4], [7, 4], [6, 5]])
+
+codet1  = N.array([[3.0000, 3.0000],
+        [6.2000, 4.0000], 
+        [5.8000, 1.8000]])
+        
+codet2  = N.array([[11.0/3, 8.0/3], 
+        [6.7500, 4.2500],
+        [6.2500, 1.7500]])
+
+class test_kmean(NumpyTestCase):
+    def check_kmeans(self, level=1):
+        initc   = N.concatenate(([[X[0]], [X[1]], [X[2]]])) 
+        code    = initc.copy()
+        code1   = kmeans(X, code)[0]
+
+        assert_array_almost_equal(code1, codet2)
+
+if __name__ == "__main__":
+    NumpyTest().run()



More information about the Scipy-svn mailing list