Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/learn-motion-patterns.py @ 1032:d0e339359d8a
work in progress
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 19 Jun 2018 17:07:50 -0400 |
| parents | cc5cb04b04b0 |
| children | 8ffb3ae9f3d2 |
comparison
equal
deleted
inserted
replaced
| 1031:045cb04ad7b8 | 1032:d0e339359d8a |
|---|---|
| 73 similarities = -np.ones((nTrajectories, nTrajectories)) | 73 similarities = -np.ones((nTrajectories, nTrajectories)) |
| 74 similarityFunc = lambda x,y : lcss.computeNormalized(x, y) | 74 similarityFunc = lambda x,y : lcss.computeNormalized(x, y) |
| 75 # the next line can be called again without reinitializing similarities | 75 # the next line can be called again without reinitializing similarities |
| 76 if args.learn: | 76 if args.learn: |
| 77 prototypeIndices = ml.prototypeCluster(trajectories, similarities, args.minSimilarity, similarityFunc, args.optimizeCentroid, args.randomInitialization, initialPrototypeIndices) | 77 prototypeIndices = ml.prototypeCluster(trajectories, similarities, args.minSimilarity, similarityFunc, args.optimizeCentroid, args.randomInitialization, initialPrototypeIndices) |
| 78 # assignment is done if explicitly passed as argument or if working on the same database (starting prototypes from scratch and assigning them) | |
| 79 else: | 78 else: |
| 80 prototypeIndices = initialPrototypeIndices | 79 prototypeIndices = initialPrototypeIndices |
| 81 | 80 |
| 82 if args.assign: | 81 if args.assign: |
| 82 if not args.learn and args.minClusterSize >= 1: | |
| 83 print('Warning: you did not learn the prototypes and you are using minimum cluster size of {}, which may lead to removing prototypes and assigning them to others'.format(args.minClusterSize)) | |
| 83 prototypeIndices, labels = ml.assignToPrototypeClusters(trajectories, prototypeIndices, similarities, args.minSimilarity, similarityFunc, args.minClusterSize) | 84 prototypeIndices, labels = ml.assignToPrototypeClusters(trajectories, prototypeIndices, similarities, args.minSimilarity, similarityFunc, args.minClusterSize) |
| 84 clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1) | 85 clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1) |
| 85 print(clusterSizes) | 86 print(clusterSizes) |
| 86 | 87 |
| 87 if args.learn or args.assign: | 88 if args.learn or args.assign: |
| 88 prototypes = [] | 89 prototypes = [] |
| 89 for i in prototypeIndices: | 90 for i in prototypeIndices: |
| 90 if args.assign: | 91 if args.assign: |
| 91 nMatchings = clusterSizes[i]-1 | 92 nMatchings = clusterSizes[i]-1 |
| 92 else: | 93 #else: |
| 93 nMatchings = 0 | 94 # nMatchings = 0 |
| 94 if i<len(initialPrototypes): | 95 if i<len(initialPrototypes): |
| 95 initialPrototypes[i].nMatchings += nMatchings | 96 if args.assign: |
| 97 initialPrototypes[i].nMatchings += nMatchings | |
| 96 prototypes.append(initialPrototypes[i]) | 98 prototypes.append(initialPrototypes[i]) |
| 97 else: | 99 else: |
| 98 prototypes.append(moving.Prototype(args.databaseFilename, objects[i-len(initialPrototypes)].getNum(), trajectoryType, nMatchings)) | 100 prototypes.append(moving.Prototype(args.databaseFilename, objects[i-len(initialPrototypes)].getNum(), trajectoryType, nMatchings)) |
| 99 | 101 |
| 100 if args.outputPrototypeDatabaseFilename is None: | 102 if args.outputPrototypeDatabaseFilename is None: |
