# HG changeset patch # User Nicolas Saunier # Date 1356132816 18000 # Node ID f2cf16ad798f8364eadffc0407c9552db43854c5 # Parent dbe7e53334d712b24bc7d3557e920793ebcb6dc9 added LCSS for trajectories diff -r dbe7e53334d7 -r f2cf16ad798f python/moving.py --- a/python/moving.py Fri Dec 21 18:20:12 2012 -0500 +++ b/python/moving.py Fri Dec 21 18:33:36 2012 -0500 @@ -171,6 +171,12 @@ '2-norm distance (Euclidean distance)' return sqrt(self.norm2Squared()) + def norm1(self): + return abs(self.x)+abs(self.y) + + def normMax(self): + return max(abs(self.x),abs(self.y)) + def aslist(self): return [self.x, self.y] @@ -368,6 +374,9 @@ def length(self): return len(self.positions[0]) + def __len__(self): + return self.length() + def addPositionXY(self, x, y): self.positions[0].append(x) self.positions[1].append(y) @@ -496,6 +505,14 @@ # version 2: use shapely polygon contains + @staticmethod + def norm2LCSS(t1, t2, threshold): + return utils.LCSS(t1, t2, threshold, Point.distanceNorm2) + + @staticmethod + def normMaxLCSS(t1, t2, threshold): + return utils.LCSS(t1, t2, threshold, lambda p1, p2: (p1-p2).normMax()) + ################## # Moving Objects ################## diff -r dbe7e53334d7 -r f2cf16ad798f python/tests/moving.txt --- a/python/tests/moving.txt Fri Dec 21 18:20:12 2012 -0500 +++ b/python/tests/moving.txt Fri Dec 21 18:33:36 2012 -0500 @@ -74,3 +74,8 @@ (0.500000,0.500000) >>> t1.getTrajectoryInPolygon(np.array([[10,10],[14,10],[14,13],[10,13]])).length() 0 + +>>> Trajectory.norm2LCSS(t1, t1, 0.1) +3 +>>> Trajectory.normMaxLCSS(t1, t1, 0.1) +3 diff -r dbe7e53334d7 -r f2cf16ad798f python/utils.py --- a/python/utils.py Fri Dec 21 18:20:12 2012 -0500 +++ b/python/utils.py Fri Dec 21 18:33:36 2012 -0500 @@ -166,12 +166,12 @@ ######################### def LCSS(l1, l2, threshold, distance): - """returns the longest common subsequence similarity - based on the threshold on distance between two elements of lists l1, l2""" - from numpy import zeros + '''returns the longest common subsequence similarity + based on the threshold on distance between two elements of lists l1, l2''' + from numpy import zeros, int as npint m = len(l1) n = len(l2) - similarity = zeros((m+1,n+1)) + similarity = zeros((m+1,n+1), dtype = npint) for i in xrange(1,m+1): for j in xrange(1,n+1): if distance(l1[i-1], l2[j-1])