Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/learn-motion-patterns.py @ 844:5a68779d7777
added capability to save prototypes
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 14 Jul 2016 00:34:59 -0400 |
| parents | 5dc7a507353e |
| children | 0cb69238e6f5 |
comparison
equal
deleted
inserted
replaced
| 843:5dc7a507353e | 844:5a68779d7777 |
|---|---|
| 48 | 48 |
| 49 similarities = -np.ones((nTrajectories, nTrajectories)) | 49 similarities = -np.ones((nTrajectories, nTrajectories)) |
| 50 | 50 |
| 51 prototypeIndices, labels = ml.prototypeCluster(trajectories, similarities, args.minSimilarity, lambda x,y : lcss.computeNormalized(x, y), args.minClusterSize, args.randomInitialization) # this line can be called again without reinitializing similarities | 51 prototypeIndices, labels = ml.prototypeCluster(trajectories, similarities, args.minSimilarity, lambda x,y : lcss.computeNormalized(x, y), args.minClusterSize, args.randomInitialization) # this line can be called again without reinitializing similarities |
| 52 | 52 |
| 53 print(ml.computeClusterSizes(labels, prototypeIndices, -1)) | 53 clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1) |
| 54 print(clusterSizes) | |
| 55 | |
| 56 storage.savePrototypesToSqlite(args.databaseFilename, [objects[i].getNum() for i in prototypeIndices], args.trajectoryType, {objects[i].getNum():clusterSizes[i] for i in prototypeIndices}) | |
| 54 | 57 |
| 55 if args.saveSimilarities: | 58 if args.saveSimilarities: |
| 56 np.savetxt(utils.removeExtension(args.databaseFilename)+'-prototype-similarities.txt.gz', similarities, '%.4') | 59 np.savetxt(utils.removeExtension(args.databaseFilename)+'-prototype-similarities.txt.gz', similarities, '%.4f') |
| 57 | 60 |
| 58 if args.display: | 61 if args.display: |
| 59 from matplotlib.pyplot import figure, show | 62 from matplotlib.pyplot import figure, show, axis |
| 60 figure() | 63 figure() |
| 61 for i,o in enumerate(objects): | 64 for i,o in enumerate(objects): |
| 62 if i not in prototypeIndices: | 65 if i not in prototypeIndices: |
| 63 if labels[i] < 0: | 66 if labels[i] < 0: |
| 64 o.plot('kx') | 67 o.plot('kx') |
| 65 else: | 68 else: |
| 66 o.plot(utils.colors[labels[i]]) | 69 o.plot(utils.colors[labels[i]]) |
| 67 for i in prototypeIndices: | 70 for i in prototypeIndices: |
| 68 objects[i].plot(utils.colors[i]+'o') | 71 objects[i].plot(utils.colors[i]+'o') |
| 72 axis('equal') | |
| 69 show() | 73 show() |
| 70 | 74 |
| 71 # TODO store the prototypes trajectories, add option so store similarities (the most expensive stuff) with limited accuracy | 75 # TODO store the prototypes trajectories, add option so store similarities (the most expensive stuff) with limited accuracy |
