discotime.utils.misc module
- class discotime.utils.misc.BaseFabricTrainer(module: LitSurvModule, dset_train: SurvDataset, dset_valid: SurvDataset, batch_size: int)[source]
Bases:
objectBare-bones trainer class using Fabric.
This trainer class supports only a very limited set of the full lightning functionality. It can be useful for quick prototyping or for k-fold cross-validation as exemplified in the scripts that can be found in the
/experimentsfolder on github.
- class discotime.utils.misc.EarlyStopping(patience: int, min_delta: float, direction: str = 'minimize')[source]
Bases:
objectLightning-free implementation of early stopping.
To be used with the bare-bones simple trainer that have no support for lightning callbacks.
- class discotime.utils.misc.OptunaCallback(trial: Trial, monitor: str, minvalue: float = -inf, maxvalue: float = inf)[source]
Bases:
CallbackLightning callback for hyperparameter optimization with Optuna.
- Parameters:
trial – A
Trialcorresponding to the current evaluation of the objective function.monitor – An evaluation metric for pruning, e.g.,
val_lossorval_acc.
- on_validation_end(trainer: Trainer, module: LightningModule) None[source]
- discotime.utils.misc.split_dataset(dataset: Dataset[T], k: int = 5) Generator[tuple[torch.utils.data.dataset.ConcatDataset[T], torch.utils.data.dataset.Subset[T]], None, None][source]
Split dataset into k train/validation splits
- discotime.utils.misc.update_mapping(d: Mapping, u: Mapping) Mapping[source]
Update nested mappings recursively.
- Parameters:
d (Mapping) – dictionary/mapping of things.
u (Mapping) – other dictionary/mapping of things to update d with.
Example
>>> foo = {"dog" : {"color" : "black", "age" : 10}} >>> bar = {"dog" : {"age" : 11}, "cat" : None} >>> update_mapping(foo, bar) {'dog': {'color': 'black', 'age': 11}, 'cat': None}