optimization.optimizer.torch.sgd

Torch SGD Optimizer

This module contains an implementation of the SGD optimizer for PyTorch.

Kramer Harrison, 2025

Classes

TorchSGDOptimizer(problem)

An optimizer that uses the PyTorch SGD algorithm.

class TorchSGDOptimizer(problem: OptimizationProblem)[source]

An optimizer that uses the PyTorch SGD algorithm.

This optimizer leverages automatic differentiation to perform gradient-based optimization on an OptimizationProblem.

optimize(n_steps: int = 100, lr: float = 0.01, gamma: float = 0.99, disp: bool = True, plot: bool = False, callback: Callable[[int, float], None] | None = None)

Runs the optimization loop.

Parameters:
  • n_steps (int) – The number of optimization steps.

  • lr (float) – The learning rate.

  • gamma (float) – The decay factor for the learning rate.

  • disp (bool) – Whether to display progress.

  • plot – If True, update live plots during optimization.

  • callback (Callable[[int, float], None] | None) – A callback function to be called after each step with the current step and loss value.