[aligner] clustering: Don't crash if sets are small.
authorSimon Chabot <simon.chabot@logilab.fr>
Mon, 26 Nov 2012 10:13:34 +0100
changeset 127 8f51d6d0c3be
parent 126 752233f1a0b3
child 128 228d0da19e3f
[aligner] clustering: Don't crash if sets are small.
aligner.py
--- a/aligner.py	Tue Nov 13 16:42:57 2012 +0100
+++ b/aligner.py	Mon Nov 26 10:13:34 2012 +0100
@@ -88,7 +88,8 @@
     #If an element is None (missing), use instead the identity element.
     #The identity element is defined as the 0-vector
     idelement = tuple([0 for _ in xrange(len(alignset[0][indexes[0]]))])
-    n_clusters = n_clusters or len(alignset) / 10
+    # We assume here that there are at least 2 elements in the alignset
+    n_clusters = n_clusters or (len(alignset)/10 or len(alignset)/2)
 
     if mode == 'kmeans':
         kmeans = cluster.KMeans(n_clusters=n_clusters)