Python - BFGS方法错误

时间:2017-10-02 01:46:41

标签: python-3.x scipy mathematical-optimization

我有许多变量的函数如下:

f = (y2**2 + (x2 - 110)**2)**0.5 + ((x1 - 16)**2 + (y1 - 65)**2)**0.5 + ((x1 - x10)**2 + (y1 - y10)**2)**0.5 + ((x10 - x11)**2 + (y10 - y11)**2)**0.5 + ((x11 - x2)**2 + (y11 - y2)**2)**0.5

我正在尝试使用BFGS方法最小化此功能,到目前为止我使用的详细信息如下所示。

x0 =  [ 61.    79.    67.5   52.5   69.5   67.25  65.25  61.  ] # initial condition 
variables = [x1, y1, x2, y2, x10, y10, x11, y11]   #variables
f_sym = f                                          #function
fprime_sym = [f_sym.diff(x_) for x_ in variables]  # derivative



xopt1 = minimize(f_sym, x0, method='BFGS', jac=fprime_sym ,options={'disp': True}) #METHOD - BFGS

但是当我运行代码时,它会跳出以下错误。

  File "<ipython-input-19-723be1cea819>", line 1, in <module>
    runfile('/Users/***/***/networks.py', wdir='/Users/***/Python')

  File "/Users/***/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 688, in runfile
    execfile(filename, namespace)

  File "/Users/***/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/***/networks.py", line 479, in <module>
    xopt1 = minimize(f_sym, x0, method='BFGS', jac=fprime_sym ,options={'disp': True})

  File "/Users/***/anaconda/lib/python3.6/site-packages/scipy/optimize/_minimize.py", line 444, in minimize
    return _minimize_bfgs(fun, x0, args, jac, callback, **options)

  File "/Users/***/anaconda/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 913, in _minimize_bfgs
    gfk = myfprime(x0)

  File "/Users/***/anaconda/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 292, in function_wrapper
    return function(*(wrapper_args + args))

  File "/Users/***/anaconda/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 71, in derivative
    self(x, *args)

  File "/Users/***/anaconda/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 63, in __call__
    fg = self.fun(x, *args)

TypeError: 'Add' object is not callable

有人可以帮我恢复吗?

0 个答案:

没有答案