Skip to content

Rolling

A generic wrapper for performing rolling computations.

This can be wrapped around any object which implements both an update and a revert method. Inputs to update are stored in a queue. Elements of the queue are popped when the window is full.

Parameters

  • obj

    TypeRollable

    An object that implements both an update method and a rollingmethod.

  • window_size

    Typeint

    Size of the window.

Attributes

  • window_size

Examples

For instance, here is how you can compute a rolling average over a window of size 3:

from river import stats, utils

X = [1, 3, 5, 7]
rmean = utils.Rolling(stats.Mean(), window_size=3)

for x in X:
    print(rmean.update(x).get())
1.0
2.0
3.0
5.0

Methods

update