| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from collections import namedtuple | 5 from collections import namedtuple |
| 6 import logging | 6 import logging |
| 7 import math | 7 import math |
| 8 | 8 |
| 9 import libs.math.logarithms as lmath | 9 import libs.math.logarithms as lmath |
| 10 from libs.math.vectors import vsum | 10 from libs.math.vectors import vsum |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 @property | 107 @property |
| 108 def name(self): | 108 def name(self): |
| 109 return self._name | 109 return self._name |
| 110 | 110 |
| 111 @property | 111 @property |
| 112 def value(self): | 112 def value(self): |
| 113 return self._value | 113 return self._value |
| 114 | 114 |
| 115 @property | 115 @property |
| 116 def reason(self): | 116 def reason(self): |
| 117 return self._reason | 117 return ('%s: %f -- %s' % (self._name, self._value, self._reason) |
| 118 if self._reason else None) |
| 118 | 119 |
| 119 @property | 120 @property |
| 120 def changed_files(self): | 121 def changed_files(self): |
| 121 return self._changed_files | 122 return self._changed_files |
| 122 | 123 |
| 123 def __str__(self): | 124 def __str__(self): |
| 124 return ('%s(name = %s, value = %f, reason = %s, changed_files = %s)' | 125 return ('%s(name = %s, value = %f, reason = %s, changed_files = %s)' |
| 125 % (self.__class__.__name__, self.name, self.value, self.reason, | 126 % (self.__class__.__name__, self.name, self.value, self.reason, |
| 126 self.changed_files)) | 127 self.changed_files)) |
| 127 | 128 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 value. However, this isn't the best thing for UX reasons. In the | 191 value. However, this isn't the best thing for UX reasons. In the |
| 191 future it might be replaced by the normal-domain score, or by | 192 future it might be replaced by the normal-domain score, or by |
| 192 the probability. | 193 the probability. |
| 193 """ | 194 """ |
| 194 if self._reason: | 195 if self._reason: |
| 195 return self._reason | 196 return self._reason |
| 196 | 197 |
| 197 formatted_reasons = [] | 198 formatted_reasons = [] |
| 198 for feature in self.itervalues(): | 199 for feature in self.itervalues(): |
| 199 if feature.reason: | 200 if feature.reason: |
| 200 formatted_reasons.append('%s: %f -- %s' % (feature.name, | 201 formatted_reasons.append(feature.reason) |
| 201 feature.value, | |
| 202 feature.reason)) | |
| 203 | 202 |
| 204 formatted_reasons.sort() | 203 formatted_reasons.sort() |
| 205 self._reason = '\n'.join(formatted_reasons) | 204 self._reason = '\n'.join(formatted_reasons) |
| 206 return self._reason | 205 return self._reason |
| 207 | 206 |
| 208 @property | 207 @property |
| 209 def changed_files(self): | 208 def changed_files(self): |
| 210 """Merge multiple``FeatureValue.changed_files`` lists into one. | 209 """Merge multiple``FeatureValue.changed_files`` lists into one. |
| 211 | 210 |
| 212 Returns: | 211 Returns: |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 """Fuction mapping ``X -> Y -> dict(FeatureValue.name to FeatureValue). | 351 """Fuction mapping ``X -> Y -> dict(FeatureValue.name to FeatureValue). |
| 353 | 352 |
| 354 Returns: | 353 Returns: |
| 355 A function ``X -> Y -> dict(FeatureValue.name to FeatureValue)`` where for | 354 A function ``X -> Y -> dict(FeatureValue.name to FeatureValue)`` where for |
| 356 all ``x``, ``y``, and for a feature f in fs, we have | 355 all ``x``, ``y``, and for a feature f in fs, we have |
| 357 ``FeatureFunction(fs)(x)(y)[f.name] == f(x)(y)``. | 356 ``FeatureFunction(fs)(x)(y)[f.name] == f(x)(y)``. |
| 358 """ | 357 """ |
| 359 fxs = {name: f(x) for name, f in self.iteritems()} | 358 fxs = {name: f(x) for name, f in self.iteritems()} |
| 360 return lambda y: MetaFeatureValue( | 359 return lambda y: MetaFeatureValue( |
| 361 self.name, {name: fx(y) for name, fx in fxs.iteritems()}) | 360 self.name, {name: fx(y) for name, fx in fxs.iteritems()}) |
| OLD | NEW |