Mercurial Hosting > traffic-intelligence
comparison python/utils.py @ 518:0c86c73f3c09
median smoothing
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 18 Jun 2014 00:52:55 -0400 |
parents | ad518f0c3218 |
children | 3707eeb20f25 |
comparison
equal
deleted
inserted
replaced
517:47d9970ee954 | 518:0c86c73f3c09 |
---|---|
200 diff = abs(center-x) | 200 diff = abs(center-x) |
201 if diff<halfwidth: | 201 if diff<halfwidth: |
202 return 1.-abs(diff/halfwidth) | 202 return 1.-abs(diff/halfwidth) |
203 else: | 203 else: |
204 return 0. | 204 return 0. |
205 | |
206 def medianSmoothing(x, X, Y, halfwidth): | |
207 '''Returns the media of Y's corresponding to X's in the interval [x-halfwidth, x+halfwidth]''' | |
208 from numpy import median | |
209 return median([y for observedx, y in zip(X,Y) if abs(x-observedx)<halfwidth]) | |
205 | 210 |
206 def argMaxDict(d): | 211 def argMaxDict(d): |
207 return max(d.iterkeys(), key=(lambda key: d[key])) | 212 return max(d.iterkeys(), key=(lambda key: d[key])) |
208 | 213 |
209 def framesToTime(nFrames, frameRate, initialTime = time()): | 214 def framesToTime(nFrames, frameRate, initialTime = time()): |