MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / EMA

Class EMA

pager_lib/tqdm/std.py:213–241  ·  view source on GitHub ↗

Exponential moving average: smoothing to give progressively lower weights to older values. Parameters ---------- smoothing : float, optional Smoothing factor in range [0, 1], [default: 0.3]. Increase to give more weight to recent values. Ranges from 0 (

Source from the content-addressed store, hash-verified

211
212
213class EMA:
214 """
215 Exponential moving average: smoothing to give progressively lower
216 weights to older values.
217
218 Parameters
219 ----------
220 smoothing : float, optional
221 Smoothing factor in range [0, 1], [default: 0.3].
222 Increase to give more weight to recent values.
223 Ranges from 0 (yields old value) to 1 (yields new value).
224 """
225 def __init__(self, smoothing=0.3):
226 self.alpha = smoothing
227 self.last = 0
228 self.calls = 0
229
230 def __call__(self, x=None):
231 """
232 Parameters
233 ----------
234 x : float
235 New value to include in EMA.
236 """
237 beta = 1 - self.alpha
238 if x is not None:
239 self.last = self.alpha * x + beta * self.last
240 self.calls += 1
241 return self.last / (1 - beta ** self.calls) if self.calls else self.last
242
243
244class tqdm(Comparable):

Callers 2

__init__Method · 0.85
resetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected