temporian.EventSet.moving_product #
moving_product(
window_length: WindowLength,
sampling: Optional[EventSetOrNode] = None,
) -> EventSetOrNode
Computes the product of values in a sliding window over an
EventSet
.
This operation only supports floating-point features.
For each t in sampling, and for each feature independently, returns at time t the product of non-zero and non-NaN 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.
Zeros result in the accumulator's result being 0 for the window. NaN values are ignored in the calculation of the product. If the window does not contain any NaN, zero or any non-zero values (e.g., all values are missing), the output for that window is an empty array.
Example
>>> a = tp.event_set(
... timestamps=[0, 1, 2],
... features={"value": [np.nan, 1, 5]},
... )
>>> b = a.moving_product(tp.duration.seconds(1))
>>> b
indexes: ...
(3 events):
timestamps: [0. 1. 2.]
'value': [nan 1. 5.]
...
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 product of each feature in the input, |
EventSetOrNode
|
considering non-zero and non-NaN values only. |