diff trafficintelligence/utils.py @ 1276:bae8de98406f

corrected bug in categorical value smoothing
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 25 Jun 2024 16:40:40 -0400
parents ad60e5adf084
children
line wrap: on
line diff
--- a/trafficintelligence/utils.py	Wed Jun 19 16:11:35 2024 -0400
+++ b/trafficintelligence/utils.py	Tue Jun 25 16:40:40 2024 -0400
@@ -420,15 +420,16 @@
 def crossProduct(l1, l2):
     return l1[0]*l2[1]-l1[1]*l2[0]
 
-def filterCategoricalMovingWindow(cat_list, halfWidth):
+def filterCategoricalMovingWindow(categoricalList, halfWidth):
     ''' Return a list of categories/values smoothed according to a window. 
         halfWidth is the search radius on either side'''
-    smoothed = deepcopy(cat_list)
-    for point in range(len(cat_list)):
-        lower_bound_check = max(0,point-halfWidth)
-        upper_bound_check = min(len(cat_list)-1,point+halfWidth+1)
-        window_values = cat_list[lower_bound_check:upper_bound_check]
-        smoothed[point] = max(set(window_values), key=window_values.count)
+    length = len(categoricalList)
+    smoothed = [0]*length
+    for point in range(length):
+        lowerBound = max(0,point-halfWidth)
+        upperBound = min(length,point+halfWidth+1)
+        window = categoricalList[lowerBound:upperBound]
+        smoothed[point] = max(set(window), key=window.count)
     return smoothed
 
 def filterMovingWindow(inputSignal, halfWidth):