neural_lam.models.forecasters.base#
Base class for forecasters.
Classes#
Generic forecaster capable of mapping from a set of initial states, |
Module Contents#
- class neural_lam.models.forecasters.base.Forecaster(*args: Any, **kwargs: Any)[source]#
Bases:
torch.nn.Module,abc.ABCGeneric forecaster capable of mapping from a set of initial states, forcing and forces and previous states into a full forecast of the requested length.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- abstract forward(init_states: torch.Tensor, forcing_features: torch.Tensor, boundary_states: torch.Tensor) tuple[torch.Tensor, torch.Tensor | None][source]#
Produce a forecast of length
pred_stepsfrom two initial states, the per-step forcing features, and the per-step true boundary states.- 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 forecast from. Dims:Bis batch size,2is the time index ([X_{t-1}, X_t]),num_grid_nodesis the number of spatial nodes, andnum_state_varsis the state feature dimension.forcing_features (torch.Tensor) – Shape
(B, pred_steps, num_grid_nodes, num_forcing_vars). External forcings provided at each predicted step. Dims:Bis batch size,pred_stepsis the autoregressive rollout length,num_grid_nodesis the number of spatial nodes, andnum_forcing_varsis the forcing feature dimension (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; interior predictions must not depend onboundary_statesin any other way. Dims:Bis batch size,pred_stepsis the rollout length,num_grid_nodesis the number of spatial nodes, andnum_state_varsis the state feature dimension. This is a temporary mechanism that mirrors the pre-refactor ARModel behavior; it will be replaced by a dedicated boundary-forcing input in #138 (training on interior + boundary datastore), at which point this parameter will be removed.
- Returns:
prediction (torch.Tensor) – Shape
(B, pred_steps, num_grid_nodes, num_state_vars). Forecast of state at each predicted step. Dims: same asboundary_states.pred_std (torch.Tensor or None) – Shape
(B, pred_steps, num_grid_nodes, num_state_vars)whenpredicts_stdis True, otherwiseNone. Per-feature predicted standard deviation; whenNone, the constant per-variable std is substituted upstream byForecasterModule. Dims: same asprediction.