neural_lam.models.forecasters.autoregressive#
Forecaster that uses an auto-regressive strategy to unroll a forecast.
Classes#
Subclass of Forecaster that uses an auto-regressive strategy to |
Module Contents#
- class neural_lam.models.forecasters.autoregressive.ARForecaster(predictor: neural_lam.models.step_predictors.base.StepPredictor, datastore: neural_lam.datastore.BaseDatastore)[source]#
Bases:
neural_lam.models.forecasters.base.ForecasterSubclass of Forecaster that uses an auto-regressive strategy to unroll a forecast. Makes use of a StepPredictor at each AR step.
Initialize the ARForecaster.
- Parameters:
predictor (StepPredictor) – The predictor to use for each step.
datastore (BaseDatastore) – The datastore providing grid metadata and boundary masks.
- forward(init_states: torch.Tensor, forcing_features: torch.Tensor, boundary_states: torch.Tensor) tuple[torch.Tensor, torch.Tensor | None][source]#
Unroll the autoregressive model: at each step
icallself.predictorto produce the next state, then overwrite boundary nodes with the true value fromboundary_states[:, i].- Parameters:
init_states (torch.Tensor) – Shape
(B, 2, num_grid_nodes, num_state_vars). The two initial states[X_{t-1}, X_t]used to start the rollout from. Dims:Bis batch size,2initial time steps (X_{t-1}, X_t),num_grid_nodesis the number of spatial nodes, andnum_state_varsis the number of state variables.forcing_features (torch.Tensor) – Shape
(B, pred_steps, num_grid_nodes, num_forcing_vars). Forcing features for each predicted step;pred_stepsdefines the rollout length. Dims:Bis batch size,pred_stepsis the number of predicted steps,num_grid_nodesis the number of spatial nodes, andnum_forcing_varsis the number of forcing variables (already concatenated past/current/future windows).boundary_states (torch.Tensor) – Shape
(B, pred_steps, num_grid_nodes, num_state_vars). True state values used ONLY to overwrite boundary nodes at each AR step. The interior prediction at stepimust not depend onboundary_states[:, i]in any other way. Dims:Bis batch size,pred_stepsis the number of predicted steps,num_grid_nodesis the number of spatial nodes, andnum_state_varsis the state feature dimension.
- Returns:
prediction (torch.Tensor) – Shape
(B, pred_steps, num_grid_nodes, num_state_vars). Stacked per-step forecasts (with boundary overwritten by the true value). Dims: same asboundary_states.pred_std (torch.Tensor or None) – Shape
(B, pred_steps, num_grid_nodes, num_state_vars)when the wrapped predictor outputs an std, otherwiseNone(in which caseForecasterModulesubstitutes the constant per-variable std). Dims: same asprediction.
- boundary_mask: torch.Tensor#
- interior_mask: torch.Tensor#
- predictor#