tBuLi / symfit

Symbolic Fitting; fitting as it should be.
http://symfit.readthedocs.org
MIT License
233 stars 17 forks source link

Runtime warnings in documentation #308

Closed stephanlachnit closed 4 years ago

stephanlachnit commented 4 years ago

While looking into what could cause the leaked build path for the documentation (see #306), I noticed that actually there is an entire example broken in the documentation. It's inside docs/examples/ex_bivariate_likelihood.ipynb, as you can prominently see here: https://symfit.readthedocs.io/en/master/examples/ex_bivariate_likelihood.html

For reference:

/usr/lib/python3/dist-packages/symfit/core/objectives.py:462: RuntimeWarning: divide by zero encountered in log
  [np.nansum(np.log(component)) for component in evaluated_func]
/usr/lib/python3/dist-packages/symfit/core/objectives.py:462: RuntimeWarning: invalid value encountered in log
  [np.nansum(np.log(component)) for component in evaluated_func]
/usr/lib/python3/dist-packages/symfit/core/objectives.py:490: RuntimeWarning: divide by zero encountered in true_divide
  df / component
/usr/lib/python3/dist-packages/symfit/core/objectives.py:490: RuntimeWarning: invalid value encountered in true_divide
  df / component
/usr/lib/python3/dist-packages/symfit/core/fit_results.py:254: RuntimeWarning: overflow encountered in exp
  gof_qualifiers['likelihood'] = np.exp(gof_qualifiers['log_likelihood'])

Edit: btw also in https://symfit.readthedocs.io/en/master/examples/ex_tikhonov.html

/home/docs/checkouts/readthedocs.org/user_builds/symfit/envs/master/lib/python3.7/site-packages/symfit/core/fit_results.py:277: RuntimeWarning: divide by zero encountered in double_scalars
  return 1 - SS_res/SS_tot
pckroon commented 4 years ago

Unfortunately RuntimeWarnings like that are unavoidable. It's caused by the minimizer exploring the parameter space, and probing numerically unstable regions. As shown in the example, the fit still finds the correct values though, so I don't think the word "broken" is appropriate :)

PS. I hope to be able to look at your PR soon. Maybe @tBuLi will be faster though.

stephanlachnit commented 4 years ago

Unfortunately RuntimeWarnings like that are unavoidable. It's caused by the minimizer exploring the parameter space, and probing numerically unstable regions. As shown in the example, the fit still finds the correct values though, so I don't think the word "broken" is appropriate :)

Alright, fair point, broken is maybe a bit to harsh. Maybe the example can be adjusted / changed to something that doesn't give warnings? It looks a bit weird to have errors in the official documentation, don't you think?

Maybe it's also possible to just silence the warnings with some Python environment variable. Will do some research.

tBuLi commented 4 years ago

I agree that if these can be polished out then that's better. They are warnings of a kind which are to be expected as @pckroon says, but I agree it would be nicer if they weren't included in the docs. Perhaps it is possible to run these notebooks with an ignore warning interpreter flag or something? For generating the docs I would have no problem with that.