pgsui.impute.unsupervised package

Subpackages

Submodules

pgsui.impute.unsupervised.callbacks module

class pgsui.impute.unsupervised.callbacks.EarlyStopping(patience: int = 25, delta: float = 0.0, verbose: int = 0, mode: str = 'min', min_epochs: int = 150, prefix: str = 'pgsui_output', debug: bool = False)[source]

Class to stop the training when a monitored metric has stopped improving.

This class is used to stop the training of a model when a monitored metric has stopped improving (such as validation loss or accuracy). If the metric does not improve for patience epochs, and we have already passed the min_epochs epoch threshold, training is halted. The best model checkpoint is reloaded when early stopping is triggered.

Example

>>> early_stopping = EarlyStopping(patience=25, verbose=1, min_epochs=100)
>>> for epoch in range(1, 1001):
>>>     val_loss = train_epoch(...)
>>>     early_stopping(val_loss, model)
>>>     if early_stopping.early_stop:
>>>         break
__init__(patience: int = 25, delta: float = 0.0, verbose: int = 0, mode: str = 'min', min_epochs: int = 150, prefix: str = 'pgsui_output', debug: bool = False)[source]

Early stopping callback for PyTorch training.

This class is used to stop the training of a model when a monitored metric has stopped improving (such as validation loss or accuracy). If the metric does not improve for patience epochs, and we have already passed the min_epochs epoch threshold, training is halted. The best model checkpoint is reloaded when early stopping is triggered. The mode parameter can be set to “min” or “max” to indicate whether the metric should be minimized or maximized, respectively.

Parameters:
  • patience (int) – Number of epochs to wait after the last time the monitored metric improved.

  • delta (float) – Minimum change in the monitored metric to qualify as an improvement.

  • verbose (int) – Verbosity level (0 = silent, 1 = improvement messages, 2+ = more).

  • mode (str) – “min” or “max” to indicate how improvement is defined.

  • prefix (str) – Prefix for directory naming.

  • output_dir (Path) – Directory in which to create subfolders/checkpoints.

  • min_epochs (int) – Minimum epoch count before early stopping can take effect.

  • debug (bool) – Debug mode for logging messages

Raises:

ValueError – If an invalid mode is provided. Must be “min” or “max”.

Module contents