changeset 371:924e38c9f70e

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 16 Jul 2013 01:36:50 -0400
parents 97e8fa0ee9a1
children 349eb1e09f45
files python/utils.py
diffstat 1 files changed, 16 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/python/utils.py	Mon Jul 15 18:18:44 2013 -0400
+++ b/python/utils.py	Tue Jul 16 01:36:50 2013 -0400
@@ -251,18 +251,10 @@
         '''
         from numpy import argmax
         self.similarities(l1, l2)
-        imax = argmax(self.similarityTable[:,-1])
-        jmax = argmax(self.similarityTable[-1,:])
+        self.similarityTable = self.similarityTable[:, :min(len(l2), len(l1)+self.delta)+1]
         if computeSubSequence:
-            if self.similarityTable[imax, -1] > self.similarityTable[-1, jmax]:
-                self.similarityTable = self.similarityTable[:imax+1, :]
-                self.subSequenceIndices = self.subSequence(imax, len(l2))
-            else:
-                self.similarityTable = self.similarityTable[:, :jmax+1]
-                self.subSequenceIndices = self.subSequence(len(l1), jmax)
-            return self.similarityTable[-1,-1]
-        else:
-            return max(self.similarityTable[imax, -1], self.similarityTable[-1, jmax])
+            self.subSequenceIndices = self.subSequence(len(l1), len(l2))
+        return self.similarityTable[-1,-1]
 
     def _compute(self, _l1, _l2, computeSubSequence = False):
         '''returns the best matching if using a finite delta by shiftinig the series alignments'''
@@ -271,9 +263,11 @@
             if len(_l2) < len(_l1): # l1 is the shortest
                 l1 = _l2
                 l2 = _l1
+                revertIndices = True
             else:
                 l1 = _l1
                 l2 = _l2
+                revertIndices = False
             n1 = len(l1)
             n2 = len(l2)
             # for i in xrange(min(delta,n1), max(n1+n2-delta, n2+1)): # i is the alignment of the end of l1 in l2
@@ -282,16 +276,21 @@
             #     print LCSS(l1[min(-i-1,n1):], l2[max(0,i-n1):], similarityFunc, delta)
             lcssValues = {}
             similarityTables = {}
-            for i in xrange(min(self.delta,n1), max(n1+n2-self.delta, n2+1), max(1,self.delta)):
-                print l1[min(-i-1,n1):] # min(n1+n2-i,n1)
-                print l2[max(0,i-n1):]
+            for i in xrange(min(self.delta,n1), max(n1+n2-self.delta, n2+1)):
+                #print l1[min(-i-1,n1):] # min(n1+n2-i,n1)
+                #print l2[max(0,i-n1):]
                 lcssValues[i] = self.computeLCSS(l1[min(-i-1,n1):], l2[max(0,i-n1):])
-                print i, lcssValues[i]
+                #print i, lcssValues[i]
                 similarityTables[i] = self.similarityTable
             imax = argMaxDict(lcssValues)
             self.similarityTable = similarityTables[imax]
-            self.subSequenceIndices = self.subSequence(self.similarityTable.shape[0]-1, self.similarityTable.shape[1]-1)
-            self.alignmentShift = max(0,imax-n1)-min(-imax-1,n1)
+            self.subSequenceIndices = self.subSequence(self.similarityTable.shape[0]-1, self.similarityTable.shape[1]-1) 
+            if revertIndices:
+                self.subSequenceIndices = [(j+imax-n1,i) for i,j in self.subSequenceIndices]
+                self.alignmentShift = imax-n1
+            else:
+                self.subSequenceIndices = [(i+n1-imax,j) for i,j in self.subSequenceIndices]
+                self.alignmentShift = n1-imax
             return lcssValues[imax]
         else:
             return self.computeLCSS(_l1, _l2, computeSubSequence)