Skip to content

temporian.EventSet.moving_sum #

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

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

For each t in sampling, and for each feature independently, returns at time t the sum of values for 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 sampling), outputs missing values.

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

>>> b = a.moving_sum(tp.duration.seconds(4))
>>> b
indexes: ...
    (6 events):
        timestamps: [0. 1. 2. 5. 6. 7.]
        'value': [ 0. 1.  6.  15.  25.  45.]
...

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

Parameters:

Name Type Description Default
window_length WindowLength

Sliding window's length.

required
sampling Optional[EventSetOrNode]

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

None

Returns:

Type Description
EventSetOrNode

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