How can I write bounds of parameters by using basinhopping?

前端 未结 2 656
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 22:39

I have difficulty with writing the bounds of parameters in basinhopping.

(x0)=(a, b, c )

a = (0, 100)

b = (0, 0.100)

c = (0, 10)

from scipy.         


        
2条回答
  •  滥情空心
    2021-01-16 23:12

    You should use "bounds" parameter in minimizer_kwargs which is passing to scipy.optimize.minimize(). Here is an example:

    bnds = ((1, 100), (1, 100), (1,100))# your bounds
    
    def rmse(X):# your function
        a,b,c = X[0],X[1],X[2]
        return a**2+b**2+c**2
    
    x0 = [10., 10., 10.]
    minimizer_kwargs = { "method": "L-BFGS-B","bounds":bnds }
    ret = basinhopping(rmse, x0, minimizer_kwargs=minimizer_kwargs,niter=10)
    print("global minimum: a = %.4f, b = %.4f c = %.4f | f(x0) = %.4f" % (ret.x[0], ret.x[1], ret.x[2], ret.fun))
    

    The result is

    global minimum: a = 1.0000, b = 1.0000 c = 1.0000 | f(x0) = 3.0000

    Without boundaries it is (clear) 0,0,0

提交回复
热议问题