ValueError: The input contains nan values - from lmfit model despite the input not containing NaNs

守給你的承諾、 提交于 2019-12-04 05:07:29
Jason

I tried to fit my model using scipy.optimize.curve_fit and got the following error:

/home/bprodz/.virtualenvs/phd_dev/lib/python3.4/site-packages/ipykernel/__main__.py:3: RuntimeWarning: invalid value encountered in sqrt
  app.launch_new_instance()

Which suggests the problem is with my model generating some negative numbers for np.sqrt(). The default behaviour for np.sqrt() when given a negative number is to output nan as per this question. NB the np.sqrt can be set to raise an error if given a negative number be setting the following: np.seterr(all='raise') source

TIP I also asked for help in the lmfit google group and received the following helpful advice:

  • Consider breaking long formulas into smaller pieces to make troubleshooting easier
  • Use Model.eval() to test what certain parameters will produce when run through your model function
  • np.ndarray is generally superior to python lists in these (numerical) situations
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!