StackedForecastLSTM
- class neuralhydrology.modelzoo.stacked_forecast_lstm.StackedForecastLSTM(cfg: Config)
Bases:
BaseModel
A 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 hindcast and forecast sequences must be the same length, and the
forecast_overlap
config parameter must be set to the correct overlap between these two sequences. For example, if we want to use a hindcast sequence length of 365 days to make a 7-day forecast, thenseq_length
andforecast_seq_length
must both be set to 365, andforecast_overlap
must be set to 358 (=365-7). Outputs from the hindcast LSTM are concatenated to the input sequences to the forecast LSTM. This causes a lag of length (seq_length
-forecast_overlap
) timesteps between the latest hindcast data and the newest forecast point, meaning that forecasts do not get information from the most recent dynamic inputs. To solve this, set thebidirectional_stacked_forecast_lstm
config parameter to True, so that the hindcast LSTM runs bidirectional and therefore all outputs from the hindcast LSTM receive information from the most recent dynamic input data.- Parameters:
cfg (Config) – The run configuration.
- forward(data: Dict[str, Tensor]) Dict[str, Tensor]
Perform a forward pass on the StackedForecastLSTM model.
- Parameters:
data (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']