shredx.datasets.dataloaders.TimeSeriesDataset#
- class shredx.datasets.dataloaders.TimeSeriesDataset(input_tensors: list[Float[Tensor, 'time_steps ...']], length: int, output_tensors: list[Float[Tensor, 'time_steps ...']] | None = None, device: str = 'cpu')#
Bases:
DatasetDataset of sliding windows over time series tensors.
Builds a dataset from lists of input and output tensors, each of shape
(time_steps, ...). Assumes input and output tensors have the same shape. Input and output windows are returned separately to support use with proper orthogonal decomposition; they can be split or concatenated as needed when used.- Parameters:
- input_tensorslist of torch.Tensor
List of input tensors, each a time series of shape
(time_steps, ...).- lengthint
Length of each sliding window.
- output_tensorslist of torch.Tensor, optional
List of output tensors, each of shape
(time_steps, ...). IfNone, output windows are the same as input windows. Default isNone.- devicestr, optional
Device to place tensors on. Default is
"cpu".
Methods
prepare_tensors(tensors)Prepare a list of tensors for use in the dataset.
- Raises:
- ValueError
If no valid windows can be created (e.g. tensor lengths too short for
length).
Notes
Class Methods:
__len__():
Returns the total number of valid windows across all tensors.
- Returns:
int. Total number of windows.
__getitem__(index):
Returns the input and output windows for a given index.
- Parameters:
index : int. Index of the window to return.
- Returns:
tuple of
(Float[torch.Tensor, "length ..."], Float[torch.Tensor, "length ..."]).(input_window, output_window), each of shape(length, ...).
prepare_tensors(tensors):
Converts a list of tensors to float32 and moves them to the configured device.
- Parameters:
tensors : list of
Float[torch.Tensor, "time_steps ..."]. List of tensors to prepare.
- Returns:
list of
Float[torch.Tensor, "time_steps ..."]. Tensors on the correct device in float32.