# HG changeset patch # User Nicolas Saunier # Date 1403300732 14400 # Node ID 21bdeb29f8558045f9784c41567b82ca97e8c52b # Parent 7124c7d2a6630b7f947294e1dedbd30717392234 corrected bug in initialization of lists and loading trajectories from vissim files diff -r 7124c7d2a663 -r 21bdeb29f855 python/events.py --- a/python/events.py Fri Jun 20 00:20:29 2014 -0400 +++ b/python/events.py Fri Jun 20 17:45:32 2014 -0400 @@ -303,7 +303,7 @@ lists.append(j.num) return lists - def getCPlist(self,indicatorThreshold=99999): + def getCPlist(self,indicatorThreshold=float('Inf')): lists = [] for j in self.pairs: if(j.hasCP): @@ -312,7 +312,7 @@ lists.append([k,j.CP[k][0]]) return lists - def getCZlist(self,indicatorThreshold=99999): + def getCZlist(self,indicatorThreshold=float('Inf')): lists = [] for j in self.pairs: if(j.hasCZ): diff -r 7124c7d2a663 -r 21bdeb29f855 python/ml.py --- a/python/ml.py Fri Jun 20 00:20:29 2014 -0400 +++ b/python/ml.py Fri Jun 20 17:45:32 2014 -0400 @@ -58,7 +58,7 @@ Either the initialCentroids or k are passed''' pass -def assignCluster(data, similarFunc, initialCentroids = [], shuffleData = True): +def assignCluster(data, similarFunc, initialCentroids = None, shuffleData = True): '''k-means algorithm with similarity function Two instances should be in the same cluster if the sameCluster function returns true for two instances. It is supposed that the average centroid of a set of instances can be computed, using the function. The number of clusters will be determined accordingly @@ -71,10 +71,10 @@ localdata = copy(data) # shallow copy to avoid modifying data if shuffleData: shuffle(localdata) - if initialCentroids: + if initialCentroids == None: + centroids = [Centroid(localdata[0])] + else: centroids = deepcopy(initialCentroids) - else: - centroids = [Centroid(localdata[0])] for instance in localdata[1:]: i = 0 while i 0 and len(objects) > nObjects: + return objects.values()[:nObjects] return objects.values()