model.utils.training

Training loss utilities for ADELM.

Module Contents

Functions

sample_r2_loss

Compute the sample-level 1 - loss by pooling all finite site-day values.

sample_r2_score

Compute sample-level R² over all finite positions.

site_r2_loss

Compute the site-level 1 - loss on per-site multi-year means.

site_r2_score

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 - 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 - loss on per-site multi-year means.

Reduces pred and target from [site, ...] to one mean per site using only finite positions, then applies sample_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_site valid samples are excluded. Returns None when fewer than min_valid_sites sites 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.