讓我們最小化函數(shù)f =lambda x: (x+1)**2 在 scipy 中使用鮑威爾方法如果我們使用scipy.optimize.minimize(f, 1, method='Powell', bounds=None)回報(bào)是 direc: array([[1.]]) fun: array(0.) message: 'Optimization terminated successfully.' nfev: 20 nit: 2 status: 0 success: True x: array(-1.)即最小值應(yīng)為-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.)現(xiàn)在這是錯(cuò)誤的!正確答案應(yīng)該是 0。這就像不考慮邊界一樣。我正在使用 scipy '1.4.1' 和 python 3.7.6。有人有任何線索嗎?
2 回答

紅糖糍粑
TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊
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])
- 2 回答
- 0 關(guān)注
- 194 瀏覽
添加回答
舉報(bào)
0/150
提交
取消