Skip to content

temporian.EventSet.simple_moving_average #

    window_length: WindowLength,
    sampling: Optional[EventSetOrNode] = None,
) -> EventSetOrNode

Computes the average of values in a sliding window over an EventSet.

For each t in sampling, and for each feature independently, returns at time t the average value of the feature in the window (t - window_length, t].

sampling can't be specified if a variable window_length is specified (i.e. if window_length is an EventSet).

If sampling is specified or window_length is an EventSet, the moving window is sampled at each timestamp in them, else it is sampled on the input's.

Missing values (such as NaNs) are ignored.

If the window does not contain any values (e.g., all the values are missing, or the window does not contain any timestamp), outputs missing values.

>>> a = tp.event_set(
...     timestamps=[0, 1, 2, 5, 6, 7],
...     features={"value": [np.nan, 1, 5, 10, 15, 20]},
... )

>>> b = a.simple_moving_average(tp.duration.seconds(4))
>>> b
indexes: ...
    (6 events):
        timestamps: [0. 1. 2. 5. 6. 7.]
        'value': [ nan 1.  3. 7.5  12.5  15. ]

See EventSet.moving_count() for examples of moving window operations with external sampling and indices.


Name Type Description Default
window_length WindowLength

Sliding window's length.

sampling Optional[EventSetOrNode]

Timestamps to sample the sliding window's value at. If not provided, timestamps in the input are used.



Type Description

EventSet containing the moving average of each feature in the input.