neural_lam.models.modules.deterministic#
Lightning module evaluating forecasters through a single deterministic forecast per batch.
Classes#
Lightning module for a single deterministic forecast per batch. |
Module Contents#
- class neural_lam.models.modules.deterministic.DeterministicForecastingModule(forecaster: neural_lam.models.forecasters.deterministic.BaseDeterministicForecaster, config: neural_lam.config.NeuralLAMConfig, datastore: neural_lam.datastore.base.BaseDatastore, datastore_boundary: neural_lam.datastore.base.BaseDatastore | None = None, lr: float = 0.001, restore_opt: bool = False, n_example_pred: int = 1, create_gif: bool = False, val_steps_to_log: list[int] | None = None, train_steps_to_log: list[int] | None = None, metrics_watch: list[str] | None = None, var_leads_metrics_watch: dict[int, list[int]] | None = None, args: Any | None = None)[source]#
Bases:
neural_lam.models.modules.base.BaseForecastingModuleLightning module for a single deterministic forecast per batch.
Validation and testing evaluate the forecaster’s own single prediction, as opposed to
ProbabilisticForecastingModule, which samples and scores an ensemble. Training is shared with that module unchanged (seeBaseForecastingModule.training_step).The reported loss comes from
forecaster.compute_loss_from_forecast, since only the forecaster knows its objective. The reported metrics (mse, mae) are computed here fromneural_lam.metrics: they are fixed regardless of what the forecaster trains on, so routing them through it would add a layer without adding meaning.Initialize the module and its deterministic evaluation metrics.
- Parameters:
forecaster (BaseDeterministicForecaster) – The forecaster to evaluate. Must supply
compute_loss_from_forecast, i.e. carry the deterministic objective, since validation and testing score a single prediction through it.config (NeuralLAMConfig) – Configuration object for the neural LAM model.
datastore (BaseDatastore) – Datastore providing grid metadata and data access.
datastore_boundary (BaseDatastore, optional) – Boundary forcing datastore, used for its standardization statistics.
lr (float, default 1e-3) – Learning rate for the optimizer.
restore_opt (bool, default False) – Whether to restore optimizer state from checkpoint.
n_example_pred (int, default 1) – Number of example predictions to plot during testing.
create_gif (bool, default False) – Whether to create GIFs of example predictions.
val_steps_to_log (list of int, optional) – Specific predicted steps to log during validation/testing.
train_steps_to_log (list of int, optional) – Specific predicted steps to log during training, reported as
train_loss_unroll{i}(seetraining_step).metrics_watch (list of str, optional) – List of metrics to watch and log specifically.
var_leads_metrics_watch (dict of {int: list of int}, optional) – Mapping from variable index to a list of predicted steps to log individually for the configured metrics.
args (argparse.Namespace, optional) – Pre-refactor
ARModelcheckpoint hyperparameters; seeBaseForecastingModule.__init__.
- on_test_epoch_end() None[source]#
Perform actions at the end of the test epoch. Aggregates and plots test metrics and spatial loss maps.
- test_step(batch: neural_lam.models.modules.base.Batch, batch_idx: int) None[source]#
Perform a single test step.
- training_step(batch: neural_lam.models.modules.base.Batch) torch.Tensor[source]#
Perform a single training step, logging the per-step breakdown.
Overrides
BaseForecastingModule.training_step, which logs only the scalar objective because a forecaster’s training loss need not decompose over predicted steps. The deterministic objective does, so--train_steps_to_logcan report individual steps astrain_loss_unroll{i}and the loggedtrain_lossis their mean, equal toforecaster.compute_training_loss.- Parameters:
batch (tuple) – The batch of data.
- Returns:
The computed loss for the training step.
- Return type:
- validation_step(batch: neural_lam.models.modules.base.Batch, batch_idx: int) None[source]#
Perform a single validation step.
- spatial_loss_maps: list[torch.Tensor] = []#
- test_metrics#
- val_metrics#