neural_lam.models.step_predictors.base#
Base class for step predictors.
Classes#
Abstract base class for step predictors mapping from the two previous |
Module Contents#
- class neural_lam.models.step_predictors.base.StepPredictor(datastore: neural_lam.datastore.BaseDatastore, output_std: bool = False, output_clamping_lower: dict[str, float] | None = None, output_clamping_upper: dict[str, float] | None = None)[source]#
Bases:
torch.nn.Module,abc.ABCAbstract base class for step predictors mapping from the two previous time steps plus forcing into a prediction of the next state.
Initialize the StepPredictor.
- Parameters:
datastore (BaseDatastore) – The datastore providing grid metadata and data access.
output_std (bool, default False) – Whether to output a predicted standard deviation.
output_clamping_lower (dict, optional) – Lower clamping limits for state variables.
output_clamping_upper (dict, optional) – Upper clamping limits for state variables.
- expand_to_batch(x: torch.Tensor, batch_size: int) torch.Tensor[source]#
Expand a shared node-feature tensor into a batch of copies.
- Parameters:
x (torch.Tensor) – Shape
(N, d). Tensor to expand. Dims:Nis the number of nodes anddis the feature dimension.batch_size (int) – Target batch size
B.
- Returns:
Shape
(B, N, d). Batch-expanded view ofx.- Return type:
- abstract forward(prev_state: torch.Tensor, prev_prev_state: torch.Tensor, forcing: torch.Tensor) tuple[torch.Tensor, torch.Tensor | None][source]#
Advance the state by one step:
(X_t, X_{t-1}, forcing_t) -> X_{t+1}.- Parameters:
prev_state (torch.Tensor) – Shape
(B, num_grid_nodes, num_state_vars). The current stateX_t. Dims:Bis batch size,num_grid_nodesis the number of spatial nodes, andnum_state_varsis the number of state variables.prev_prev_state (torch.Tensor) – Shape
(B, num_grid_nodes, num_state_vars). The previous stateX_{t-1}, used as additional conditioning. Dims: same asprev_state.forcing (torch.Tensor) – Shape
(B, num_grid_nodes, num_forcing_vars). External forcings for this step (already concatenated past/current/future windows). Dims:Bis batch size,num_grid_nodesis the number of spatial nodes, andnum_forcing_varsis the forcing feature dimension.
- Returns:
pred_state (torch.Tensor) – Shape
(B, num_grid_nodes, num_state_vars). The predicted next stateX_{t+1}. Dims: same asprev_state.pred_std (torch.Tensor or None) – Shape
(B, num_grid_nodes, num_state_vars)whenoutput_stdis True, otherwiseNone. Per-feature predicted standard deviation. Dims: same asprev_state.
- get_clamped_new_state(state_delta: torch.Tensor, prev_state: torch.Tensor) torch.Tensor[source]#
Clamp the next-state prediction to its valid feature range.
Instead of the plain residual update
X_{t+1} = X_t + delta, the clamped form isX_{t+1} = f(f^{-1}(X_t) + delta)so the model learns to output increments in the domain of the inverse clamping function.- Parameters:
state_delta (torch.Tensor) – Shape
(B, num_grid_nodes, num_state_vars). Raw predicted state increment (network output, already rescaled). Dims:Bis batch size,num_grid_nodesis the number of spatial nodes, andnum_state_varsis the number of state variables.prev_state (torch.Tensor) – Shape
(B, num_grid_nodes, num_state_vars). Current stateX_tused as the base for the clamped update. Dims: same asstate_delta.
- Returns:
Shape
(B, num_grid_nodes, num_state_vars). Clamped next state. Dims: same asstate_delta.- Return type:
- prepare_clamping_params(datastore: neural_lam.datastore.BaseDatastore) None[source]#
Prepare parameters for clamping predicted values to valid range.
Reads the per-feature lower/upper limits from
self._output_clamping_lowerandself._output_clamping_upper(set in__init__) and registers the buffers and clamping functions used byget_clamped_new_state.- Parameters:
datastore (BaseDatastore) – The datastore providing variable names.
- clamp_lower_idx: torch.Tensor#
- clamp_lower_upper_idx: torch.Tensor#
- clamp_upper_idx: torch.Tensor#
- grid_static_features: torch.Tensor#
- output_std = False#
- property predicts_std: bool#
Whether this predictor outputs a predicted standard deviation.
- Returns:
Trueif the predictor predicts standard deviation,Falseotherwise.- Return type:
- sigmoid_lower_lims: torch.Tensor#
- sigmoid_upper_lims: torch.Tensor#
- softplus_lower_lims: torch.Tensor#
- softplus_upper_lims: torch.Tensor#
- state_mean: torch.Tensor#
- state_std: torch.Tensor#