Mercurial Hosting > traffic-intelligence
changeset 284:f2cf16ad798f
added LCSS for trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 21 Dec 2012 18:33:36 -0500 |
parents | dbe7e53334d7 |
children | 5957aa1d69e1 8e66ced156dd |
files | python/moving.py python/tests/moving.txt python/utils.py |
diffstat | 3 files changed, 26 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 ##################
--- 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
--- 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])<threshold: