Mercurial Hosting > traffic-intelligence
changeset 518:0c86c73f3c09
median smoothing
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 18 Jun 2014 00:52:55 -0400 |
parents | 47d9970ee954 |
children | 4ad5123d969e |
files | python/utils.py |
diffstat | 1 files changed, 5 insertions(+), 0 deletions(-) [+] |
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]))