Skip to content

Moving Average Utility

Time-series smoothing utilities.

This module provides simple and exponential moving-average functions for smoothing one-dimensional data series commonly produced by ReaxFF simulations, such as energies, bond orders, dipole moments, or polarization signals.

Typical use cases include:

  • reducing high-frequency noise in MD trajectories
  • smoothing field-response or hysteresis curves
  • preparing time-series data for extrema or trend analysis

exponential_moving_average(y, *, window=None, alpha=None, adjust=False)

Compute an exponential moving average (EMA) of a 1D data series.

The exponential moving average applies exponentially decreasing weights to past observations. The smoothing factor may be specified directly via alpha or indirectly via a window size.

Parameters:

Name Type Description Default
y array - like

Input data values to smooth.

required
window int

Window size used to derive the smoothing factor (alpha = 2 / (window + 1)).

None
alpha float

Smoothing factor in the interval (0, 1].

None
adjust bool

Whether to use bias-adjusted weights.

False

Returns:

Type Description
Series

Smoothed data series using an exponential moving average.

Examples:

>>> exponential_moving_average(signal, window=8)
>>> exponential_moving_average(signal, alpha=0.2)

simple_moving_average(y, window=5, *, center=True, min_periods=1)

Compute a simple moving average (SMA) of a 1D data series.

The moving average is computed over a fixed-size sliding window and returned as a pandas Series. If the input is already a Series, its index is preserved.

Parameters:

Name Type Description Default
y array - like

Input data values to smooth.

required
window int

Size of the moving window.

5
center bool

Whether the window is centered on each data point.

True
min_periods int

Minimum number of observations required to compute a value.

1

Returns:

Type Description
Series

Smoothed data series using a simple moving average.

Examples:

>>> simple_moving_average(energy, window=10)