comparison python/ml.py @ 949:d6c1c05d11f5

modified multithreading at the interaction level for safety computations
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 21 Jul 2017 17:52:56 -0400
parents 89cc05867c4c
children a9b2beef0db4
comparison
equal deleted inserted replaced
948:584b9405e494 949:d6c1c05d11f5
180 it will become a new prototype. 180 it will become a new prototype.
181 Non-prototype instances will be assigned to an existing prototype 181 Non-prototype instances will be assigned to an existing prototype
182 182
183 if optimizeCentroid is True, each time an element is added, we recompute the centroid trajectory as the most similar to all in the cluster 183 if optimizeCentroid is True, each time an element is added, we recompute the centroid trajectory as the most similar to all in the cluster
184 184
185 initialPrototypeIndices are indices in instances
186
185 TODO: check how similarity evolves in clusters''' 187 TODO: check how similarity evolves in clusters'''
186 if len(instances) == 0: 188 if len(instances) == 0:
187 print('no instances to cluster (empty list)') 189 print('no instances to cluster (empty list)')
188 return None 190 return None
189 if similarityFunc is None: 191 if similarityFunc is None:
209 prototypeIndices = [indices[0]] 211 prototypeIndices = [indices[0]]
210 else: 212 else:
211 prototypeIndices = initialPrototypeIndices # think of the format: if indices, have to be in instances 213 prototypeIndices = initialPrototypeIndices # think of the format: if indices, have to be in instances
212 for i in prototypeIndices: 214 for i in prototypeIndices:
213 clusters.append([i]) 215 clusters.append([i])
214 for i in indices[1:]: 216 indices.remove(i)
217 for i in indices:
215 for j in prototypeIndices: 218 for j in prototypeIndices:
216 if similarities[i][j] < 0: 219 if similarities[i][j] < 0:
217 similarities[i][j] = similarityFunc(instances[i], instances[j]) 220 similarities[i][j] = similarityFunc(instances[i], instances[j])
218 similarities[j][i] = similarities[i][j] 221 similarities[j][i] = similarities[i][j]
219 label = similarities[i][prototypeIndices].argmax() 222 label = similarities[i][prototypeIndices].argmax()