Create Input for Recurrent Networks

Module

prosper_nn.utils.create_input_ecnn_hcnn.create_input(Y: Tensor, past_horizon: int, batchsize: int, U: Tensor | None = None, future_U: bool | None = False, forecast_horizon: int | None = None) Tuple[Tensor, Tensor][source]

Takes time series of target variable Y and (optional) external variables U and reshapes them to be used for ecnn or hcnn or any model based on them.

Parameters:
  • Y (torch.Tensor) – The time series of the target variable. Should be of shape=(length of time series, n_features_Y).

  • past_horizon (int) – The sequence length that is meant to be used for predictions.

  • batchsize (int)

  • U (Optional[torch.Tensor]) – The time series of the inputs (external/explanatory variables). Should be of shape=(length of time series, n_features_U). If no U is given, the input for a hcnn model is created.

  • future_U (boolean) – Is U also known in the future? Then a sequence of U should have length past_horizon+forecast_horizon, else past_horizon.

  • forecast_horizon (int) – If future_U is true, this is used to create U_batches.

Returns:

  • Y_batches (torch.Tensor) – Reshaped target variable that can be used for ECNNs or HCNNs. shape=(n_seqs, past_horizon, batchsize, n_features_Y).

  • U_batches (torch.Tensor) – Only if U has been passed. Reshaped inputs that can be used for ECNNs. shape=(n_seqs, past_horizon, batchsize, n_features_U) or shape=(n_seqs, past_horizon+forecast_horizon, batchsize, n_features_U), depending on future_U.

Example

>>> Y, U = sample_data(100, 1, 3)
>>> Y_batches, U_batches = ci.create_input(Y, 20, 2, U, False)
>>> print(Y_batches.shape)
>>> print(U_batches.shape)
torch.Size([5, 20, 2, 1])
torch.Size([5, 20, 2, 3])