staircase.Stairs.rolling_mean#

Stairs.rolling_mean(window=(0, 0), where=(<staircase.constants.NegInf object>, <staircase.constants.Inf object>))#

Returns coordinates defining rolling mean

The rolling mean of a step function is a continous piece-wise linear function, hence it can be described by a sequence of x,y coordinates which mark where function changes gradient. These x,y coordinates are returned as a pandas.Series which could then be used with matplotlib.axes.Axes.plot(), or equivalent, to visualise.

A rolling mean requires a window around a point x (referred to as the focal point) to be defined. In this implementation the window is defined by two values paired into an array-like parameter called window. These two numbers are the distance from the focal point to the left boundary of the window, and the right boundary of the window respectively. This allows for trailing windows, leading windows and everything between (including a centred window).

Parameters
windowarray-like of int, float or pandas.Timedelta

should be length of 2. Defines distances from focal point to window boundaries.

wheretuple or list of length two, optional

Indicates the domain interval over which to evaluate the step function. Default is (-sc.inf, sc.inf) or equivalently (None, None).

Returns
pandas.Series

See also

Stairs.mean

Examples

>>> s2.rolling_mean(window=[-0.5, 0.5])
-0.5    0.0
 0.5    0.5
 1.5    0.5
 2.5    0.0
 3.5   -1.0
 5.0   -1.0
 6.0    0.0
dtype: float64
>>> series_list = [s2.rolling_mean(window=[-0.5, 0.5]), s2.rolling_mean(window=[-0.5, 0.5], where=(0, 5.5))]
>>> fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(7,3), sharey=True, sharex=True, tight_layout=True, dpi=400)
>>> for ax, title, series in zip(axes, ("default", "'where' specified"), series_list):
...     s2.plot(ax=ax)
...     series.plot(ax=ax, label='rolling mean')
...     ax.set_title(title)
...     ax.legend()
../../_images/staircase-Stairs-rolling_mean-1.png
>>> series_list = [s2.rolling_mean(window=[-1, 0], where=(0, 5.5)), s2.rolling_mean(window=[0, 1], where=(0, 5.5))]
>>> fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8,3), sharey=True, sharex=True, tight_layout=True, dpi=400)
>>> for ax, title, series in zip(axes, ("trailing window", "leading window"), series_list):
...     s2.plot(ax=ax)
...     series.plot(ax=ax, label='rolling mean')
...     ax.set_title(title)
...     ax.legend()
../../_images/staircase-Stairs-rolling_mean-2.png