Mercurial Hosting > traffic-intelligence
comparison python/utils.py @ 307:8e66ced156dd
add delta to sample the time window in LCSS function
author | Mohamed Gomaa |
---|---|
date | Tue, 25 Dec 2012 02:16:10 -0500 |
parents | f2cf16ad798f |
children | 6c068047edbf |
comparison
equal
deleted
inserted
replaced
284:f2cf16ad798f | 307:8e66ced156dd |
---|---|
163 | 163 |
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, delta, 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 looks for points that are sampled within a delta time window, can put 'inf' value to cancl this condition''' | |
171 from numpy import zeros, int as npint | 172 from numpy import zeros, int as npint |
172 m = len(l1) | 173 m = len(l1) |
173 n = len(l2) | 174 n = len(l2) |
174 similarity = zeros((m+1,n+1), dtype = npint) | 175 similarity = zeros((m+1,n+1), dtype = npint) |
175 for i in xrange(1,m+1): | 176 for i in xrange(1,m+1): |
176 for j in xrange(1,n+1): | 177 for j in xrange(1,n+1): |
177 if distance(l1[i-1], l2[j-1])<threshold: | 178 from math import fabs |
178 similarity[i][j] = similarity[i-1][j-1]+1 | 179 while fabs(i-j)<= delta: |
179 else: | 180 if distance(l1[i-1], l2[j-1])<threshold: |
180 similarity[i][j] = max(similarity[i-1][j], similarity[i][j-1]) | 181 similarity[i][j] = similarity[i-1][j-1]+1 |
182 else: | |
183 similarity[i][j] = max(similarity[i-1][j], similarity[i][j-1]) | |
181 return similarity[-1][-1] | 184 return similarity[-1][-1] |
182 | 185 |
183 def framesToTime(nFrames, frameRate, initialTime = (0.,0.,0.)): | 186 def framesToTime(nFrames, frameRate, initialTime = (0.,0.,0.)): |
184 'returns hour, minutes and seconds' | 187 'returns hour, minutes and seconds' |
185 from math import floor | 188 from math import floor |