diff scripts/learn-poi.py @ 913:1cd878812529

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 28 Jun 2017 17:57:06 -0400
parents 6db83beb5350
children f228fd649644
line wrap: on
line diff
--- a/scripts/learn-poi.py	Wed Jun 28 16:51:17 2017 -0400
+++ b/scripts/learn-poi.py	Wed Jun 28 17:57:06 2017 -0400
@@ -17,6 +17,7 @@
 parser.add_argument('-w', dest = 'worldImageFilename', help = 'filename of the world image')
 parser.add_argument('-u', dest = 'unitsPerPixel', help = 'number of units of distance per pixel', type = float, default = 1.)
 parser.add_argument('--display', dest = 'display', help = 'display points of interests', action = 'store_true') # default is manhattan distance
+parser.add_argument('--assign', dest = 'display', help = 'display points of interests', action = 'store_true') # default is manhattan distance
 
 args = parser.parse_args()
 
@@ -37,11 +38,11 @@
 
 gmmId=0
 for nClusters, points, gmmType in zip([args.nOriginClusters, nDestinationClusters],
-                                   [beginnings, ends],
-                                   ['beginning', 'end']):
+                                      [beginnings, ends],
+                                      ['beginning', 'end']):
     # estimation
     gmm = mixture.GaussianMixture(n_components=nClusters, covariance_type = args.covarianceType)
-    model=gmm.fit(beginnings)
+    model=gmm.fit(points)
     if not model.converged_:
         print('Warning: model for '+gmmType+' points did not converge')
     # plot
@@ -50,12 +51,16 @@
         if args.worldImageFilename is not None and args.unitsPerPixel is not None:
             img = plt.imread(args.worldImageFilename)
             plt.imshow(img)
-        labels = ml.plotGMMClusters(model, points, fig, nUnitsPerPixel = args.unitsPerPixel)
+        labels = model.predict(points)
+        labels = ml.plotGMMClusters(model, labels, points, fig, nUnitsPerPixel = args.unitsPerPixel)
         plt.axis('image')
         plt.title(gmmType)
         print(gmmType+' Clusters:\n{}'.format(ml.computeClusterSizes(labels, range(model.n_components))))
     # save
     storage.savePOIs(args.databaseFilename, model, gmmType, gmmId)
+    # save assignments
+    if args.assign:
+        pass
     gmmId += 1
 
 if args.display: