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

Side by Side Diff: appengine/findit/crash/loglinear/feature.py

Issue 2617273002: [Predator] Move ``SingleFeatureScore`` to LLM. (Closed)
Patch Set: Address comments. Created 3 years, 11 months 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
OLDNEW
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 math 6 import math
7 7
8 import libs.math.logarithms as lmath 8 import libs.math.logarithms as lmath
9 9
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 thinks the ``y`` should be blamed or should not be depends on the sign 131 thinks the ``y`` should be blamed or should not be depends on the sign
132 of the value and the sign of the weight given to this feature.) As 132 of the value and the sign of the weight given to this feature.) As
133 special cases, a value of negative infinity means "do not blame this 133 special cases, a value of negative infinity means "do not blame this
134 ``y`` no matter what any other features say", and a value of positive 134 ``y`` no matter what any other features say", and a value of positive
135 infinity means "definitely blame this ``y`` no matter what any other 135 infinity means "definitely blame this ``y`` no matter what any other
136 features say". Both of those special values should be used sparingly, 136 features say". Both of those special values should be used sparingly,
137 since they override the model's ability to combine multiple sources of 137 since they override the model's ability to combine multiple sources of
138 information and decide the cuplrit based on all the evidence together. 138 information and decide the cuplrit based on all the evidence together.
139 """ 139 """
140 raise NotImplementedError() 140 raise NotImplementedError()
141
142
143 class FeatureFunction(object):
144 """Given a dict of scalar-valued functions, return an dict-valued function.
145
146 Properties:
147 fs (iterable of functions): A collection of curried functions
148 ``X -> Y -> dict(FeatureValue)``. That is, given a particular ``x`` they
149 return a function ``Y -> dict(FeatureValue)``. N.B. each function should
150 have a name property.
wrengr 2017/01/12 19:09:09 The input functions don't return a dict(FV), they
Sharu Jiang 2017/01/13 01:08:34 Oops, I will stick to the option (b).
151 """
152 def __init__(self, fs):
153 self._fs = fs
154
155 def __call__(self, x):
156 """Fuction mapping ``X -> Y -> dict(A.name to A).
wrengr 2017/01/12 19:09:09 The ``A`` should be ``FeatureValue`` here as well
Sharu Jiang 2017/01/13 01:08:34 Done.
157
158 Returns:
159 A function ``X -> Y -> dict(A.name to A)`` where for all ``x``, ``y``, and
wrengr 2017/01/12 19:09:09 ditto
Sharu Jiang 2017/01/13 01:08:34 Done.
160 for a feature f in fs, we have
161 ``FeatureFunction(fs)(x)(y)[f.name] == f(x)(y)``.
162 """
163 name_to_fx = {f.name: f(x) for f in self._fs}
164 return lambda y: {name: fx(y) for name, fx in name_to_fx.iteritems()}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698