neural_lam.models.modules.probabilistic#
Lightning module evaluating probabilistic forecasters.
Classes#
Lightning module evaluating a forecaster by sampling an ensemble. |
Module Contents#
- class neural_lam.models.modules.probabilistic.ProbabilisticForecastingModule(forecaster: neural_lam.models.forecasters.probabilistic.BaseProbabilisticForecaster, config: neural_lam.config.NeuralLAMConfig, datastore: neural_lam.datastore.base.BaseDatastore, *, eval_ensemble_size: int, 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 evaluating a forecaster by sampling an ensemble.
Training is inherited unchanged from
BaseForecastingModule: the wrapped forecaster assembles its own training loss. Validation and testing are ensemble based instead of deterministic: an ensemble is sampled throughforecaster.sample_ensembleand its mean scored per lead time and variable, with validation additionally reporting the forecaster’s own objective. The module makes no assumption on how the members are produced, only that repeated sampling is what an ensemble is made of.Initialize the module and store the evaluation ensemble size.
- Parameters:
forecaster (BaseProbabilisticForecaster) – The forecaster to evaluate. Its
forwardreturns one sampled forecast;sample_ensembledraws the ensemble evaluated during validation and testing.config (NeuralLAMConfig) – Configuration object for the neural LAM model.
datastore (BaseDatastore) – Datastore providing grid metadata and data access.
eval_ensemble_size (int) – Number of ensemble members sampled during validation and testing. Keyword-only and required: how many members to draw is a choice this module cannot sensibly default.
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. Unused here, since
test_stepplots no examples.create_gif (bool, default False) – Whether to create GIFs of example predictions. Unused here, for the same reason.
val_steps_to_log (list of int, optional) – Specific predicted steps to log during validation/testing. Unused here: nothing this module reports decomposes per step, since the ensemble metrics are logged for every step at once as heatmaps and the objective is a single scalar.
train_steps_to_log (list of int, optional) – Specific predicted steps to log during training. Has no effect unless the forecaster’s objective decomposes per step; see
BaseForecastingModule.training_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__.
- Raises:
ValueError – If
eval_ensemble_sizeis less than 1.
- on_test_epoch_end() None[source]#
Perform actions at the end of the test epoch.
Aggregates the ensemble test metrics. Implements
BaseForecastingModule.on_test_epoch_endwithout the spatial loss maps and example plots thatDeterministicForecastingModuleadds, sincetest_stephere does not populate them.
- test_step(batch: neural_lam.models.modules.base.Batch, batch_idx: int) None[source]#
Perform a single ensemble test step.
Scores the ensemble mean against the target states (see
_ensemble_step) and collects per-variable ensemble-mean MSE for epoch-end aggregation.
- validation_step(batch: neural_lam.models.modules.base.Batch, batch_idx: int) None[source]#
Perform a single ensemble validation step.
Logs the forecaster’s objective as
val_mean_loss, scores the ensemble mean against the target states (see_ensemble_step) and collects per-variable ensemble-mean MSE for epoch-end aggregation.
- eval_ensemble_size#
- test_metrics#
- val_metrics#