Commits

Alexander Konovalov committed 6f46e2e

Features in entries, move mkdir_p to util.py, slight change in Model interface.

  • Participants
  • Parent commits 326790e

Comments (0)

Files changed (4)

baseline_models.py

 class Baseline1Model:
     def learn(self, learn_set):
         pass
-    def predict(self, time, mouse, click):
+    def predict(self, entry):
+        time, mouse, click, features = entry.time, entry.mouse, entry.click, entry.features
         return mouse
 
 class Baseline2Model:
         self.sy = x
 
 
-    def predict(self, time, mouse, click):
+    def predict(self, entry):
+        time, mouse, click, features = entry.time, entry.mouse, entry.click, entry.features
         import numpy as np
 
         cx, cy = mouse[:,0], mouse[:,1]
         self.sy = x
 
 
-    def predict(self, time, mouse, click):
+    def predict(self, entry):
+        time, mouse, click, features = entry.time, entry.mouse, entry.click, entry.features
         import numpy as np
 
         t = (time - time[0]) / 1000.0
         self.sy = x
 
 
-    def predict(self, time, mouse, click):
+    def predict(self, entry):
+        time, mouse, click, features = entry.time, entry.mouse, entry.click, entry.features
         import numpy as np
 
         cx, cy = mouse[:,0], mouse[:,1]
 
     return data
 
-def mkdir_p(path):
-    """ http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python """
-    try:
-        os.makedirs(path)
-    except OSError as exc: # Python >2.5
-        if exc.errno == errno.EEXIST and os.path.isdir(path):
-            pass
-        else: raise
-
-def normalizeData(entry):
+def compress_frames_with_same_timestamp(entry):
     def group_mean(values, groups, axis=0):
         return group_map(lambda x: numpy.mean(x, axis=axis), values, groups, axis)
     def group_max(values, groups, axis=0):
     entry.gaze = group_mean(entry.gaze, groups)
     entry.click = group_max(entry.click, groups)
 
+def normalizeData(entry):
+    compress_frames_with_same_timestamp(entry)
+
 if __name__ == "__main__":
     data = read_data("data/DATA")
 
         future_value = future_average(t, mouse, 1.0, 0.2)
 
         return (
-            dwell_time_logarithm, 
-            movement_flag, 
+            dwell_time_logarithm,
+            movement_flag,
             log_time_since_last_movement,
             future_value)
 
         self.sy = x
 
 
-    def predict(self, time, mouse, click):
+    def predict(self, entry):
+        time, mouse, click, features = entry.time, entry.mouse, entry.click, entry.features
         import numpy as np
 
         cx, cy = mouse[:,0], mouse[:,1]
 import bisect
 import copy
 import itertools
+import os, os.path, errno
+
+def mkdir_p(path):
+    """ http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python """
+    try:
+        os.makedirs(path)
+    except OSError as exc: # Python >2.5
+        if exc.errno == errno.EEXIST and os.path.isdir(path):
+            pass
+        else: raise
 
 class Entry:
-    __slots__ = ["time", "gaze", "mouse", "click"]
+    __slots__ = ["time", "gaze", "mouse", "click", "features"]
 
     def __init__(self):
         self.time = []
         self.gaze = [[], []]
         self.mouse = [[], []]
         self.click = []
+        self.features = []
 
 def rmse(a, b):
     assert a.shape == b.shape