[Scipy-svn] r3075 - in trunk/Lib/cluster: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Fri Jun 8 00:09:31 EDT 2007
Author: cdavid
Date: 2007-06-07 23:09:24 -0500 (Thu, 07 Jun 2007)
New Revision: 3075
Modified:
trunk/Lib/cluster/tests/test_vq.py
trunk/Lib/cluster/vq.py
Log:
Modify kmeans2 arguments order so that they conform to the ones from kmeans
Modified: trunk/Lib/cluster/tests/test_vq.py
===================================================================
--- trunk/Lib/cluster/tests/test_vq.py 2007-06-08 02:36:11 UTC (rev 3074)
+++ trunk/Lib/cluster/tests/test_vq.py 2007-06-08 04:09:24 UTC (rev 3075)
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# David Cournapeau
-# Last Change: Sat May 05 06:00 PM 2007 J
+# Last Change: Fri Jun 08 12:00 PM 2007 J
# For now, just copy the tests from sandbox.pyem, so we can check that
# kmeans works OK for trivial examples.
@@ -72,6 +72,7 @@
# print _py_vq_1d(data, initc)
class test_kmean(NumpyTestCase):
+ #def check_kmeans
def check_kmeans_simple(self, level=1):
initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
@@ -93,8 +94,8 @@
"""Testing simple call to kmeans2 and its results."""
initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
- code1 = kmeans2(X, code, niter = 1)[0]
- code2 = kmeans2(X, code, niter = 2)[0]
+ code1 = kmeans2(X, code, iter = 1)[0]
+ code2 = kmeans2(X, code, iter = 2)[0]
assert_array_almost_equal(code1, CODET1)
assert_array_almost_equal(code2, CODET2)
Modified: trunk/Lib/cluster/vq.py
===================================================================
--- trunk/Lib/cluster/vq.py 2007-06-08 02:36:11 UTC (rev 3074)
+++ trunk/Lib/cluster/vq.py 2007-06-08 04:09:24 UTC (rev 3075)
@@ -466,7 +466,7 @@
_valid_init_meth = {'random': _krandinit, 'points': _kpoints}
-def kmeans2(data, k, minit='random', niter=10):
+def kmeans2(data, k, iter = 10, thresh = 1e-5, minit='random'):
"""Classify a set of points into k clusters using kmean algorithm.
The algorithm works by minimizing the euclidian distance between data points
@@ -481,6 +481,10 @@
k : int or ndarray
Number of clusters. If a ndarray is given instead, it is
interpreted as initial cluster to use instead.
+ niter : int
+ Number of iterations to run.
+ niter : float
+ (not used yet).
minit : string
Method for initialization. Available methods are random, points and
uniform:
@@ -493,9 +497,6 @@
uniform choses k points from the data such are they form a uniform
grid od the dataset.
- niter : int
- Number of iterations to run.
-
:Returns:
clusters : ndarray
the found clusters (one cluster per row).
@@ -535,8 +536,8 @@
raise ValueError("unknown init method %s" % str(minit))
clusters = init(data, k)
- assert not niter == 0
- return _kmeans2(data, clusters, niter, nc)
+ assert not iter == 0
+ return _kmeans2(data, clusters, iter, nc)
def _kmeans2(data, code, niter, nc):
""" "raw" version of kmeans2. Do not use directly.
More information about the Scipy-svn
mailing list