Basinhopping算法返回'RuntimeWarning:double_scalars中遇到的无效值'

时间:2017-08-07 08:06:49

标签: algorithm optimization scipy runtime warnings

大家好。所以,我遇到了盆景算法的问题。它对我所有的其他数据集都很好用,但是对于特定的数据集,它会返回我在标题中提到的这个错误。目标是求解具有三个未知数(x [0],x [1],x [2])的三个方程的非线性系统。代码总结如下:

import numpy as np
from scipy.optimize import basinhopping

xmin = [-10 , -1, 0]
xmax = [10, 1, 1]
bnds = np.array([(low, high) for low, high in zip(xmin, xmax)])
x0 = np.array([0,0,0])
Solution = np.zeros((len(Vp),3))
kwargs = dict(bounds=bnds, tol=1.0e-16)

for ii in range(0,len(Vp)):
    def fun(x):
         return  ((C[1]*x[1] + C[2]*x[2] + C[3]*x[0]*x[2] + C[4]*x[1]**2 + 
                 C[5]*x[1]*x[2] + C[6]**x[2]**2 - Vp[ii])**2 +  
                 (D[1]*x[1] + D[2]*x[0]*x[1] - Vs[ii])**2 + 
                 (E[1]*x[1] + E[2]*x[0]**2 +
                 E[3]*x[0]*x[1]- Density[ii])**2)  

    sol = basinhopping(fun, x0, minimizer_kwargs = kwargs)
    Solution[ii,:] = np.asarray(sol.x)
    x0 = Solution[ii,:]

C,D,E,Vp,Vs和密度的值是

C = [ 0.        ,  0.23602278, -0.03112353, -0.00200731,  0.12631723,
    0.01686503, -0.03604464]
D = [ 0.        , -0.01411336, -0.00048822]
E = [  0.00000000e+00,   2.74052684e-02,  -2.51367338e-05,
     9.57081839e-04]

Vp = [ 0.026575, -0.076332, -0.063064, -0.058712, -0.103915, -0.145887,
   -0.080618, -0.079216, -0.171163, -0.115634, -0.076444]
Vs = [ 0.002064, -0.000847,  0.002788,  0.004255,  0.003588,  0.003474,
    0.001675,  0.004111,  0.006459,  0.004753,  0.009658]
Density = [ 0.001782, -0.001433, -0.002109, -0.002997, -0.009515, -0.005077,
   -0.004877, -0.013798, -0.010524, -0.015607, -0.017562]

我想我可能会遗漏一些非常基本的东西,因为这段代码到目前为止一直在运作。我意识到这个错误通常与除以零有关,但我不认为在这种情况下发生了......任何提示?

0 个答案:

没有答案