Mercurial Hosting > traffic-intelligence
diff python/indicators.py @ 368:2db4e76599a1
implemented subsequence extraction and rearranged arguments
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 15 Jul 2013 15:08:53 -0400 |
parents | 2f39c4ed0b62 |
children | 027e254f0b53 |
line wrap: on
line diff
--- a/python/indicators.py Mon Jul 15 12:13:08 2013 -0400 +++ b/python/indicators.py Mon Jul 15 15:08:53 2013 -0400 @@ -96,21 +96,6 @@ values.append(self.values[key]) return values - @staticmethod - def getDLCSS(indic1, indic2, 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''' - print('Deprecated: this is not appropriate method for indicator comparison') - l1 = indic1.valueSorted - l2 = indic2.valueSorted - DLCSS = None - 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 - def distanceForLCSS(x, y): # lambda x,y:abs(x-y) if x == None or y == None: @@ -123,7 +108,7 @@ ''' compute the LCSS between two indicators using LCSS''' from utils import LCSS if indicator1 and indicator2: - return LCSS(indicator1.getValues(), indicator2.getValues(), threshold, distanceForLCSS, delta) + return LCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta) else: return 0 @@ -132,21 +117,24 @@ ie, the LCSS divided by the min or mean of the indicator lengths''' from utils import normalizedLCSS if indicator1 and indicator2: - return normalizedLCSS(indicator1.getValues(), indicator2.getValues(), threshold, distanceForLCSS, delta, method) + return normalizedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) else: return 0. def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method = min): ''' compute the LCSS distance between two indicators using LCSS''' from utils import DLCSS - return DLCSS(indicator1.getValues(), indicator2.getValues(), threshold, distanceForLCSS, delta, method) + if indicator1 and indicator2: + return DLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) + else: + return 1. # aligned LCSS computations def computeAlignedLCSS(indicator1, indicator2, threshold, delta = float('inf')): ''' compute the aligned LCSS between two indicators using LCSS''' from utils import alignedLCSS if indicator1 and indicator2: - return alignedLCSS(indicator1.getValues(), indicator2.getValues(), threshold, distanceForLCSS, delta) + return alignedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta) else: return 0 @@ -155,14 +143,17 @@ ie, the LCSS divided by the min or mean of the indicator lengths''' from utils import normalizedAlignedLCSS if indicator1 and indicator2: - return normalizedAlignedLCSS(indicator1.getValues(), indicator2.getValues(), threshold, distanceForLCSS, delta, method) + return normalizedAlignedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) else: return 0. def computeAlignedDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method = min): ''' compute the aligned LCSS distance between two indicators using LCSS''' from utils import alignedDLCSS - return alignedDLCSS(indicator1.getValues(), indicator2.getValues(), threshold, distanceForLCSS, delta, method) + if indicator1 and indicator2: + return alignedDLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) + else: + return 1. class SeverityIndicator(TemporalIndicator): '''Class for severity indicators