Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 an iterable of scalar-valued functions, return an dict function. | |
| 145 | |
| 146 Properties: | |
| 147 fs (iterable of functions): A collection of curried functions | |
| 148 ``X -> Y -> 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/25 21:54:27
I still say it'd be clearer to refer to the ``Feat
| |
| 151 """ | |
| 152 def __init__(self, fs): | |
| 153 self._fs = fs | |
| 154 | |
| 155 def __call__(self, x): | |
| 156 """Fuction mapping ``X -> Y -> dict(FeatureValue.name to FeatureValue). | |
| 157 | |
| 158 Returns: | |
| 159 A function ``X -> Y -> dict(FeatureValue.name to FeatureValue)`` where for | |
| 160 all ``x``, ``y``, and 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()} | |
| OLD | NEW |