diff python/ml.py @ 293:ee3302528cdc

rearranged new code by Paul (works now)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 08 Feb 2013 18:13:29 -0500
parents 5957aa1d69e1
children 6c068047edbf
line wrap: on
line diff
--- a/python/ml.py	Wed Feb 06 20:39:14 2013 -0500
+++ b/python/ml.py	Fri Feb 08 18:13:29 2013 -0500
@@ -58,7 +58,7 @@
 
     return centroids
 
-def spectralClustering(similarityMatrix,k):	
+def spectralClustering(similarityMatrix, k, iter=20):
 	'''Spectral Clustering algorithm'''
 	n = len(similarityMatrix)
 	# create Laplacian matrix
@@ -74,6 +74,6 @@
 	# k-means
 	from scipy.cluster.vq import kmeans, whiten, vq
 	features = whiten(features)
-	centroids,distortion = kmeans(features,k,iter=20) # default iter = 20
+	centroids,distortion = kmeans(features,k, iter)
 	code,distance = vq(features,centroids) # code starting from 0 (represent first cluster) to k-1 (last cluster)
 	return code,sigma