Chromium Code Reviews| 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..4633c9f1869866e3e76dff39fcf75fdf05609a90 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 an iterable of scalar-valued functions, return an dict function. |
| + |
| + Properties: |
| + fs (iterable of functions): A collection of curried functions |
| + ``X -> Y -> 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/25 21:54:27
I still say it'd be clearer to refer to the ``Feat
|
| + """ |
| + def __init__(self, fs): |
| + self._fs = fs |
| + |
| + def __call__(self, x): |
| + """Fuction mapping ``X -> Y -> dict(FeatureValue.name to FeatureValue). |
| + |
| + Returns: |
| + A function ``X -> Y -> dict(FeatureValue.name to FeatureValue)`` where for |
| + all ``x``, ``y``, and 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()} |