MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / smooth

Function smooth

numpy_ml/bandits/trainer.py:42–76  ·  view source on GitHub ↗

r""" Compute a simple weighted average of the previous and current value. Notes ----- The smoothed value at timestep `t`, :math:`\tilde{X}_t` is calculated as .. math:: \tilde{X}_t = \epsilon \tilde{X}_{t-1} + (1 - \epsilon) X_t where :math:`X_t` is the value at t

(prev, cur, weight)

Source from the content-addressed store, hash-verified

40
41
42def smooth(prev, cur, weight):
43 r"""
44 Compute a simple weighted average of the previous and current value.
45
46 Notes
47 -----
48 The smoothed value at timestep `t`, :math:`\tilde{X}_t` is calculated as
49
50 .. math::
51
52 \tilde{X}_t = \epsilon \tilde{X}_{t-1} + (1 - \epsilon) X_t
53
54 where :math:`X_t` is the value at timestep `t`, :math:`\tilde{X}_{t-1}` is
55 the value of the smoothed signal at timestep `t-1`, and :math:`\epsilon` is
56 the smoothing weight.
57
58 Parameters
59 ----------
60 prev : float or :py:class:`ndarray <numpy.ndarray>` of shape `(N,)`
61 The value of the smoothed signal at the immediately preceding
62 timestep.
63 cur : float or :py:class:`ndarray <numpy.ndarray>` of shape `(N,)`
64 The value of the signal at the current timestep
65 weight : float or :py:class:`ndarray <numpy.ndarray>` of shape `(N,)`
66 The smoothing weight. Values closer to 0 result in less smoothing,
67 values closer to 1 produce more aggressive smoothing. If weight is an
68 array, each dimension will be interpreted as a separate smoothing
69 weight the corresponding dimension in `cur`.
70
71 Returns
72 -------
73 smoothed : float or :py:class:`ndarray <numpy.ndarray>` of shape `(N,)`
74 The smoothed signal
75 """
76 return weight * prev + (1 - weight) * cur
77
78
79class BanditTrainer:

Callers 1

_smoothed_metricsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected