Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 375:2ea8584aa80a
making indicator LCSS work
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 17 Jul 2013 01:29:25 -0400 |
| parents | a7af3519687e |
| children | 2e6b8610bcaa |
comparison
equal
deleted
inserted
replaced
| 374:a7af3519687e | 375:2ea8584aa80a |
|---|---|
| 287 | 287 |
| 288 def compute(self, l1, l2, computeSubSequence = False): | 288 def compute(self, l1, l2, computeSubSequence = False): |
| 289 '''get methods are to be shadowed in child classes ''' | 289 '''get methods are to be shadowed in child classes ''' |
| 290 return self._compute(l1, l2, computeSubSequence) | 290 return self._compute(l1, l2, computeSubSequence) |
| 291 | 291 |
| 292 def computeAlignement(self): | 292 def computeAlignment(self): |
| 293 from numpy import mean | 293 from numpy import mean |
| 294 return mean([j-i for i,j in self.subSequenceIndices]) | 294 return mean([j-i for i,j in self.subSequenceIndices]) |
| 295 | 295 |
| 296 def _computeNormalized(self, l1, l2): | 296 def _computeNormalized(self, l1, l2): |
| 297 ''' compute the normalized LCSS | 297 ''' compute the normalized LCSS |
| 298 ie, the LCSS divided by the min or mean of the indicator lengths (using lengthFunc) | 298 ie, the LCSS divided by the min or mean of the indicator lengths (using lengthFunc) |
| 299 lengthFunc = lambda x,y:float(x,y)/2''' | 299 lengthFunc = lambda x,y:float(x,y)/2''' |
| 300 return float(self.compute(l1, l2))/self.lengthFunc(len(l1), len(l2)) | 300 return float(self._compute(l1, l2))/self.lengthFunc(len(l1), len(l2)) |
| 301 | 301 |
| 302 def computeNormalized(self, l1, l2): | 302 def computeNormalized(self, l1, l2): |
| 303 return self._computeNormalized(l1, l2) | 303 return self._computeNormalized(l1, l2) |
| 304 | 304 |
| 305 def _computeDistance(self, l1, l2): | 305 def _computeDistance(self, l1, l2): |
| 306 ''' compute the LCSS distance''' | 306 ''' compute the LCSS distance''' |
| 307 return 1-self.computeNormalized(l1, l2) | 307 return 1-self._computeNormalized(l1, l2) |
| 308 | 308 |
| 309 def computeDistance(self, l1, l2): | 309 def computeDistance(self, l1, l2): |
| 310 return self._computeDistance(l1, l2) | 310 return self._computeDistance(l1, l2) |
| 311 | 311 |
| 312 ######################### | 312 ######################### |
