mindspore.scipy.optimize.line_search
- mindspore.scipy.optimize.line_search(f, xk, pk, jac=None, gfk=None, old_fval=None, old_old_fval=None, c1=0.0001, c2=0.9, maxiter=20)[源代码]
Inexact line search that satisfies strong Wolfe conditions.
Algorithm 3.5 from Wright and Nocedal, ‘Numerical Optimization’, 1999, pg. 59-61
说明
line_search is not supported on Windows platform yet.
- 参数
f (function) – function of the form f(x) where x is a flat Tensor and returns a real scalar. The function should be composed of operations with vjp defined.
gf (function) – the gradient function at x where x is a flat Tensor and returns a Tensor. The function can be None if you want to use automatic credits.
xk (Tensor) – initial guess.
pk (Tensor) – direction to search in. Assumes the direction is a descent direction.
gfk (Tensor) – initial value of value_and_gradient as position. Default:
None
.old_fval (Tensor) – The same as gfk. Default:
None
.old_old_fval (Tensor) – unused argument, only for scipy API compliance. Default:
None
.c1 (float) – Wolfe criteria constant, see ref. Default:
1e-4
.c2 (float) – The same as c1. Default:
0.9
.maxiter (int) – maximum number of iterations to search. Default:
20
.
- 返回
LineSearchResults, results of line search results.
- Supported Platforms:
GPU
CPU
样例
>>> import numpy as onp >>> from mindspore.scipy.optimize import line_search >>> from mindspore import Tensor >>> x0 = Tensor(onp.ones(2).astype(onp.float32)) >>> p0 = Tensor(onp.array([-1, -1]).astype(onp.float32)) >>> def func(x): ... return x[0] ** 2 - x[1] ** 3 >>> res = line_search(func, x0, p0) >>> print(res.a_k) 1.0