Python scipy.optimize.minimize行搜索参数
在中,它没有解释使用了什么Python scipy.optimize.minimize行搜索参数,python,scipy,mathematical-optimization,Python,Scipy,Mathematical Optimization,在中,它没有解释使用了什么linesearch方法。我假设它使用中实现的强wolfe条件,该函数包括更改linesearch中使用的关键参数c1和c2。我想更改这些参数,以便在minimize中实现的优化算法中使用 我试图通过更改line\u search中的默认值来实现这一点,但没有效果。下面是一个简单的示例代码 import scipy.optimize as sc from functools import partial myans = sc.minimize(sc.rosen,[2,2
linesearch
方法。我假设它使用中实现的强wolfe条件,该函数包括更改linesearch
中使用的关键参数c1
和c2
。我想更改这些参数,以便在minimize中实现的优化算法中使用
我试图通过更改line\u search
中的默认值来实现这一点,但没有效果。下面是一个简单的示例代码
import scipy.optimize as sc
from functools import partial
myans = sc.minimize(sc.rosen,[2,2],(),'L-BFGS-B')
###try changing default line search parameters from default of c1=.0001 and c2 = .9 to .1 and .5
sc.line_search.__defaults__ = (None, None, None, (), 0.1, 0.5, None, None, 10)
###try another way
partial(sc.line_search,c1=.1, c2=.5)
myans2 = sc.minimize(sc.rosen,[2,2],(),'L-BFGS-B')
我不是想最小化rosenbrock函数,我是在使用与我的研究相关的自定义函数。但是代码片段的结果没有差异,这表明在
line\u search
中更改默认值似乎没有效果。Scipy的line search函数只在一些基于python的优化实现中使用
另一方面,L-BFGS-B
被完全包装(只允许设置ls迭代的上限)并使用(这是Fortran代码)
虽然原始代码可能允许更改这些常量(懒得检查驱动程序),但它看起来不像scipy那样
subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
+ task,isave,dsave)
character*(*) task
integer isave(2)
double precision f,g,stp,ftol,gtol,xtol,stpmin,stpmax
double precision dsave(13)
c **********
c
c Subroutine dcsrch
c
c This subroutine finds a step that satisfies a sufficient
c decrease condition and a curvature condition.
c
c Each call of the subroutine updates an interval with
c endpoints stx and sty. The interval is initially chosen
c so that it contains a minimizer of the modified function
c
c psi(stp) = f(stp) - f(0) - ftol*stp*f'(0).
c
c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
c interval is chosen so that it contains a minimizer of f.
c
c The algorithm is designed to find a step that satisfies
c the sufficient decrease condition
c
c f(stp) <= f(0) + ftol*stp*f'(0),
c
c and the curvature condition
c
c abs(f'(stp)) <= gtol*abs(f'(0)).
c
c If ftol is less than gtol and if, for example, the function
c is bounded below, then there is always a step which satisfies
c both conditions.
c
c If no step can be found that satisfies both conditions, then
c the algorithm stops with a warning. In this case stp only
c satisfies the sufficient decrease condition.
c
c A typical invocation of dcsrch has the following outline:
c
c task = 'START'
c 10 continue
c call dcsrch( ... )
c if (task .eq. 'FG') then
c Evaluate the function and the gradient at stp
c goto 10
c end if
c
c NOTE: The user must no alter work arrays between calls.
c
c The subroutine statement is
c
c subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
c task,isave,dsave)
c where
c
c f is a double precision variable.
c On initial entry f is the value of the function at 0.
c On subsequent entries f is the value of the
c function at stp.
c On exit f is the value of the function at stp.
c
c g is a double precision variable.
c On initial entry g is the derivative of the function at 0.
c On subsequent entries g is the derivative of the
c function at stp.
c On exit g is the derivative of the function at stp.
c
c stp is a double precision variable.
c On entry stp is the current estimate of a satisfactory
c step. On initial entry, a positive initial estimate
c must be provided.
c On exit stp is the current estimate of a satisfactory step
c if task = 'FG'. If task = 'CONV' then stp satisfies
c the sufficient decrease and curvature condition.
c
c ftol is a double precision variable.
c On entry ftol specifies a nonnegative tolerance for the
c sufficient decrease condition.
c On exit ftol is unchanged.
c
c gtol is a double precision variable.
c On entry gtol specifies a nonnegative tolerance for the
c curvature condition.
c On exit gtol is unchanged.
c
c xtol is a double precision variable.
c On entry xtol specifies a nonnegative relative tolerance
c for an acceptable step. The subroutine exits with a
c warning if the relative difference between sty and stx
c is less than xtol.
c On exit xtol is unchanged.
c
c stpmin is a double precision variable.
c On entry stpmin is a nonnegative lower bound for the step.
c On exit stpmin is unchanged.
c
c stpmax is a double precision variable.
c On entry stpmax is a nonnegative upper bound for the step.
c On exit stpmax is unchanged.
c
c task is a character variable of length at least 60.
c On initial entry task must be set to 'START'.
c On exit task indicates the required action:
c
c If task(1:2) = 'FG' then evaluate the function and
c derivative at stp and call dcsrch again.
c
c If task(1:4) = 'CONV' then the search is successful.
c
c If task(1:4) = 'WARN' then the subroutine is not able
c to satisfy the convergence conditions. The exit value of
c stp contains the best point found during the search.
c
c If task(1:5) = 'ERROR' then there is an error in the
c input arguments.
c
c On exit with convergence, a warning or an error, the
c variable task contains additional information.
c
c isave is an integer work array of dimension 2.
c
c dsave is a double precision work array of dimension 13.
c
c Subprograms called
c
c MINPACK-2 ... dcstep
c
c MINPACK-1 Project. June 1983.
c Argonne National Laboratory.
c Jorge J. More' and David J. Thuente.
c
c MINPACK-2 Project. October 1993.
c Argonne National Laboratory and University of Minnesota.
c Brett M. Averick, Richard G. Carter, and Jorge J. More'.
c
c **********
子例程dcsrch(f、g、stp、ftol、gtol、xtol、stpmin、stpmax、,
+任务、isave、dsave)
字符*(*)任务
整数isave(2)
双精度f、g、stp、ftol、gtol、xtol、stpmin、stpmax
双精度数据存储(13)
c**********
C
c子程序dcsrch
C
c该子例程找到满足充分条件的步骤
c减少条件和曲率条件。
C
c子程序的每次调用都会用
c端点stx和sty。时间间隔是最初选择的
使其包含修改函数的极小值
C
c psi(stp)=f(stp)-f(0)-ftol*stp*f'(0)。
C
c如果psi(stp)