|
minimize是scipy中optimize模块的一个函数,调用
import scipy.optimize as opt
res=opt.minimize()
主要参数
res=opt.minimize(fun, x0, args=(), method=None, jac=None, hess=None,
hessp=None, bounds=None, constraints=(), tol=None,
callback=None, options=None)
#fun:该参数就是costFunction你要去最小化的损失函数,将costFunction的名字传给fun
#x0: 猜测的初始值
#args=():优化的附加参数,默认从第二个开始
#method:该参数代表采用的方式,默认是BFGS, L-BFGS-B, SLSQP中的一种,可选TNC
#options:用来控制最大的迭代次数,以字典的形式来进行设置,例如:options={‘maxiter’:400}
#constraints: 约束条件,针对fun中为参数的部分进行约束限制,多个约束如下:
'''cons = ({'type': 'ineq', 'fun': lambda x: x[0] - x1min},\
{'type': 'ineq', 'fun': lambda x: -x[0] + x1max},\
{'type': 'ineq', 'fun': lambda x: x[1] - x2min},\
{'type': 'ineq', 'fun': lambda x: -x[1] + x2max})'''
#tol: 目标函数误差范围,控制迭代结束
#callback: 保留优化过程
|