comparison python/indicators.py @ 375:2ea8584aa80a

making indicator LCSS work
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 17 Jul 2013 01:29:25 -0400
parents 97e8fa0ee9a1
children 2e6b8610bcaa
comparison
equal deleted inserted replaced
374:a7af3519687e 375:2ea8584aa80a
72 return self.name 72 return self.name
73 73
74 def getValues(self): 74 def getValues(self):
75 return [self.__getitem__(t) for t in self.timeInterval] 75 return [self.__getitem__(t) for t in self.timeInterval]
76 76
77 def plot(self, options = '', xfactor = 1., **kwargs): 77 def plot(self, options = '', xfactor = 1., timeShift = 0, **kwargs):
78 from matplotlib.pylab import plot,ylim 78 from matplotlib.pylab import plot,ylim
79 if self.getTimeInterval().length() == 1: 79 if self.getTimeInterval().length() == 1:
80 marker = 'o' 80 marker = 'o'
81 else: 81 else:
82 marker = '' 82 marker = ''
83 time = sorted(self.values.keys()) 83 time = sorted(self.values.keys())
84 plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs) 84 plot([(x+timeShift)/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs)
85 if self.maxValue: 85 if self.maxValue:
86 ylim(ymax = self.maxValue) 86 ylim(ymax = self.maxValue)
87 87
88 def valueSorted(self): 88 def valueSorted(self):
89 ''' return the values after sort the keys in the indicator 89 ''' return the values after sort the keys in the indicator
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'), 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 112
113 def compute(self, indicator1, indicator2): 113 def compute(self, indicator1, indicator2, computeSubSequence = False):
114 if indicator1 and indicator2: 114 if indicator1 and indicator2:
115 return self._compute(indicator1.getValues(), indicator2.getValues()) 115 return self._compute(indicator1.getValues(), indicator2.getValues(), computeSubSequence)
116 else: 116 else:
117 return 0 117 return 0
118 118
119 def computeNormalized(self, indicator1, indicator2): 119 def computeNormalized(self, indicator1, indicator2):
120 if indicator1 and indicator2: 120 if indicator1 and indicator2: