Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
285:5957aa1d69e1 | 286:fa95796a76b3 |
---|---|
92 time = sorted(self.values.keys()) | 92 time = sorted(self.values.keys()) |
93 plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs) | 93 plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs) |
94 if self.maxValue: | 94 if self.maxValue: |
95 ylim(ymax = self.maxValue) | 95 ylim(ymax = self.maxValue) |
96 | 96 |
97 @staticmethod | 97 def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= 'min'): |
98 def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= 'min'): | 98 ''' compute the distance between two indicators using LCSS |
99 ''' compute the distance between two indicators using LCSS | 99 two common methods are used: min or mean of the indicators length''' |
100 two common methods are used: min or mean of the indicators length''' | 100 from utils import LCSS |
101 # l1= TemporalIndicator1.valueSorted | 101 lcss = LCSS(indicator1, indicator2, threshold, lambda x,y:abs(x-y), delta) |
102 # l2= TemporalIndicator2.valueSorted | 102 if method == 'min': |
103 # if method = 'min': | 103 denominator = min(len(indicator1), len(indicator2)) |
104 # DLCSS= 1- (LCSS(l1,l2, threshold, delta, distance))/min(len(l1),len(l2))) | 104 elif method == 'mean': |
105 # if method = 'mean': | 105 denominator = float(len(indicator1) + len(indicator2))/2 |
106 # average= len(l1)+len(l2))/2 | 106 else: |
107 # DLCSS= 1- ((LCSS(l1,l2, threshold, delta, distance))/average) | 107 print('Unknown denominator method name') |
108 # return DLCSS | 108 denominator = 1. |
109 return 0 | 109 return 1-float(lcss)/denominator |
110 | 110 |
111 class SeverityIndicator(TemporalIndicator): | 111 class SeverityIndicator(TemporalIndicator): |
112 '''Class for severity indicators | 112 '''Class for severity indicators |
113 field mostSevereIsMax is True | 113 field mostSevereIsMax is True |
114 if the most severe value taken by the indicator is the maximum''' | 114 if the most severe value taken by the indicator is the maximum''' |
115 | 115 |
116 def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, ignoredValue = None, maxValue = None): | 116 def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, maxValue = None): |
117 TemporalIndicator.__init__(self, name, values, timeInterval, maxValue) | 117 TemporalIndicator.__init__(self, name, values, timeInterval, maxValue) |
118 self.mostSevereIsMax = mostSevereIsMax | 118 self.mostSevereIsMax = mostSevereIsMax |
119 self.ignoredValue = ignoredValue | |
120 | 119 |
121 def getMostSevereValue(self, minNInstants=1): # TODO use scoreatpercentile | 120 def getMostSevereValue(self, minNInstants=1): # TODO use scoreatpercentile |
122 from matplotlib.mlab import find | 121 from matplotlib.mlab import find |
123 from numpy.core.multiarray import array | 122 from numpy.core.multiarray import array |
124 from numpy.core.fromnumeric import mean | 123 from numpy.core.fromnumeric import mean |
125 values = array(self.values.values()) | 124 values = array(self.values.values()) |
126 if self.ignoredValue: | 125 indices = range(len(values)) |
127 indices = find(values != self.ignoredValue) | |
128 else: | |
129 indices = range(len(values)) | |
130 if len(indices) >= minNInstants: | 126 if len(indices) >= minNInstants: |
131 values = sorted(values[indices], reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values | 127 values = sorted(values[indices], reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values |
132 return mean(values[:minNInstants]) | 128 return mean(values[:minNInstants]) |
133 else: | 129 else: |
134 return None | 130 return None |