Mercurial > hg > nsaunier > traffic-intelligence
comparison python/indicators.py @ 369:027e254f0b53
lcss subclass for indicators
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 15 Jul 2013 16:47:09 -0400 |
| parents | 2db4e76599a1 |
| children | 97e8fa0ee9a1 |
comparison
equal
deleted
inserted
replaced
| 368:2db4e76599a1 | 369:027e254f0b53 |
|---|---|
| 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 # non-aligned LCSS computations, ok for delta = inf | 106 from utils import LCSS as utilsLCSS |
| 107 def computeLCSS(indicator1, indicator2, threshold, delta = float('inf')): | 107 |
| 108 ''' compute the LCSS between two indicators using LCSS''' | 108 class LCSS(utilsLCSS): |
| 109 from utils import LCSS | 109 '''Adapted LCSS class for indicators, same pattern''' |
| 110 if indicator1 and indicator2: | 110 def __init__(self, threshold, delta = float('inf'), aligned = False, lengthFunc = min): |
| 111 return LCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta) | 111 utilsLCSS.__init__(self, lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, aligned, lengthFunc) |
| 112 else: | 112 |
| 113 return 0 | 113 def get(self, indicator1, indicator2): |
| 114 | 114 if indicator1 and indicator2: |
| 115 def computeNormalizedLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= min): | 115 return self.compute(indicator1.getValues(), indicator2.getValues()) |
| 116 ''' compute the normalized LCSS between two indicators using LCSS | 116 else: |
| 117 ie, the LCSS divided by the min or mean of the indicator lengths''' | 117 return 0 |
| 118 from utils import normalizedLCSS | 118 |
| 119 if indicator1 and indicator2: | 119 def getNormalized(self, indicator1, indicator2): |
| 120 return normalizedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) | 120 if indicator1 and indicator2: |
| 121 else: | 121 return self.computeNormalized(indicator1.getValues(), indicator2.getValues()) |
| 122 return 0. | 122 else: |
| 123 | 123 return 0. |
| 124 def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method = min): | 124 |
| 125 ''' compute the LCSS distance between two indicators using LCSS''' | 125 def getDistance(self, indicator1, indicator2): |
| 126 from utils import DLCSS | 126 if indicator1 and indicator2: |
| 127 if indicator1 and indicator2: | 127 return self.computeDistance(indicator1.getValues(), indicator2.getValues()) |
| 128 return DLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) | 128 else: |
| 129 else: | 129 return 1. |
| 130 return 1. | 130 |
| 131 | |
| 132 # aligned LCSS computations | |
| 133 def computeAlignedLCSS(indicator1, indicator2, threshold, delta = float('inf')): | |
| 134 ''' compute the aligned LCSS between two indicators using LCSS''' | |
| 135 from utils import alignedLCSS | |
| 136 if indicator1 and indicator2: | |
| 137 return alignedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta) | |
| 138 else: | |
| 139 return 0 | |
| 140 | |
| 141 def computeNormalizedAlignedLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= min): | |
| 142 ''' compute the normalized aligned LCSS between two indicators using LCSS | |
| 143 ie, the LCSS divided by the min or mean of the indicator lengths''' | |
| 144 from utils import normalizedAlignedLCSS | |
| 145 if indicator1 and indicator2: | |
| 146 return normalizedAlignedLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) | |
| 147 else: | |
| 148 return 0. | |
| 149 | |
| 150 def computeAlignedDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method = min): | |
| 151 ''' compute the aligned LCSS distance between two indicators using LCSS''' | |
| 152 from utils import alignedDLCSS | |
| 153 if indicator1 and indicator2: | |
| 154 return alignedDLCSS(indicator1.getValues(), indicator2.getValues(), lambda x,y: (distanceForLCSS(x,y) <= threshold), delta, method) | |
| 155 else: | |
| 156 return 1. | |
| 157 | 131 |
| 158 class SeverityIndicator(TemporalIndicator): | 132 class SeverityIndicator(TemporalIndicator): |
| 159 '''Class for severity indicators | 133 '''Class for severity indicators |
| 160 field mostSevereIsMax is True | 134 field mostSevereIsMax is True |
| 161 if the most severe value taken by the indicator is the maximum''' | 135 if the most severe value taken by the indicator is the maximum''' |
