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 a dict of scalar-valued functions, return an dict-valued function. | |
| 145 | |
| 146 Properties: | |
| 147 fs (list of functions): A collection of curried functions ``X -> Y -> A``. | |
|
wrengr
2017/01/11 20:38:30
Type of ``fs`` should be an iterable of ``Feature`
Sharu Jiang
2017/01/12 01:41:38
Acknowledged.
| |
| 148 That is, given a particular ``x`` they return a function ``Y -> A``. N.B. | |
| 149 each function should have a name property. | |
| 150 """ | |
| 151 def __init__(self, fs): | |
| 152 self._fs = fs | |
| 153 | |
| 154 def __call__(self, x): | |
| 155 """Fuction mapping ``X -> Y -> dict(A.name to A). | |
| 156 | |
| 157 Returns: | |
| 158 A function ``X -> Y -> dict(A.name to A)`` where for all ``x``, ``y``, and | |
| 159 for a feature f in fs, we have | |
| 160 ``ToFeatureFunction(fs)(x)(y)[f.name] == f(x)(y)``. | |
|
wrengr
2017/01/11 20:38:30
the name "ToFeatureFunction"is no longer used anyw
Sharu Jiang
2017/01/12 01:41:38
Done.
| |
| 161 """ | |
| 162 name_to_fx = {f.name: f(x) for f in self._fs} | |
| 163 return lambda y: {name: fx(y) for name, fx in name_to_fx.iteritems()} | |
| OLD | NEW |