rethinkpriorities / squigglepy

Squiggle programming language for intuitive probabilistic estimation features in Python
MIT License
63 stars 8 forks source link

Overflows #46

Open agucova opened 1 year ago

agucova commented 1 year ago

During testing of the correlations feature, I've noticed a bunch of distributions which casually produce overflows. Users wouldn't notice this except for infinities (np.inf) in their samples or distribution parameters.

I've fixed some of these (mostly those related to input parameters) alongside the distributions feature, but some that are still a problem:

I think it would be hard to fix this, most of these errors come from limitations inherent of the floating point operations; but I would at least try to reraise the warning as an error, to prevent users from creating models which might be silently wrong.

peterhurford commented 1 year ago

Yeah my guess is that this occurs in underlying numpy right?

Hm yeah this seems pretty annoying. I imagine the user also wouldn't be excited for their programs to randomly crash with an error, though I imagine that is better than having unnoticed infinities. Resampling would also be complicated. I suppose rclip could be helpful here?

agucova commented 1 year ago

Hm yeah this seems pretty annoying. I imagine the user also wouldn't be excited for their programs to randomly crash with an error, though I imagine that is better than having unnoticed infinities. Resampling would also be complicated. I suppose rclip could be helpful here?

In some specific cases we can work around overflow and underflows by limiting calculations to a minimum or a maximum, but it's tough to estimate how they would impact the distributions.

For now I much prefer to raise an error unless there's an obvious fix (like bounding the parameters).

peterhurford commented 1 year ago

Yeah we could raise an error and recommend the user define their own bounds to make the error go away. I think that would be the best solution.