Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 659:784298512b60
minor modifications
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 14 May 2015 23:18:44 +0200 |
| parents | c9a0b72979fd |
| children | 15e244d2a1b5 |
comparison
equal
deleted
inserted
replaced
| 658:6668f541b915 | 659:784298512b60 |
|---|---|
| 251 | 251 |
| 252 def cat_mvgavg(cat_list, halfWidth): | 252 def cat_mvgavg(cat_list, halfWidth): |
| 253 ''' Return a list of categories/values smoothed according to a window. | 253 ''' Return a list of categories/values smoothed according to a window. |
| 254 halfWidth is the search radius on either side''' | 254 halfWidth is the search radius on either side''' |
| 255 from copy import deepcopy | 255 from copy import deepcopy |
| 256 catgories = deepcopy(cat_list) | 256 smoothed = deepcopy(cat_list) |
| 257 smoothed = catgories | 257 for point in range(len(cat_list)): |
| 258 for point in range(len(catgories)): | |
| 259 lower_bound_check = max(0,point-halfWidth) | 258 lower_bound_check = max(0,point-halfWidth) |
| 260 upper_bound_check = min(len(catgories)-1,point+halfWidth+1) | 259 upper_bound_check = min(len(cat_list)-1,point+halfWidth+1) |
| 261 window_values = catgories[lower_bound_check:upper_bound_check] | 260 window_values = cat_list[lower_bound_check:upper_bound_check] |
| 262 smoothed[point] = max(set(window_values), key=window_values.count) | 261 smoothed[point] = max(set(window_values), key=window_values.count) |
| 263 return smoothed | 262 return smoothed |
| 264 | 263 |
| 265 def filterMovingWindow(inputSignal, halfWidth): | 264 def filterMovingWindow(inputSignal, halfWidth): |
| 266 '''Returns an array obtained after the smoothing of the input by a moving average | 265 '''Returns an array obtained after the smoothing of the input by a moving average |
