Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scipy/optimize/_trustregion_krylov.py: 36%

11 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-12 06:31 +0000

1from ._trustregion import (_minimize_trust_region) 

2from ._trlib import (get_trlib_quadratic_subproblem) 

3 

4__all__ = ['_minimize_trust_krylov'] 

5 

6def _minimize_trust_krylov(fun, x0, args=(), jac=None, hess=None, hessp=None, 

7 inexact=True, **trust_region_options): 

8 """ 

9 Minimization of a scalar function of one or more variables using 

10 a nearly exact trust-region algorithm that only requires matrix 

11 vector products with the hessian matrix. 

12 

13 .. versionadded:: 1.0.0 

14 

15 Options 

16 ------- 

17 inexact : bool, optional 

18 Accuracy to solve subproblems. If True requires less nonlinear 

19 iterations, but more vector products. 

20 """ 

21 

22 if jac is None: 

23 raise ValueError('Jacobian is required for trust region ', 

24 'exact minimization.') 

25 if hess is None and hessp is None: 

26 raise ValueError('Either the Hessian or the Hessian-vector product ' 

27 'is required for Krylov trust-region minimization') 

28 

29 # tol_rel specifies the termination tolerance relative to the initial 

30 # gradient norm in the Krylov subspace iteration. 

31 

32 # - tol_rel_i specifies the tolerance for interior convergence. 

33 # - tol_rel_b specifies the tolerance for boundary convergence. 

34 # in nonlinear programming applications it is not necessary to solve 

35 # the boundary case as exact as the interior case. 

36 

37 # - setting tol_rel_i=-2 leads to a forcing sequence in the Krylov 

38 # subspace iteration leading to quadratic convergence if eventually 

39 # the trust region stays inactive. 

40 # - setting tol_rel_b=-3 leads to a forcing sequence in the Krylov 

41 # subspace iteration leading to superlinear convergence as long 

42 # as the iterates hit the trust region boundary. 

43 

44 # For details consult the documentation of trlib_krylov_min 

45 # in _trlib/trlib_krylov.h 

46 # 

47 # Optimality of this choice of parameters among a range of possibilities 

48 # has been tested on the unconstrained subset of the CUTEst library. 

49 

50 if inexact: 

51 return _minimize_trust_region(fun, x0, args=args, jac=jac, 

52 hess=hess, hessp=hessp, 

53 subproblem=get_trlib_quadratic_subproblem( 

54 tol_rel_i=-2.0, tol_rel_b=-3.0, 

55 disp=trust_region_options.get('disp', False) 

56 ), 

57 **trust_region_options) 

58 else: 

59 return _minimize_trust_region(fun, x0, args=args, jac=jac, 

60 hess=hess, hessp=hessp, 

61 subproblem=get_trlib_quadratic_subproblem( 

62 tol_rel_i=1e-8, tol_rel_b=1e-6, 

63 disp=trust_region_options.get('disp', False) 

64 ), 

65 **trust_region_options)