reverse_windowing¶
- reverse_windowing(y: ~numpy.ndarray, window_size: int, reduction: ~typing.Callable[[...], ~numpy.ndarray] = <function nanmean>, stride: int = 1, padding_length: int | None = None, force_iterative: bool = False) ndarray [source]¶
Aggregate windowed results for each point of the original time series.
Reverse windowing is the inverse operation of sliding windows. It aggregates the windowed results for each point of the original time series. The aggregation is performed with a reduction function, e.g., np.nanmean, np.nanmedian, or np.nanmax. An aggregation function ignoring NaN values is required to handle the padding.
The resulting time series has the same length as the original time series, namely n_timepoints = (n_windows - 1) * stride + window_size + padding_length.
For a time series of length 10, a window size of 3, and a stride of 2, there are four windows. Assuming the following result as input to this function y = np.array([1, 4, 8, 2]), the example shows the aggregation of the windowed results using the np.nanmean reduction function:
- mapped = 1 1 2.5 4 6 8 5 2 2 0
y[0] = 1 1 1 y[1] = 4 4 4 y[2] = 8 8 8 y[3] = 2 2 2
- Parameters:
- ynp.ndarray
Array of windowed results with the shape (n_windows,).
- window_sizeint
Size of the sliding windows.
- reductioncallable, optional, default=np.nanmean
Reduction function to aggregate the windowed results. The function must accept an axis argument to specify the axis along which the reduction is applied. It is required to ignore NaN values to handle the padding on the edges.
- strideint, optional, default=1
Stride of the sliding windows. If stride is greater than 1, the windows have skipped over some time points. If stride is unequal 1,
padding_length
must be provided as well.- padding_lengthint, optional
Number of time points at the end of the time series that are not covered by any windows. Must be provided if
stride
is not 1.- force_iterativebool, optional, default=False
Force iterative reverse windowing function to limit memory usage. If False, the function will choose the most efficient reverse windowing function based on the available memory trading off between memory usage and speed.
- Returns:
- mappednp.ndarray
Array of mapped results with the shape (n_timepoints,). The mapped results are aggregated windowed results for each point of the original time series.
Examples
>>> import numpy as np >>> from aeon.utils.windowing import sliding_windows, reverse_windowing >>> X = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) >>> windows, padding_length = sliding_windows(X, window_size=3, stride=2) >>> y = np.array([0.5, 0.6, 0.5, 0.8]) >>> reverse_windowing(y, window_size=3, stride=2, padding_length=padding_length) array([0.5 , 0.5 , 0.55, 0.6 , 0.55, 0.5 , 0.65, 0.8 , 0.8 , 0. ])