Inference Datasets

  • TorchInferenceDataset

  • SequentialTorchInferenceDataset

class darts.utils.data.torch_datasets.inference_dataset.SequentialTorchInferenceDataset(series, past_covariates=None, future_covariates=None, n=1, stride=0, bounds=None, input_chunk_length=12, output_chunk_length=1, output_chunk_shift=0, use_static_covariates=True)[source]

Bases: TorchInferenceDataset

Sequential Inference Dataset

Each sample drawn from this dataset is an eight-element tuple extracted from a specific time window and set of single input TimeSeries. The elements are:

  • past_target: target series values in the input chunk

  • past_covariates: past_covariates values in the input chunk (None if past_covariates=None)

  • future_past_covariates: past_covariates values in the forecast horizon (None if past_covariates=None or n<=output_chunk_length / non-auto-regressive forecasting)

  • historic_future_covariates: future_covariates values in the input chunk (None if future_covariates=None)

  • future_covariates: future_covariates values in the forecast horizon (None if future_covariates=None)

  • static_covariates: static_covariates values of the series (None if use_static_covariates=False)

  • target_series: the target TimeSeries

  • pred_time: the time of the first point in the forecast horizon

The output chunk / forecast horizon starts output_chunk_length + output_chunk_shift after the input chunk’s start.

The sample index determines:

  • the position / time of the extracted chunks relative to the end of a single target series

  • the index (which series and covariates) to use in case series (and covariates) are passed as a sequence of series.

With bounds=None, all samples will be extracted relative to the end of the target series (input chunk’s end time is the same as the target series’ end time). Otherwise, samples will be extracted from the given boundaries bounds with a stride of stride.

Note

“historic_future_covariates” are the values of the future-known covariates that fall into the sample’s input chunk (the past window / history in the view of the sample).

Note

“future_past_covariates” are past covariates that happen to be also known in the future - those are needed for forecasting with n > output_chunk_length (auto-regression) by any model relying on past covariates. For this reason, this dataset may also emit the “future past_covariates”.

Parameters
  • series (Union[TimeSeries, Sequence[TimeSeries]]) – One or a sequence of target TimeSeries that are to be predicted into the future.

  • past_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, one or a sequence of TimeSeries containing past covariates. If past covariates were used during training, they must be supplied at prediction.

  • future_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, one or a sequence of TimeSeries containing future-known covariates. If future covariates were used during training, they must be supplied at prediction.

  • n (int) – Forecast horizon: The number of time steps to predict after the end of the target series.

  • stride (int) – Optionally, the number of time steps between two consecutive predictions. Can only be used together with bounds.

  • bounds (Optional[ndarray, None]) – Optionally, an array of shape (n series, 2), with the left and right prediction start point boundaries per series. The boundaries must represent the positional index of the series (0, len(series)). If provided, stride must be >=1.

  • input_chunk_length (int) – The length of the lookback / past window the model takes as input.

  • output_chunk_length (int) – The length of the lookahead / future window that the model emits as output (for the target) and takes as input (for future covariates).

  • output_chunk_shift (int) – Optionally, the number of steps to shift the start of the output chunk into the future.

  • use_static_covariates (bool) – Whether to use/include static covariate data from the target series.

class darts.utils.data.torch_datasets.inference_dataset.TorchInferenceDataset[source]

Bases: TorchDataset, ABC

Abstract class for all inference datasets that can be used with Darts’ TorchForecastingModel.

Provides samples to compute forecasts using a TorchForecastingModel.

Each sample drawn from this dataset is an eight-element tuple extracted from a specific time window and set of single input TimeSeries. The elements are:

  • past_target: target series values in the input chunk

  • past_covariates: Optional past_covariates values in the input chunk

  • future_past_covariates: Optional past_covariates values in the forecast horizon (for auto-regression with n>output_chunk_length)

  • historic_future_covariates: Optional future_covariates values in the input chunk

  • future_covariates: Optional future_covariates values in the output chunk and forecast horizon

  • static_covariates: Optional static_covariates values of the series

  • target_series: the target TimeSeries

  • pred_time: the time of the first point in the forecast horizon

Darts TorchForecastingModel can predict from instances of TorchInferenceDataset using the predict_from_dataset() method.

TorchInferenceDataset inherits from torch Dataset; meaning that all subclasses must implement the __getitem__() method. All returned elements except target_series (TimeSeries) and pred_time (pd.Timestamp or int) must be of type np.ndarray (or None for optional covariates).