Shortcuts

pypose.utils.ReduceToBason

class pypose.utils.ReduceToBason(steps, patience=5, decreasing=0.001, tol=1e-05, verbose=False)[source]

A stepper to stop a loop when no relative loss ‘decreasing’ is seen for a ‘patience’ number of steps.

Parameters:
  • steps (int) – Maximum number of iterations a loop will step.

  • patience (int, optional) – Number of steps with no loss ‘decreasing’ is seen. For example, if patience = 2, then it ignores the first 2 steps with no improvement, and stop the loop after the 3rd step if the loss has no decerasing. Default: 5.

  • decreasing (float, optional) – relative loss decreasing used to count the number of patience steps. Default: 1e-3.

  • tol (float, optional) – the minimum loss tolerance to stop a loop. Default: 1e-5.

  • verbose (bool, optional) – if True, prints a message to stdout for each step. Default: False.

Warning

Remember to call stepper.reset() if you want to re-use a stepper.

Example

>>> from pypose.utils import ReduceToBason
>>> x = 0.9
>>> stepper = ReduceToBason(steps=5, patience=2, decreasing=0.1, verbose=True)
>>> while stepper.continual():
...     x = x ** 2
...     stepper.step(x)
ReduceToBason step 0 loss 8.099999e-01.
ReduceToBason step 1 loss 6.560999e-01.
ReduceToBason step 2 loss 4.304671e-01.
ReduceToBason step 3 loss 1.853019e-01.
ReduceToBason step 4 loss 3.433681e-02.
ReduceToBason: Maximum steps reached, Quiting..
step(loss)[source]

Performs a stepper step.

Parameters:

loss (float or torch.Tensor) – the model loss after one loop. Can be a batched tensor. If batched tensor, all losses in the batch has to satisfy the condition to stop a loop.

Docs

Access documentation for PyPose

View Docs

Tutorials

Get started with tutorials and examples

View Tutorials

Get Started

Find resources and how to start using pypose

View Resources