Skip to content

Moving Average Utility

Smooth one-dimensional time-series data using moving-average methods.

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.

Usage context

  • Noise reduction: Suppress high-frequency variance in MD trajectories.
  • Curve conditioning: Smooth field-response or hysteresis signals.
  • Preprocessing: Prepare series for extrema and trend analysis steps.

Function: simple_moving_average

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
Notes
  • This function uses pandas.Series.rolling under the hood for SMA computation.
  • Main documentation for pandas.Series.rolling: https://pandas.pydata.org/docs/reference/api/pandas.Series.rolling.html
  • An example is at: https://www.geeksforgeeks.org/python/pandas-rolling-mean-by-time-interval/

Returns:

Type Description
Series

Smoothed data series using a simple moving average.

Examples:

>>> simple_moving_average(energy, window=10)

Function: exponential_moving_average

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
Notes
  • This function uses pandas.Series.ewm under the hood for EMA computation.
  • Main documentation for pandas.Series.ewm: https://pandas.pydata.org/docs/reference/api/pandas.Series.ewm.html
  • An example is at: https://aleksandarhaber.com/exponential-moving-average-in-pandas-and-python/

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)