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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | appengine/findit/crash/loglinear/test/model_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import random
6 import unittest
7
8 from crash.loglinear.feature import FeatureValue
9 from crash.loglinear.model import ToFeatureFunction
10
11
12 class LoglinearTestCase(unittest.TestCase): # pragma: no cover
13 """Common code for testing ``model.py`` and ``training.py``."""
14
15 def setUp(self):
16 """Set up some basic parts of our loglinear model.
17
18 These parts describe a silly model for detecting whether an integer
19 in [0..9] is the number 7. So ``X`` is the set of integers [0..9],
20 and ``Y`` is the set of ``bool`` values. The independent variable
21 is boolean-valued because we only have two categories: "yes, x ==
22 7" and "no, x != 7". This doesn't take advantage of the fact that
23 loglinear models can categorize larger sets of labels, but it's good
24 enough for testing purposes.
25
26 In addition to specifying ``X`` and ``Y``, we also specify a set of
27 features and choose some random weights for them.
28 """
29 super(LoglinearTestCase, self).setUp()
30
31 # Some arbitrary features.
32 # We don't use double lambdas because gpylint complains about that.
33 def feature0(x):
34 return lambda y: FeatureValue('feature0', y == (x > 5), None, None)
35
36 def feature1(x):
37 return lambda y: FeatureValue('feature1', y == ((x % 2) == 1), None, None)
38
39 def feature2(x):
40 return lambda y: FeatureValue('feature2', y == (x <= 7), None, None)
41
42 self._feature_list = [feature0, feature1, feature2]
43 self._feature_function = ToFeatureFunction(self._feature_list)
44 self._qty_features = len(self._feature_list)
45 self._X = range(10)
46 self._Y = [False, True]
47 self._weights = [random.random() for _ in xrange(self._qty_features)]
OLDNEW
« 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