Mercurial Hosting > traffic-intelligence
diff python/indicators.py @ 308:8bafd054cda4
Added a function to compute LCSS distance between two indcators
author | Mohamed Gomaa |
---|---|
date | Tue, 25 Dec 2012 02:20:25 -0500 |
parents | abbd4bc13dac |
children | 6c068047edbf |
line wrap: on
line diff
--- a/python/indicators.py Tue Dec 25 02:16:10 2012 -0500 +++ b/python/indicators.py Tue Dec 25 02:20:25 2012 -0500 @@ -4,7 +4,7 @@ __metaclass__ = type import moving - +from utils import LCSS # need for a class representing the indicators, their units, how to print them in graphs... class TemporalIndicator: '''Class for temporal indicators @@ -82,7 +82,28 @@ plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs) if self.maxValue: ylim(ymax = self.maxValue) - + + def valueSorted(self): + ''' return the values after sort the keys in the indicator''' + values=[] + keys = self.values.keys() + keys.sort() + for key in keys: + values.append(self.values[key]) + return values + @staticmethod + def getDLCSS(TemporalIndicator1,TemporalIndicator2, threshold, delta= np.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 + class SeverityIndicator(TemporalIndicator): '''Class for severity indicators field mostSevereIsMax is True