Chromium Code Reviews| Index: appengine/findit/crash/loglinear/changelist_classifier.py |
| diff --git a/appengine/findit/crash/loglinear/changelist_classifier.py b/appengine/findit/crash/loglinear/changelist_classifier.py |
| index ccbfb569999f418bb0f063a87a73ccc0c6195ef3..3823d9cc147a76bae96a1f474bc3225758158d8e 100644 |
| --- a/appengine/findit/crash/loglinear/changelist_classifier.py |
| +++ b/appengine/findit/crash/loglinear/changelist_classifier.py |
| @@ -11,7 +11,7 @@ from crash import changelist_classifier |
| from crash.crash_report_with_dependencies import CrashReportWithDependencies |
| from crash.loglinear.changelist_features import min_distance |
| from crash.loglinear.changelist_features import top_frame_index |
| -from crash.loglinear.model import ToFeatureFunction |
| +from crash.loglinear.feature import FeatureFunction |
| from crash.loglinear.model import UnnormalizedLogLinearModel |
| from crash.stacktrace import CallStack |
| from crash.stacktrace import Stacktrace |
| @@ -42,20 +42,12 @@ class LogLinearChangelistClassifier(object): |
| self._top_n_frames = top_n_frames |
| self._top_n_suspects = top_n_suspects |
| - feature_function = ToFeatureFunction([ |
| + feature_function = FeatureFunction([ |
| top_frame_index.TopFrameIndexFeature(top_n_frames), |
| min_distance.MinDistanceFeature(), |
| ]) |
| - weight_list = [ |
| - weights['TopFrameIndex'], |
| - weights['MinDistance'], |
| - ] |
| - |
| - self._model = UnnormalizedLogLinearModel(feature_function, weight_list) |
| - |
| - # TODO(crbug.com/674262): remove the need for storing these weights. |
| - self._weights = weights |
| + self._model = UnnormalizedLogLinearModel(feature_function, weights) |
| # TODO(crbug.com/673964): something better for detecting "close to log(0)". |
| def _LogZeroish(self, x): |
|
wrengr
2017/01/11 20:38:30
This should also be moved to UnnormalizedLLM. That
Sharu Jiang
2017/01/12 01:41:38
Done.
|
| @@ -75,20 +67,6 @@ class LogLinearChangelistClassifier(object): |
| """ |
| return x < 0 and math.isinf(x) |
| - def _SingleFeatureScore(self, feature_value): |
| - """Returns the score (aka weighted value) of a ``FeatureValue``. |
| - |
| - This function assumes the report's stacktrace has already had any necessary |
| - preprocessing (like filtering or truncating) applied. |
| - |
| - Args: |
| - feature_value (FeatureValue): the feature value to check. |
| - |
| - Returns: |
| - The score of the feature value. |
| - """ |
| - return feature_value.value * self._weights.get(feature_value.name, 0.) |
| - |
| def __call__(self, report): |
| """Finds changelists suspected of being responsible for the crash report. |
| @@ -142,10 +120,10 @@ class LogLinearChangelistClassifier(object): |
| suspect.confidence = score |
| features = features_given_report(suspect) |
| - suspect.reasons = self.FormatReasons(features) |
| + suspect.reasons = self.FormatReasons(features.itervalues()) |
| suspect.changed_files = [ |
| changed_file.ToDict() |
| - for changed_file in self.AggregateChangedFiles(features)] |
| + for changed_file in self.AggregateChangedFiles(features.itervalues())] |
| scored_suspects.append(suspect) |
| scored_suspects.sort(key=lambda suspect: suspect.confidence) |
| @@ -173,7 +151,7 @@ class LogLinearChangelistClassifier(object): |
| """ |
| formatted_reasons = [] |
| for feature in features: |
| - feature_score = self._SingleFeatureScore(feature) |
| + feature_score = self._model.SingleFeatureScore(feature) |
| if self._LogZeroish(feature_score): # pragma: no cover |
| logging.debug('Discarding reasons from feature %s' |
| ' because it has zero probability' % feature.name) |
| @@ -201,7 +179,8 @@ class LogLinearChangelistClassifier(object): |
| """ |
| all_changed_files = {} |
| for feature in features: |
| - if self._LogZeroish(self._SingleFeatureScore(feature)): # pragma: no cover |
| + if self._LogZeroish( |
| + self._model.SingleFeatureScore(feature)): # pragma: no cover |
| logging.debug('Discarding changed files from feature %s' |
| ' because it has zero probability' % feature.name) |
| continue |