# HG changeset patch # User Nicolas Saunier # Date 1359244945 18000 # Node ID 5957aa1d69e126c8985d428648b374550a2d2046 # Parent f2cf16ad798f8364eadffc0407c9552db43854c5 Integrating Mohamed's changes Changed the indicator interface to access values, so that the generic LCSS implementation can be used diff -r f2cf16ad798f -r 5957aa1d69e1 python/indicators.py --- a/python/indicators.py Fri Dec 21 18:33:36 2012 -0500 +++ b/python/indicators.py Sat Jan 26 19:02:25 2013 -0500 @@ -38,11 +38,22 @@ return len(self.values) == 0 def __getitem__(self, i): + 'Returns ith value' + sortedKeys = sorted(self.values.keys()) + if 0<=i>> indic1 = TemporalIndicator('bla', [0,3,-4], TimeInterval(4,6)) >>> indic1.empty() False ->>> indic1[5] +>>> indic1.valueAtInstant(5) 3 ->>> indic1[3] +>>> indic1.valueAtInstant(3) +>>> indic1[1] +3 +>>> indic1[5] >>> [v for v in indic1] [0, 3, -4] >>> indic1 = TemporalIndicator('bla', {2:0,4:3,5:-5}) ->>> indic1[4] +>>> indic1.valueAtInstant(4) 3 ->>> indic1[3] ->>> [v for v in indic1] -[0, 3, -5] +>>> indic1.valueAtInstant(3) +>>> indic1[2] +-5 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]]) >>> indicatorMap([1,2,3], t1, 1) diff -r f2cf16ad798f -r 5957aa1d69e1 python/tests/utils.txt --- a/python/tests/utils.txt Fri Dec 21 18:33:36 2012 -0500 +++ b/python/tests/utils.txt Sat Jan 26 19:02:25 2013 -0500 @@ -40,3 +40,11 @@ 71.5... >>> values[-1] 6.0 + +>>> LCSS(range(5), range(5), 0.1, lambda x,y:abs(x-y)) +5 +>>> LCSS(range(1,5), range(5), 0.1, lambda x,y:abs(x-y)) +4 +>>> LCSS(range(5,10), range(5), 0.1, lambda x,y:abs(x-y)) +0 + diff -r f2cf16ad798f -r 5957aa1d69e1 python/utils.py --- a/python/utils.py Fri Dec 21 18:33:36 2012 -0500 +++ b/python/utils.py Sat Jan 26 19:02:25 2013 -0500 @@ -165,15 +165,16 @@ # maths section ######################### -def LCSS(l1, l2, threshold, distance): +def LCSS(l1, l2, threshold, distance, delta = float('inf')): '''returns the longest common subsequence similarity - based on the threshold on distance between two elements of lists l1, l2''' + 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), dtype = npint) for i in xrange(1,m+1): - for j in xrange(1,n+1): + for j in xrange(max(1,i-delta),min(n+1,i+delta)): if distance(l1[i-1], l2[j-1])