model.utils.training¶
Training loss utilities for ADELM.
Module Contents¶
Functions¶
Compute the sample-level |
|
Compute sample-level R² over all finite positions. |
|
Compute the site-level |
|
Compute R² on per-site means over valid samples. |
API¶
- model.utils.training.sample_r2_loss(pred: Tensor, target: Tensor)¶
Compute the sample-level
1 - R²loss by pooling all finite site-day values.This is the primary training loss. It constrains day-to-day and seasonal variability within sites. Use together with
site_r2_loss()when cross-site climatological differences also matter.
- model.utils.training.sample_r2_score(pred: Tensor, target: Tensor)¶
Compute sample-level R² over all finite positions.
- model.utils.training.site_r2_loss(pred: Tensor, target: Tensor, min_valid_sites: int = 1, min_samples_per_site: int = 1)¶
Compute the site-level
1 - R²loss on per-site multi-year means.Reduces
predandtargetfrom[site, ...]to one mean per site using only finite positions, then appliessample_r2_loss()to the reduced vectors. This constrains the cross-site climatological gradient, which is the signal most relevant to learning attribute-to-parameter mappings that transfer in space.Sites with fewer than
min_samples_per_sitevalid samples are excluded. ReturnsNonewhen fewer thanmin_valid_sitessites remain, so the caller can skip the gradient step.
- model.utils.training.site_r2_score(pred: Tensor, target: Tensor, min_valid_sites: int = 1, min_samples_per_site: int = 1)¶
Compute R² on per-site means over valid samples.