Scipy error using optimization module. Failure converting array to fortran

匿名 (未验证) 提交于 2019-12-03 08:42:37

问题:

Trying to use scipy's optimize module to find the minimum of a function using slsqp and I'm running into some issues. The actual code calling the function is shown below:

def minimizeWebEnergyLost(x, parameters):     """values = [theta, velocity]"""     firstTerm = lambda values: (x * values[1]**2 / 2.0)     sqrtTerm = lambda values: np.sqrt((parameters.gravity**2 * x**2) / (4 * values[1]**4 * np.cos(values[0])**4) + 1)     secondTerm = lambda values: (values[1]**4 * np.cos(values[0])**2) / parameters.gravity     arcsinhTerm = lambda values: np.arcsinh((parameters.gravity * x) / (2 * values[1]**2 * np.cos(values[0])**2))     costFunction = lambda values: firstTerm(values)*sqrtTerm(values)+secondTerm(values)*arcsinhTerm(values)     bounds = ((-math.pi/2,math.pi/2),(0,parameters.maxSlingSpeed))     minimum = minimize(costFunction, (pi/4, 20), method="SLSQP", bounds=bounds)     return minimum

For some reason the error I'm getting is as follows:

_slsqp.error: failed in converting 8th argument `g' of _slsqp.slsqp to C/Fortran array

Not quite sure what's going on hre, but I can put up any more code that might be useful if it helps.

回答1:

This cryptic error occurs when the user specified objective function does not returning a scalar. A clear error message is now returned in a patch by b-carter,

"Objective function must return a scalar" 

and the documentation is updated, see this thread for discussion.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!