Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
307:8e66ced156dd | 308:8bafd054cda4 |
---|---|
2 '''Class for indicators, temporal indicators, and safety indicators''' | 2 '''Class for indicators, temporal indicators, and safety indicators''' |
3 | 3 |
4 __metaclass__ = type | 4 __metaclass__ = type |
5 | 5 |
6 import moving | 6 import moving |
7 | 7 from utils import LCSS |
8 # need for a class representing the indicators, their units, how to print them in graphs... | 8 # need for a class representing the indicators, their units, how to print them in graphs... |
9 class TemporalIndicator: | 9 class TemporalIndicator: |
10 '''Class for temporal indicators | 10 '''Class for temporal indicators |
11 i.e. indicators that take a value at specific instants | 11 i.e. indicators that take a value at specific instants |
12 | 12 |
80 marker = '' | 80 marker = '' |
81 time = sorted(self.values.keys()) | 81 time = sorted(self.values.keys()) |
82 plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs) | 82 plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs) |
83 if self.maxValue: | 83 if self.maxValue: |
84 ylim(ymax = self.maxValue) | 84 ylim(ymax = self.maxValue) |
85 | 85 |
86 def valueSorted(self): | |
87 ''' return the values after sort the keys in the indicator''' | |
88 values=[] | |
89 keys = self.values.keys() | |
90 keys.sort() | |
91 for key in keys: | |
92 values.append(self.values[key]) | |
93 return values | |
94 @staticmethod | |
95 def getDLCSS(TemporalIndicator1,TemporalIndicator2, threshold, delta= np.inf , method='min' ): | |
96 ''' compute the distance between two indicators using LCSS | |
97 two common methods are used: min or mean of the indicators length''' | |
98 l1= TemporalIndicator1.valueSorted | |
99 l2= TemporalIndicator2.valueSorted | |
100 if method = 'min': | |
101 DLCSS= 1- (LCSS(l1,l2, threshold, delta, distance))/min(len(l1),len(l2))) | |
102 if method = 'mean': | |
103 average= len(l1)+len(l2))/2 | |
104 DLCSS= 1- ((LCSS(l1,l2, threshold, delta, distance))/average) | |
105 return DLCSS | |
106 | |
86 class SeverityIndicator(TemporalIndicator): | 107 class SeverityIndicator(TemporalIndicator): |
87 '''Class for severity indicators | 108 '''Class for severity indicators |
88 field mostSevereIsMax is True | 109 field mostSevereIsMax is True |
89 if the most severe value taken by the indicator is the maximum''' | 110 if the most severe value taken by the indicator is the maximum''' |
90 | 111 |