comparison python/indicators.py @ 376:2e6b8610bcaa

work on indicator similarity
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 17 Jul 2013 18:19:08 -0400
parents 2ea8584aa80a
children 6d26dcc7bba0
comparison
equal deleted inserted replaced
375:2ea8584aa80a 376:2e6b8610bcaa
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'), aligned = False, lengthFunc = min): 110 def __init__(self, threshold, 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, lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, aligned, lengthFunc)
112 self.minLength = minLength
113
114 def checkIndicator(self, indicator):
115 return indicator != None and len(indicator) >= self.minLength
112 116
113 def compute(self, indicator1, indicator2, computeSubSequence = False): 117 def compute(self, indicator1, indicator2, computeSubSequence = False):
114 if indicator1 and indicator2: 118 if self.checkIndicator(indicator1) and self.checkIndicator(indicator2):
115 return self._compute(indicator1.getValues(), indicator2.getValues(), computeSubSequence) 119 return self._compute(indicator1.getValues(), indicator2.getValues(), computeSubSequence)
116 else: 120 else:
117 return 0 121 return 0
118 122
119 def computeNormalized(self, indicator1, indicator2): 123 def computeNormalized(self, indicator1, indicator2, computeSubSequence = False):
120 if indicator1 and indicator2: 124 if self.checkIndicator(indicator1) and self.checkIndicator(indicator2):
121 return self._computeNormalized(indicator1.getValues(), indicator2.getValues()) 125 return self._computeNormalized(indicator1.getValues(), indicator2.getValues(), computeSubSequence)
122 else: 126 else:
123 return 0. 127 return 0.
124 128
125 def computeDistance(self, indicator1, indicator2): 129 def computeDistance(self, indicator1, indicator2, computeSubSequence = False):
126 if indicator1 and indicator2: 130 if self.checkIndicator(indicator1) and self.checkIndicator(indicator2):
127 return self._computeDistance(indicator1.getValues(), indicator2.getValues()) 131 return self._computeDistance(indicator1.getValues(), indicator2.getValues(), computeSubSequence)
128 else: 132 else:
129 return 1. 133 return 1.
130 134
131 135
132 class SeverityIndicator(TemporalIndicator): 136 class SeverityIndicator(TemporalIndicator):