diff python/indicators.py @ 369:027e254f0b53

lcss subclass for indicators
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 15 Jul 2013 16:47:09 -0400
parents 2db4e76599a1
children 97e8fa0ee9a1
line wrap: on
line diff
--- a/python/indicators.py	Mon Jul 15 15:08:53 2013 -0400
+++ b/python/indicators.py	Mon Jul 15 16:47:09 2013 -0400
@@ -103,57 +103,31 @@
     else:
         return abs(x-y)
 
-# non-aligned LCSS computations, ok for delta = inf
-def computeLCSS(indicator1, indicator2, threshold, delta = float('inf')):
-    ''' compute the LCSS between two indicators using LCSS'''
-    from utils import LCSS
-    if indicator1 and indicator2:
-        return LCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta)
-    else:
-        return 0
+from utils import LCSS as utilsLCSS
 
-def computeNormalizedLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= min):
-    ''' compute the normalized LCSS between two indicators using LCSS
-    ie, the LCSS divided by the min or mean of the indicator lengths'''
-    from utils import normalizedLCSS
-    if indicator1 and indicator2:
-        return normalizedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method)
-    else:
-        return 0.
+class LCSS(utilsLCSS):
+    '''Adapted LCSS class for indicators, same pattern'''
+    def __init__(self, threshold, delta = float('inf'), aligned = False, lengthFunc = min):
+        utilsLCSS.__init__(self, lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, aligned, lengthFunc)
 
-def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method = min):
-    ''' compute the LCSS distance between two indicators using LCSS'''
-    from utils import DLCSS
-    if indicator1 and indicator2:
-        return DLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method)
-    else:
-        return 1.
+    def get(self, indicator1, indicator2):
+        if indicator1 and indicator2:
+            return self.compute(indicator1.getValues(), indicator2.getValues())
+        else:
+            return 0
 
-# aligned LCSS computations
-def computeAlignedLCSS(indicator1, indicator2, threshold, delta = float('inf')):
-    ''' compute the aligned LCSS between two indicators using LCSS'''
-    from utils import alignedLCSS
-    if indicator1 and indicator2:
-        return alignedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta)
-    else:
-        return 0
+    def getNormalized(self, indicator1, indicator2):
+        if indicator1 and indicator2:
+            return self.computeNormalized(indicator1.getValues(), indicator2.getValues())
+        else:
+            return 0.
 
-def computeNormalizedAlignedLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= min):
-    ''' compute the normalized aligned LCSS between two indicators using LCSS
-    ie, the LCSS divided by the min or mean of the indicator lengths'''
-    from utils import normalizedAlignedLCSS
-    if indicator1 and indicator2:
-        return normalizedAlignedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method)
-    else:
-        return 0.
-
-def computeAlignedDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method = min):
-    ''' compute the aligned LCSS distance between two indicators using LCSS'''
-    from utils import alignedDLCSS
-    if indicator1 and indicator2:
-        return alignedDLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method)
-    else:
-        return 1.
+    def getDistance(self, indicator1, indicator2):
+        if indicator1 and indicator2:
+            return self.computeDistance(indicator1.getValues(), indicator2.getValues())
+        else:
+            return 1.
+        
 
 class SeverityIndicator(TemporalIndicator):
     '''Class for severity indicators