_trustregion_krylov.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from ._trustregion import (_minimize_trust_region)
  2. from ._trlib import (get_trlib_quadratic_subproblem)
  3. __all__ = ['_minimize_trust_krylov']
  4. def _minimize_trust_krylov(fun, x0, args=(), jac=None, hess=None, hessp=None,
  5. inexact=True, **trust_region_options):
  6. """
  7. Minimization of a scalar function of one or more variables using
  8. a nearly exact trust-region algorithm that only requires matrix
  9. vector products with the hessian matrix.
  10. .. versionadded:: 1.0.0
  11. Options
  12. -------
  13. inexact : bool, optional
  14. Accuracy to solve subproblems. If True requires less nonlinear
  15. iterations, but more vector products.
  16. """
  17. if jac is None:
  18. raise ValueError('Jacobian is required for trust region ',
  19. 'exact minimization.')
  20. if hess is None and hessp is None:
  21. raise ValueError('Either the Hessian or the Hessian-vector product '
  22. 'is required for Krylov trust-region minimization')
  23. # tol_rel specifies the termination tolerance relative to the initial
  24. # gradient norm in the Krylov subspace iteration.
  25. # - tol_rel_i specifies the tolerance for interior convergence.
  26. # - tol_rel_b specifies the tolerance for boundary convergence.
  27. # in nonlinear programming applications it is not necessary to solve
  28. # the boundary case as exact as the interior case.
  29. # - setting tol_rel_i=-2 leads to a forcing sequence in the Krylov
  30. # subspace iteration leading to quadratic convergence if eventually
  31. # the trust region stays inactive.
  32. # - setting tol_rel_b=-3 leads to a forcing sequence in the Krylov
  33. # subspace iteration leading to superlinear convergence as long
  34. # as the iterates hit the trust region boundary.
  35. # For details consult the documentation of trlib_krylov_min
  36. # in _trlib/trlib_krylov.h
  37. #
  38. # Optimality of this choice of parameters among a range of possibilities
  39. # has been tested on the unconstrained subset of the CUTEst library.
  40. if inexact:
  41. return _minimize_trust_region(fun, x0, args=args, jac=jac,
  42. hess=hess, hessp=hessp,
  43. subproblem=get_trlib_quadratic_subproblem(
  44. tol_rel_i=-2.0, tol_rel_b=-3.0,
  45. disp=trust_region_options.get('disp', False)
  46. ),
  47. **trust_region_options)
  48. else:
  49. return _minimize_trust_region(fun, x0, args=args, jac=jac,
  50. hess=hess, hessp=hessp,
  51. subproblem=get_trlib_quadratic_subproblem(
  52. tol_rel_i=1e-8, tol_rel_b=1e-6,
  53. disp=trust_region_options.get('disp', False)
  54. ),
  55. **trust_region_options)