【问题标题】:Boundary in Powell method ScipyPowell 方法 Scipy 中的边界
【发布时间】:2021-01-29 00:57:14
【问题描述】:

让我们最小化函数

f =lambda x: (x+1)**2 

在 scipy 中使用鲍威尔方法

如果我们使用

scipy.optimize.minimize(f, 1, method='Powell', bounds=None)

回报是

   direc: array([[1.]])
     fun: array(0.)
 message: 'Optimization terminated successfully.'
    nfev: 20
     nit: 2
  status: 0
 success: True
       x: array(-1.)

即最小值应为-1。如果我们提供界限

scipy.optimize.minimize(f, 1, method='Powell', bounds=[(0,2)])

又来了

   direc: array([[1.]])
     fun: array(0.)
 message: 'Optimization terminated successfully.'
    nfev: 20
     nit: 2
  status: 0
 success: True
       x: array(-1.)

现在是错误的!正确答案应该是 0。就像没有考虑边界一样。我正在使用 scipy '1.4.1' 和 python 3.7.6。 有人知道吗?

【问题讨论】:

  • 如果我的回答对你有帮助,你可以考虑accepting it
  • 很有帮助!抱歉,我是堆栈溢出的“新手”.. 并且不知道如何接受它.. 再次感谢

标签: python scipy minimize boundary


【解决方案1】:

在 scipy 1.4.x 中,Powell 方法无法处理约束和边界,如您所见 here。更新到scipy 1.5.x,可以处理边界了,见here

In [11]: scipy.optimize.minimize(f, x0=1.0, method='Powell', bounds=[(0.0,2.0)])
Out[11]:
   direc: array([[1.64428414e-08]])
     fun: array(1.)
 message: 'Optimization terminated successfully.'
    nfev: 103
     nit: 2
  status: 0
 success: True
       x: array([2.44756652e-12])

【讨论】:

    猜你喜欢
    • 2018-02-03
    • 2017-10-29
    • 2016-10-11
    • 2013-08-15
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 2015-08-25
    相关资源
    最近更新 更多