Mercurial > hg > nsaunier > traffic-intelligence
comparison python/prediction.py @ 946:e5970606066f
bug fix on list filtering (cannot remove while iterating) and motion prediction keeping the same features
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 21 Jul 2017 11:25:20 -0400 |
| parents | 05d4302bf67e |
| children | 584b9405e494 |
comparison
equal
deleted
inserted
replaced
| 945:05d4302bf67e | 946:e5970606066f |
|---|---|
| 573 | 573 |
| 574 def generatePredictedTrajectories(self, obj, instant): | 574 def generatePredictedTrajectories(self, obj, instant): |
| 575 predictedTrajectories = [] | 575 predictedTrajectories = [] |
| 576 if instant-obj.getFirstInstant()+1 >= self.minFeatureTime: | 576 if instant-obj.getFirstInstant()+1 >= self.minFeatureTime: |
| 577 if self.useFeatures and obj.hasFeatures(): | 577 if self.useFeatures and obj.hasFeatures(): |
| 578 # get current features existing for the most time, sort on first instant of feature and take n first | 578 if not hasattr(obj, 'currentPredictionFeatures'): |
| 579 firstInstants = [(f,f.getFirstInstant()) for f in obj.getFeatures() if f.existsAtInstant(instant)] | 579 obj.currentPredictionFeatures = [] |
| 580 else: | |
| 581 obj.currentPredictionFeatures[:] = [f for f in obj.currentPredictionFeatures if f.existsAtInstant(instant)] | |
| 582 firstInstants = [(f,f.getFirstInstant()) for f in obj.getFeatures() if f.existsAtInstant(instant) and f not in obj.currentPredictionFeatures] | |
| 580 firstInstants.sort(key = lambda t: t[1]) | 583 firstInstants.sort(key = lambda t: t[1]) |
| 581 for f,t1 in firstInstants[:min(self.nPredictedTrajectories, len(firstInstants))]: | 584 for f,t1 in firstInstants[:min(self.nPredictedTrajectories, len(firstInstants), self.nPredictedTrajectories-len(obj.currentPredictionFeatures))]: |
| 585 obj.currentPredictionFeatures.append(f) | |
| 586 print len(obj.currentPredictionFeatures), self.nPredictedTrajectories | |
| 587 for f in obj.currentPredictionFeatures: | |
| 582 self.addPredictedTrajectories(predictedTrajectories, f, instant) | 588 self.addPredictedTrajectories(predictedTrajectories, f, instant) |
| 583 else: | 589 else: |
| 584 self.addPredictedTrajectories(predictedTrajectories, obj, instant) | 590 self.addPredictedTrajectories(predictedTrajectories, obj, instant) |
| 585 return predictedTrajectories | 591 return predictedTrajectories |
| 586 | 592 |
