Mercurial Hosting > traffic-intelligence
diff 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 |
line wrap: on
line diff
--- a/python/utils.py Fri Jun 06 17:51:10 2014 -0400 +++ b/python/utils.py Wed Jun 18 00:52:55 2014 -0400 @@ -203,6 +203,11 @@ else: return 0. +def medianSmoothing(x, X, Y, halfwidth): + '''Returns the media of Y's corresponding to X's in the interval [x-halfwidth, x+halfwidth]''' + from numpy import median + return median([y for observedx, y in zip(X,Y) if abs(x-observedx)<halfwidth]) + def argMaxDict(d): return max(d.iterkeys(), key=(lambda key: d[key]))