temporian.EventSet.moving_count #
moving_count(
window_length: WindowLength,
sampling: Optional[EventSetOrNode] = None,
) -> EventSetOrNode
Gets the number of events in a sliding window.
Create a tp.int32 feature containing the number of events in the time 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.
Example without sampling
>>> a = tp.event_set(timestamps=[0, 1, 2, 5, 6, 7])
>>> b = a.moving_count(tp.duration.seconds(2))
>>> b
indexes: ...
(6 events):
timestamps: [0. 1. 2. 5. 6. 7.]
'count': [1 2 2 1 2 2]
...
Example with sampling
>>> a = tp.event_set(timestamps=[0, 1, 2, 5])
>>> b = tp.event_set(timestamps=[-1, 0, 1, 2, 3, 4, 5, 6, 7])
>>> c = a.moving_count(tp.duration.seconds(2), sampling=b)
>>> c
indexes: ...
(9 events):
timestamps: [-1. 0. 1. 2. 3. 4. 5. 6. 7.]
'count': [0 1 2 2 1 0 1 1 0]
...
Example with variable window length
>>> a = tp.event_set(timestamps=[0, 1, 2, 5])
>>> b = tp.event_set(
... timestamps=[0, 3, 3, 3, 9],
... features={
... "w": [1, 0.5, 3.5, 2.5, 5],
... },
... )
>>> c = a.moving_count(window_length=b)
>>> c
indexes: []
features: [('count', int32)]
events:
(5 events):
timestamps: [0. 3. 3. 3. 9.]
'count': [1 0 3 2 1]
...
Example with index
>>> a = tp.event_set(
... timestamps=[1, 2, 3, 0, 1, 2],
... features={
... "idx": ["i1", "i1", "i1", "i2", "i2", "i2"],
... },
... indexes=["idx"],
... )
>>> b = a.moving_count(tp.duration.seconds(2))
>>> b
indexes: [('idx', str_)]
features: [('count', int32)]
events:
idx=b'i1' (3 events):
timestamps: [1. 2. 3.]
'count': [1 2 2]
idx=b'i2' (3 events):
timestamps: [0. 1. 2.]
'count': [1 2 2]
...
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 |
None
|
Returns:
Type | Description |
---|---|
EventSetOrNode
|
EventSet containing the count of events in |