EMAReducer¶
- class EMAReducer(step_time: float, alpha: float, duration: float = 0.0, inclusive: bool = False, inplace: bool = False)[source]¶
Bases:
FoldReducerStores the exponential moving average.
\[\begin{split}\begin{align*} s_0 &= x_0 \\ s_{t + 1} &= \alpha x_{t + 1} + (1 - \alpha) s_t \end{align*}\end{split}\]For the smoothed data (state) \(s\) and observation \(x\) and where smoothing factor \(\alpha\) is as follows.
\[\alpha = 1 - \exp \left(\frac{-\Delta t}{\tau}\right)\]For some time constant \(\tau\).
- Parameters:
step_time (float) – length of time between observations, \(\Delta t\).
alpha (float) – exponential smoothing factor, \(\alpha\).
duration (float, optional) – length of time over which results should be stored, in the same units as \(\Delta t\). Defaults to
0.0.inclusive (bool, optional) – if the duration should be inclusive. Defaults to
False.inplace (bool, optional) – if write operations should be performed in-place. Defaults to
False.
Note
alphais decoupled from the step time, so if the step time changes, then theunderlying time constant will change,
alphawill remain the same.
- fold(obs: Tensor, state: Tensor | None) Tensor[source]¶
Application of exponential smoothing.
- Parameters:
obs (torch.Tensor) – observation to incorporate into state.
state (torch.Tensor | None) – state from the prior time step,
Noneif no prior observations.
- Returns:
state for the current time step.
- Return type:
- interpolate(prev_data: Tensor, next_data: Tensor, sample_at: Tensor, step_time: float) Tensor[source]¶
Linear interpolation between observations.
- Parameters:
prev_data (torch.Tensor) – most recent observation prior to sample time.
next_data (torch.Tensor) – most recent observation subsequent to sample time.
sample_at (torch.Tensor) – relative time at which to sample data.
step_time (float) – length of time between the prior and subsequent observations.
- Returns:
interpolated data at sample time.
- Return type: