Mercurial Hosting > traffic-intelligence
diff python/indicators.py @ 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 |
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])