Mercurial Hosting > traffic-intelligence
comparison python/utils.py @ 279:3af4c267a7bf
generic simple LCSS
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 20 Dec 2012 18:04:05 -0500 |
parents | 78922b4de3bf |
children | 4f012e3d881b |
comparison
equal
deleted
inserted
replaced
278:f21ef87f98f1 | 279:3af4c267a7bf |
---|---|
162 | 162 |
163 | 163 |
164 ######################### | 164 ######################### |
165 # maths section | 165 # maths section |
166 ######################### | 166 ######################### |
167 | |
168 def LCSS(l1, l2, threshold, distance): | |
169 "returns the longest common subsequence similarity | |
170 based on the threshold on distance between two elements of lists l1, l2" | |
171 from numpy import zeros | |
172 m = len(l1) | |
173 n = len(l2) | |
174 similarity = zeros((m+1,n+1)) | |
175 for i in xrange(1,m+1): | |
176 for j in xrange(1,n+1): | |
177 if distance(l1[i], l2[i])<threshold: | |
178 similarity[i][j] = similarity(i-1, j-1)+1 | |
179 else: | |
180 similarity[i][j] = max(similarity[i-1][j], similarity[i][j-1]) | |
181 return similarity[-1][-1] | |
167 | 182 |
168 def framesToTime(nFrames, frameRate, initialTime = (0.,0.,0.)): | 183 def framesToTime(nFrames, frameRate, initialTime = (0.,0.,0.)): |
169 'returns hour, minutes and seconds' | 184 'returns hour, minutes and seconds' |
170 from math import floor | 185 from math import floor |
171 from datetime import time | 186 from datetime import time |