changeset 286:fa95796a76b3

simplified indicators (only non-measured values, whether measurable or not)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 Jan 2013 00:22:55 -0500
parents 5957aa1d69e1
children 66691c06928c
files python/indicators.py python/ubc_utils.py python/utils.py
diffstat 3 files changed, 19 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/python/indicators.py	Sat Jan 26 19:02:25 2013 -0500
+++ b/python/indicators.py	Sun Jan 27 00:22:55 2013 -0500
@@ -94,39 +94,35 @@
         if self.maxValue:
             ylim(ymax = self.maxValue)
 
-    @staticmethod
-    def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= 'min'):
-	''' compute the distance between two indicators using LCSS
-	two common methods are used: min or mean of the indicators length'''
-        # l1= TemporalIndicator1.valueSorted
-	# 	l2= TemporalIndicator2.valueSorted
-	# 	if method = 'min':
-	# 		DLCSS= 1- (LCSS(l1,l2, threshold, delta, distance))/min(len(l1),len(l2)))
-	# 	if method = 'mean':
-	# 		average= len(l1)+len(l2))/2
-	# 		DLCSS= 1- ((LCSS(l1,l2, threshold, delta, distance))/average)
-	# 	return DLCSS
-        return 0
+def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= 'min'):
+    ''' compute the distance between two indicators using LCSS
+    two common methods are used: min or mean of the indicators length'''
+    from utils import LCSS
+    lcss = LCSS(indicator1, indicator2, threshold, lambda x,y:abs(x-y), delta)
+    if method == 'min':
+        denominator = min(len(indicator1), len(indicator2))
+    elif method == 'mean':
+        denominator = float(len(indicator1) + len(indicator2))/2
+    else:
+        print('Unknown denominator method name')
+        denominator = 1.
+    return 1-float(lcss)/denominator
 
 class SeverityIndicator(TemporalIndicator):
     '''Class for severity indicators 
     field mostSevereIsMax is True 
     if the most severe value taken by the indicator is the maximum'''
 
-    def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, ignoredValue = None, maxValue = None): 
+    def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, maxValue = None): 
         TemporalIndicator.__init__(self, name, values, timeInterval, maxValue)
         self.mostSevereIsMax = mostSevereIsMax
-        self.ignoredValue = ignoredValue
 
     def getMostSevereValue(self, minNInstants=1): # TODO use scoreatpercentile
         from matplotlib.mlab import find
         from numpy.core.multiarray import array
         from numpy.core.fromnumeric import mean
         values = array(self.values.values())
-        if self.ignoredValue:
-            indices = find(values != self.ignoredValue)
-        else:
-            indices = range(len(values))
+        indices = range(len(values))
         if len(indices) >= minNInstants:
             values = sorted(values[indices], reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values
             return mean(values[:minNInstants])
--- a/python/ubc_utils.py	Sat Jan 26 19:02:25 2013 -0500
+++ b/python/ubc_utils.py	Sun Jan 27 00:22:55 2013 -0500
@@ -188,8 +188,9 @@
         for indicatorNum,line in enumerate(lines[2:]):
             values = {}
             for i,v in enumerate([float(n) for n in line.split(' ')]):
-                values[indicatorFrameNums[i]] = v
-            inter.indicators.append(SeverityIndicator(severityIndicatorNames[indicatorNum], values, None, mostSevereIsMax[indicatorNum], ignoredValue[indicatorNum]))
+                if not ignoredValue[indicatorNum] or v != ignoredValue[indicatorNum]:
+                    values[indicatorFrameNums[i]] = v
+            inter.indicators.append(SeverityIndicator(severityIndicatorNames[indicatorNum], values, None, mostSevereIsMax[indicatorNum]))
 
         interactions.append(inter)
         interactionNum+=1
--- a/python/utils.py	Sat Jan 26 19:02:25 2013 -0500
+++ b/python/utils.py	Sun Jan 27 00:22:55 2013 -0500
@@ -175,7 +175,7 @@
     similarity = zeros((m+1,n+1), dtype = npint)
     for i in xrange(1,m+1):
         for j in xrange(max(1,i-delta),min(n+1,i+delta)):
-            if distance(l1[i-1], l2[j-1])<threshold:
+            if distance(l1[i-1], l2[j-1])<=threshold:
                 similarity[i][j] = similarity[i-1][j-1]+1
             else:
                 similarity[i][j] = max(similarity[i-1][j], similarity[i][j-1])