comparison python/indicators.py @ 442:eb8baa080470

generalized indicator LCSS with similarityFunc (thanks Mohamed)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 27 Jan 2014 01:19:19 -0500
parents 365d8dee44f3
children 2d1d33ae1c69
comparison
equal deleted inserted replaced
440:b5cc6b001ae6 442:eb8baa080470
95 for key in keys: 95 for key in keys:
96 values.append(self.values[key]) 96 values.append(self.values[key])
97 return values 97 return values
98 98
99 99
100 def distanceForLCSS(x, y): # lambda x,y:abs(x-y) 100 def l1Distance(x, y): # lambda x,y:abs(x-y)
101 if x == None or y == None: 101 if x == None or y == None:
102 return float('inf') 102 return float('inf')
103 else: 103 else:
104 return abs(x-y) 104 return abs(x-y)
105 105
106 from utils import LCSS as utilsLCSS 106 from utils import LCSS as utilsLCSS
107 107
108 class LCSS(utilsLCSS): 108 class LCSS(utilsLCSS):
109 '''Adapted LCSS class for indicators, same pattern''' 109 '''Adapted LCSS class for indicators, same pattern'''
110 def __init__(self, threshold, delta = float('inf'), minLength = 0, aligned = False, lengthFunc = min): 110 def __init__(self, similarityFunc, delta = float('inf'), minLength = 0, aligned = False, lengthFunc = min):
111 utilsLCSS.__init__(self, lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, aligned, lengthFunc) 111 utilsLCSS.__init__(self, similarityFunc, delta, aligned, lengthFunc)
112 self.minLength = minLength 112 self.minLength = minLength
113 113
114 def checkIndicator(self, indicator): 114 def checkIndicator(self, indicator):
115 return indicator != None and len(indicator) >= self.minLength 115 return indicator != None and len(indicator) >= self.minLength
116 116