Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2730)

Unified Diff: appengine/findit/crash/loglinear/test/loglinear_testcase.py

Issue 2544493004: [Predator] Implement training for loglinear models (Closed)
Patch Set: Breaking out the shared code of loglinear/{model,training}_test.py Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/findit/crash/loglinear/test/model_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/crash/loglinear/test/loglinear_testcase.py
diff --git a/appengine/findit/crash/loglinear/test/loglinear_testcase.py b/appengine/findit/crash/loglinear/test/loglinear_testcase.py
new file mode 100644
index 0000000000000000000000000000000000000000..edf0fe8f567ca146374b38fdbb8a160c79bbf834
--- /dev/null
+++ b/appengine/findit/crash/loglinear/test/loglinear_testcase.py
@@ -0,0 +1,47 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import random
+import unittest
+
+from crash.loglinear.feature import FeatureValue
+from crash.loglinear.model import ToFeatureFunction
+
+
+class LoglinearTestCase(unittest.TestCase): # pragma: no cover
+ """Common code for testing ``model.py`` and ``training.py``."""
+
+ def setUp(self):
+ """Set up some basic parts of our loglinear model.
+
+ These parts describe a silly model for detecting whether an integer
+ in [0..9] is the number 7. So ``X`` is the set of integers [0..9],
+ and ``Y`` is the set of ``bool`` values. The independent variable
+ is boolean-valued because we only have two categories: "yes, x ==
+ 7" and "no, x != 7". This doesn't take advantage of the fact that
+ loglinear models can categorize larger sets of labels, but it's good
+ enough for testing purposes.
+
+ In addition to specifying ``X`` and ``Y``, we also specify a set of
+ features and choose some random weights for them.
+ """
+ super(LoglinearTestCase, self).setUp()
+
+ # Some arbitrary features.
+ # We don't use double lambdas because gpylint complains about that.
+ def feature0(x):
+ return lambda y: FeatureValue('feature0', y == (x > 5), None, None)
+
+ def feature1(x):
+ return lambda y: FeatureValue('feature1', y == ((x % 2) == 1), None, None)
+
+ def feature2(x):
+ return lambda y: FeatureValue('feature2', y == (x <= 7), None, None)
+
+ self._feature_list = [feature0, feature1, feature2]
+ self._feature_function = ToFeatureFunction(self._feature_list)
+ self._qty_features = len(self._feature_list)
+ self._X = range(10)
+ self._Y = [False, True]
+ self._weights = [random.random() for _ in xrange(self._qty_features)]
« no previous file with comments | « no previous file | appengine/findit/crash/loglinear/test/model_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698