torchmin.minimize

torchmin.minimize(fun, x0, method, max_iter=None, tol=None, options=None, callback=None, disp=0, return_all=False)[source]

Minimize a scalar function of one or more variables.

Note

This is a general-purpose minimizer that calls one of the available routines based on a supplied method argument.

Parameters
  • fun (callable) – Scalar objective function to minimize.

  • x0 (Tensor) – Initialization point.

  • method (str) –

    The minimization routine to use. Should be one of

    • ’bfgs’

    • ’l-bfgs’

    • ’cg’

    • ’newton-cg’

    • ’newton-exact’

    • ’dogleg’

    • ’trust-ncg’

    • ’trust-exact’

    • ’trust-krylov’

    At the moment, method must be specified; there is no default.

  • max_iter (int, optional) – Maximum number of iterations to perform. If unspecified, this will be set to the default of the selected method.

  • tol (float) – Tolerance for termination. For detailed control, use solver-specific options.

  • options (dict, optional) – A dictionary of keyword arguments to pass to the selected minimization routine.

  • callback (callable, optional) – Function to call after each iteration with the current parameter state, e.g. callback(x).

  • disp (int or bool) – Display (verbosity) level. Set to >0 to print status messages.

  • return_all (bool, optional) – Set to True to return a list of the best solution at each of the iterations.

Returns

result – Result of the optimization routine.

Return type

OptimizeResult