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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: appengine/findit/crash/loglinear/feature.py
diff --git a/appengine/findit/crash/loglinear/feature.py b/appengine/findit/crash/loglinear/feature.py
index 20cda371f4b9ab7c92d40f972f748ebddb8a1f76..097e67ae7355c428172f47ebe6e1245bc8fdf65d 100644
--- a/appengine/findit/crash/loglinear/feature.py
+++ b/appengine/findit/crash/loglinear/feature.py
@@ -138,3 +138,27 @@ class Feature(object):
information and decide the cuplrit based on all the evidence together.
"""
raise NotImplementedError()
+
+
+class FeatureFunction(object):
+ """Given a dict of scalar-valued functions, return an dict-valued function.
+
+ Properties:
+ fs (iterable of functions): A collection of curried functions
+ ``X -> Y -> dict(FeatureValue)``. That is, given a particular ``x`` they
+ return a function ``Y -> dict(FeatureValue)``. N.B. each function should
+ 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).
+ """
+ def __init__(self, fs):
+ self._fs = fs
+
+ def __call__(self, x):
+ """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.
+
+ Returns:
+ 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.
+ for a feature f in fs, we have
+ ``FeatureFunction(fs)(x)(y)[f.name] == f(x)(y)``.
+ """
+ name_to_fx = {f.name: f(x) for f in self._fs}
+ return lambda y: {name: fx(y) for name, fx in name_to_fx.iteritems()}

Powered by Google App Engine
This is Rietveld 408576698