Mercurial Hosting > traffic-intelligence
changeset 279:3af4c267a7bf
generic simple LCSS
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 20 Dec 2012 18:04:05 -0500 |
parents | f21ef87f98f1 |
children | 8d44fb1756bc |
files | python/utils.py |
diffstat | 1 files changed, 15 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/python/utils.py Fri Dec 14 01:01:55 2012 -0500 +++ b/python/utils.py Thu Dec 20 18:04:05 2012 -0500 @@ -165,6 +165,21 @@ # maths section ######################### +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 + m = len(l1) + n = len(l2) + similarity = zeros((m+1,n+1)) + for i in xrange(1,m+1): + for j in xrange(1,n+1): + if distance(l1[i], l2[i])<threshold: + similarity[i][j] = similarity(i-1, j-1)+1 + else: + similarity[i][j] = max(similarity[i-1][j], similarity[i][j-1]) + return similarity[-1][-1] + def framesToTime(nFrames, frameRate, initialTime = (0.,0.,0.)): 'returns hour, minutes and seconds' from math import floor