comparison python/ml.py @ 917:89cc05867c4c

reorg and work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 04 Jul 2017 18:00:01 -0400
parents 7345f0d51faa
children d6c1c05d11f5
comparison
equal deleted inserted replaced
916:7345f0d51faa 917:89cc05867c4c
264 similarities[l][k] = similarities[k][l] 264 similarities[l][k] = similarities[k][l]
265 print('Mean similarity to prototype: {}'.format((similarities[prototypeIndices[i]][cluster].sum()+1)/(n-1))) 265 print('Mean similarity to prototype: {}'.format((similarities[prototypeIndices[i]][cluster].sum()+1)/(n-1)))
266 print('Mean overall similarity: {}'.format((similarities[cluster][:,cluster].sum()+n)/(n*(n-1)))) 266 print('Mean overall similarity: {}'.format((similarities[cluster][:,cluster].sum()+n)/(n*(n-1))))
267 267
268 # Gaussian Mixture Models 268 # Gaussian Mixture Models
269 def plotGMM(mean, covariance, num, fig, color, alpha = 0.3): 269 def plotGMM(mean, covariance, gmmId, fig, color, alpha = 0.3):
270 v, w = np.linalg.eigh(covariance) 270 v, w = np.linalg.eigh(covariance)
271 angle = 180*np.arctan2(w[0][1], w[0][0])/np.pi 271 angle = 180*np.arctan2(w[0][1], w[0][0])/np.pi
272 v *= 4 272 v *= 4
273 ell = mpl.patches.Ellipse(mean, v[0], v[1], 180+angle, color=color) 273 ell = mpl.patches.Ellipse(mean, v[0], v[1], 180+angle, color=color)
274 ell.set_clip_box(fig.bbox) 274 ell.set_clip_box(fig.bbox)
275 ell.set_alpha(alpha) 275 ell.set_alpha(alpha)
276 fig.axes[0].add_artist(ell) 276 fig.axes[0].add_artist(ell)
277 plt.plot([mean[0]], [mean[1]], 'x'+color) 277 plt.plot([mean[0]], [mean[1]], 'x'+color)
278 plt.annotate(str(num), xy=(mean[0]+1, mean[1]+1)) 278 plt.annotate(str(gmmId), xy=(mean[0]+1, mean[1]+1))
279 279
280 def plotGMMClusters(model, labels = None, dataset = None, fig = None, colors = utils.colors, nUnitsPerPixel = 1., alpha = 0.3): 280 def plotGMMClusters(model, labels = None, dataset = None, fig = None, colors = utils.colors, nUnitsPerPixel = 1., alpha = 0.3):
281 '''plot the ellipse corresponding to the Gaussians 281 '''plot the ellipse corresponding to the Gaussians
282 and the predicted classes of the instances in the dataset''' 282 and the predicted classes of the instances in the dataset'''
283 if fig is None: 283 if fig is None: