diff scripts/learn-motion-patterns.py @ 927:c030f735c594

added assignment of trajectories to prototypes and cleanup of insert queries
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 11 Jul 2017 17:56:23 -0400
parents acb5379c5fd7
children 584b9405e494
line wrap: on
line diff
--- a/scripts/learn-motion-patterns.py	Mon Jul 10 18:04:41 2017 -0400
+++ b/scripts/learn-motion-patterns.py	Tue Jul 11 17:56:23 2017 -0400
@@ -24,7 +24,8 @@
 parser.add_argument('--subsample', dest = 'positionSubsamplingRate', help = 'rate of position subsampling (1 every n positions)', type = int)
 parser.add_argument('--display', dest = 'display', help = 'display trajectories', action = 'store_true')
 parser.add_argument('--save-similarities', dest = 'saveSimilarities', help = 'save computed similarities (in addition to prototypes)', action = 'store_true')
-#parser.add_argument('--save-matches', dest = 'saveMatches', help = 'save the matched prototype information', action = 'store_true')
+parser.add_argument('--save-matches', dest = 'saveMatches', help = 'saves the assignments of the objects (not for features) to the prototypes', action = 'store_true')
+#parser.add_argument('--assign', dest = 'assign', help = 'saves the assignments of the objects (not for features) to the prototypes', action = 'store_true') # default is train, but one could want only to assign the objects to the loaded prototypes without learning
 
 args = parser.parse_args()
 
@@ -70,7 +71,6 @@
 clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1)
 print(clusterSizes)
 
-
 prototypes = [moving.Prototype(args.databaseFilename, objects[i].getNum(), prototypeType, clusterSizes[i]) for i in prototypeIndices]
 if args.outputPrototypeDatabaseFilename is None:
     outputPrototypeDatabaseFilename = args.databaseFilename
@@ -81,10 +81,11 @@
 if args.saveSimilarities:
     np.savetxt(utils.removeExtension(args.databaseFilename)+'-prototype-similarities.txt.gz', similarities, '%.4f')
 
-# if args.saveMatches:
-#     out = storage.openCheck(utils.removeExtension(args.databaseFilename)+'prototypes-matches.csv', 'w')
-#     for o in ojbects:
-#         out.write('')
+labelsToProtoIndices = {protoId: i for i, protoId in enumerate(prototypeIndices)}
+if args.saveMatches: # or args.assign
+# save in the db that contained originally the data
+    # retirer les assignations anterieures?
+    storage.savePrototypeAssignmentsToSqlite(args.databaseFilename, objects, [labelsToProtoIndices[l] for l in labels], prototypes)
 
 if args.display:
     from matplotlib.pyplot import figure, show, axis