model.utils.cross_validationΒΆ
Cross-validation helpers for entity-first ADELM datasets.
All ADELM tensors are assumed to use entity as the first dimension.
Time-varying tensors additionally use time as the second dimension.
Module ContentsΒΆ
ClassesΒΆ
One cross-validation fold over a entity-first dataset. |
|
Cross-validation interface for ADELM datasets. |
APIΒΆ
- class model.utils.cross_validation.CVFoldΒΆ
One cross-validation fold over a entity-first dataset.
- index: intΒΆ
None
- name: strΒΆ
None
- train_entity_mask: torch.TensorΒΆ
None
- valid_entity_mask: torch.TensorΒΆ
None
- train_time_mask: torch.TensorΒΆ
None
- valid_time_mask: torch.TensorΒΆ
None
- valid_entities: tupleΒΆ
()
- valid_time_range: tupleΒΆ
()
- target_mask(split='train')ΒΆ
Return a 2D
[entity, time]mask for the requested split.
- mask_tensor(tensor, split='train', fill_value=torch.nan)ΒΆ
Keep only the requested split and fill the remainder.
- class model.utils.cross_validation.CrossValidation(mode, folds, entity_ids, time_values=None, metadata=None)ΒΆ
Bases:
objectCross-validation interface for ADELM datasets.
Use
foldsto iterate over prepared splits, then apply the split to a single target tensor or an entiredict[str, Tensor]collection.Initialization
- __len__()ΒΆ
- __iter__()ΒΆ
- split_targets(targets, fold, fill_value=torch.nan)ΒΆ
Return
(train_targets, valid_targets)for one fold.
- mask_targets(targets, fold, split='train', fill_value=torch.nan)ΒΆ
Mask one tensor or a dict of tensors by the requested fold split.
- classmethod spatial_random(entity_ids, n_folds, shuffle=True, seed=0)ΒΆ
Random spatial CV by entity.
- classmethod spatial_predefined(entity_ids, fold_definition)ΒΆ
Spatial CV from a user-defined fold specification.
- classmethod temporal_block(entity_ids, time_values, n_folds, train_start, train_end)ΒΆ
Temporal CV by contiguous time blocks within the training window.
- classmethod from_config(config, entity_ids, cv_cfg=None, scheme=None, time_values=None, n_folds=None, fold_definition=None, shuffle=True, seed=0)ΒΆ
Build a cross-validator over the given entities.
cv_cfgis the active headβscross_validationblock (site_level or gauge_level);entity_idsare that headβs entities (flux sites or gauges). The time window for temporal CV is read from the sharedlearning.time.