【问题标题】:scipy.optimize.minimize line search parametersscipy.optimize.minimize 行搜索参数
【发布时间】:2019-03-31 16:38:48
【问题描述】:

documentation for scipy.optimize.minimize 中并没有解释使用什么linesearch 方法。我假设它使用了在here 中实现的强沃尔夫条件,并且该功能包括更改linesearch 中使用的关键参数c1c2 的能力。我想更改这些参数以用于最小化实现的优化算法。

我尝试通过更改line_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 函数,我正在使用与我的研究相关的自定义函数。但是代码sn -p 的结果没有差异,说明更改line_search 中的默认值似乎没有任何效果。

【问题讨论】:

    标签: python scipy mathematical-optimization


    【解决方案1】:

    您提到的 Scipy 的行搜索功能仅用于一些基于 python 的优化实现。

    另一方面,L-BFGS-B 被完全包装(只允许设置 ls-iterations 的上限)并使用reference implementation(这是 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     **********
    

    此外,它看起来像 this LS is wrapped too,但我看不到修改原始 LBFGS-B 算法的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-31
      • 2019-01-23
      • 2018-05-06
      • 1970-01-01
      • 2019-06-29
      相关资源
      最近更新 更多