试图用一个变量解决一个简单的非线性最小化问题。
from scipy.optimize import minimize
import math
alpha = 0.05
waiting = 50
mean_period = 50
neighborhood_size = 5
def my_func(w):
return -(2/(w+1) + alpha*math.floor(waiting/mean_period))*(1-(2/(w+1) + alpha*math.floor(waiting/mean_period)))**(neighborhood_size-1)
print minimize(my_func, mean_period, bounds=(2,200))
这给了我
ValueError: length of x0 != length of bounds
我输入错了吗?我应该如何格式化它?
如果我删除界限,我会得到:
status: 2
success: False
njev: 19
nfev: 69
hess_inv: array([[1]])
fun: array([-0.04072531])
x: array([50])
message: 'Desired error not necessarily achieved due to precision loss.'
jac: array([-1386838.30676792])
该函数看起来像这样,因此我需要将解决方案限制在我感兴趣的局部最大值中。