changeset 376:2e6b8610bcaa

work on indicator similarity
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 17 Jul 2013 18:19:08 -0400
parents 2ea8584aa80a
children 2aed569f39e7
files python/indicators.py python/utils.py
diffstat 2 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/python/indicators.py	Wed Jul 17 01:29:25 2013 -0400
+++ b/python/indicators.py	Wed Jul 17 18:19:08 2013 -0400
@@ -107,24 +107,28 @@
 
 class LCSS(utilsLCSS):
     '''Adapted LCSS class for indicators, same pattern'''
-    def __init__(self, threshold, delta = float('inf'), aligned = False, lengthFunc = min):
+    def __init__(self, threshold, delta = float('inf'), minLength = 0, aligned = False, lengthFunc = min):
         utilsLCSS.__init__(self, lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, aligned, lengthFunc)
+        self.minLength = minLength
+
+    def checkIndicator(self, indicator):
+        return indicator != None and len(indicator) >= self.minLength
 
     def compute(self, indicator1, indicator2, computeSubSequence = False):
-        if indicator1 and indicator2:
+        if self.checkIndicator(indicator1) and self.checkIndicator(indicator2):
             return self._compute(indicator1.getValues(), indicator2.getValues(), computeSubSequence)
         else:
             return 0
 
-    def computeNormalized(self, indicator1, indicator2):
-        if indicator1 and indicator2:
-            return self._computeNormalized(indicator1.getValues(), indicator2.getValues())
+    def computeNormalized(self, indicator1, indicator2, computeSubSequence = False):
+        if self.checkIndicator(indicator1) and self.checkIndicator(indicator2):
+            return self._computeNormalized(indicator1.getValues(), indicator2.getValues(), computeSubSequence)
         else:
             return 0.
 
-    def computeDistance(self, indicator1, indicator2):
-        if indicator1 and indicator2:
-            return self._computeDistance(indicator1.getValues(), indicator2.getValues())
+    def computeDistance(self, indicator1, indicator2, computeSubSequence = False):
+        if self.checkIndicator(indicator1) and self.checkIndicator(indicator2):
+            return self._computeDistance(indicator1.getValues(), indicator2.getValues(), computeSubSequence)
         else:
             return 1.
         
--- a/python/utils.py	Wed Jul 17 01:29:25 2013 -0400
+++ b/python/utils.py	Wed Jul 17 18:19:08 2013 -0400
@@ -293,21 +293,21 @@
         from numpy import mean
         return mean([j-i for i,j in self.subSequenceIndices])
 
-    def _computeNormalized(self, l1, l2):
+    def _computeNormalized(self, l1, l2, computeSubSequence = False):
         ''' compute the normalized LCSS
         ie, the LCSS divided by the min or mean of the indicator lengths (using lengthFunc)
         lengthFunc = lambda x,y:float(x,y)/2'''
-        return float(self._compute(l1, l2))/self.lengthFunc(len(l1), len(l2))
+        return float(self._compute(l1, l2, computeSubSequence))/self.lengthFunc(len(l1), len(l2))
 
-    def computeNormalized(self, l1, l2):
-        return self._computeNormalized(l1, l2)
+    def computeNormalized(self, l1, l2, computeSubSequence = False):
+        return self._computeNormalized(l1, l2, computeSubSequence)
 
-    def _computeDistance(self, l1, l2):
+    def _computeDistance(self, l1, l2, computeSubSequence = False):
         ''' compute the LCSS distance'''
-        return 1-self._computeNormalized(l1, l2)
+        return 1-self._computeNormalized(l1, l2, computeSubSequence)
 
-    def computeDistance(self, l1, l2):
-        return self._computeDistance(l1, l2)
+    def computeDistance(self, l1, l2, computeSubSequence = False):
+        return self._computeDistance(l1, l2, computeSubSequence)
     
 #########################
 # plotting section