Mercurial Hosting > traffic-intelligence
diff python/indicators.py @ 285:5957aa1d69e1
Integrating Mohamed's changes
Changed the indicator interface to access values, so that the generic LCSS implementation can be used
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sat, 26 Jan 2013 19:02:25 -0500 |
parents | abbd4bc13dac |
children | fa95796a76b3 |
line wrap: on
line diff
--- a/python/indicators.py Fri Dec 21 18:33:36 2012 -0500 +++ b/python/indicators.py Sat Jan 26 19:02:25 2013 -0500 @@ -38,11 +38,22 @@ return len(self.values) == 0 def __getitem__(self, i): + 'Returns ith value' + sortedKeys = sorted(self.values.keys()) + if 0<=i<len(sortedKeys): + return self.values[sortedKeys[i]] + else: + return None + + def valueAtInstant(self, i): if i in self.values.keys(): return self.values[i] else: return None + def __len__(self): + return len(self.values) + def __iter__(self): self.iterInstantNum = 0 # index in the interval or keys of the dict return self @@ -53,7 +64,7 @@ raise StopIteration else: self.iterInstantNum += 1 - return self.values[self.values.keys()[self.iterInstantNum-1]] + return self.__getitem__(self.iterInstantNum-1) def getTimeInterval(self): return self.timeInterval @@ -83,6 +94,20 @@ 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 + class SeverityIndicator(TemporalIndicator): '''Class for severity indicators field mostSevereIsMax is True @@ -93,7 +118,7 @@ self.mostSevereIsMax = mostSevereIsMax self.ignoredValue = ignoredValue - def getMostSevereValue(self, minNInstants=1): + 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