StackedForecastLSTM
- class neuralhydrology.modelzoo.stacked_forecast_lstm.StackedForecastLSTM(cfg: Config)
Bases:
BaseModelA forecasting model using stacked LSTMs for hindcast and forecast.
This is a forecasting model that uses two stacked sequential (LSTM) models to handle hindcast vs. forecast.
The total sequence length
seq_lengthconfig parameter must be equal to the total hindcast + forecast time ranges.The forecast sequence length
forecast_seq_lengthconfig parameter must be equal to the overlapping portion of the hindcast and forecast models plus the forecast time period.The
forecast_overlapconfig parameter must be set to the correct overlap between these two sequences.For example, if we want to use a spinup period of 365 days to make a 7-day forecast, then
seq_lengthmust be set to 372 (=365+7),forecast_seq_lengthmust be set to 365, andforecast_overlapmust be set to 358 (=365-7).Outputs from the hindcast LSTM are concatenated to the input sequences to the forecast LSTM and shifted in time by the forecast horizon (7 days in the example above. This causes a lag between the latest hindcast data and the newest forecast time point, meaning that forecasts do not get information from the most recent hindcast inputs. To solve this, set the
bidirectional_stacked_forecast_lstmconfig parameter to True, so that the hindcast LSTM runs bidirectional and therefore all outputs from the hindcast LSTM receive information from the most recent hindcast input data.- Parameters:
cfg (Config) – The run configuration.
- forward(data: dict[str, Tensor | dict[str, Tensor]]) Dict[str, Tensor]
Perform a forward pass on the StackedForecastLSTM model.
- Parameters:
data (dict[str, torch.Tensor | dict[str, torch.Tensor]]) – Dictionary, containing input features as key-value pairs.
- Returns:
- Model outputs and intermediate states as a dictionary.
lstm_output_hindcast: Output sequence from the hindcast LSTM.
lstm_output_forecast: Output sequence from the forecast LSTM.
y_hat: Predictions over the sequence from the head layer.
- Return type:
Dict[str, torch.Tensor]
- Raises:
ValueError if hindcast and forecast sequences are not equal. –
- module_parts = ['hindcast_embedding_net', 'forecast_embedding_net', 'forecast_lstm', 'hindcast_lstm', 'head']