Mercurial Hosting > traffic-intelligence
comparison python/utils.py @ 284:f2cf16ad798f
added LCSS for trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 21 Dec 2012 18:33:36 -0500 |
parents | abbd4bc13dac |
children | 5957aa1d69e1 8e66ced156dd |
comparison
equal
deleted
inserted
replaced
283:dbe7e53334d7 | 284:f2cf16ad798f |
---|---|
164 ######################### | 164 ######################### |
165 # maths section | 165 # maths section |
166 ######################### | 166 ######################### |
167 | 167 |
168 def LCSS(l1, l2, threshold, distance): | 168 def LCSS(l1, l2, threshold, distance): |
169 """returns the longest common subsequence similarity | 169 '''returns the longest common subsequence similarity |
170 based on the threshold on distance between two elements of lists l1, l2""" | 170 based on the threshold on distance between two elements of lists l1, l2''' |
171 from numpy import zeros | 171 from numpy import zeros, int as npint |
172 m = len(l1) | 172 m = len(l1) |
173 n = len(l2) | 173 n = len(l2) |
174 similarity = zeros((m+1,n+1)) | 174 similarity = zeros((m+1,n+1), dtype = npint) |
175 for i in xrange(1,m+1): | 175 for i in xrange(1,m+1): |
176 for j in xrange(1,n+1): | 176 for j in xrange(1,n+1): |
177 if distance(l1[i-1], l2[j-1])<threshold: | 177 if distance(l1[i-1], l2[j-1])<threshold: |
178 similarity[i][j] = similarity[i-1][j-1]+1 | 178 similarity[i][j] = similarity[i-1][j-1]+1 |
179 else: | 179 else: |