quantlab.model.torch_training.TrainLossThreshold#

class quantlab.model.torch_training.TrainLossThreshold(threshold, max_epochs)[source]#

Bases: object

MASTER’s stopping rule, for a head’s stop hooks.

update returns True once an epoch’s training loss is at or below threshold, or after max_epochs epochs; the head keeps the last weights either way. The object counts the epochs of one fit: build a fresh one in _on_fit_start.

Parameters:
thresholdfloat

Training loss to reach.

max_epochsint

Epoch cap; at least 1. Training never runs past the epochs hyperparameter anyway.

Raises:
ValueError

If max_epochs is below 1.

Examples

>>> rule = TrainLossThreshold(threshold=0.95, max_epochs=40)
>>> [rule.update(loss) for loss in (1.2, 1.0, 0.9)]
[False, False, True]
update(train_loss)[source]#

Record one epoch’s training loss; return True to stop.

Examples

>>> TrainLossThreshold(0.5, 1).update(1.0)
True