Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Wald's logcdf method #4436

Closed
ricardoV94 opened this issue Jan 24, 2021 · 2 comments · Fixed by #4496
Closed

Simplify Wald's logcdf method #4436

ricardoV94 opened this issue Jan 24, 2021 · 2 comments · Fixed by #4496
Assignees

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Jan 24, 2021

Wald's logcdf checks a lot of conditions for degenerate distribution parameters/values that =0 or =np.inf to decide whether to return a logcdf of -inf or 0. As far as I can tell, this is the only distribution that goes to such lengths to accommodate degenerate cases, some of which are not even allowed by the distribution initialization (or the docstrings or the logp):

https://github.com/pymc-devs/pymc3/blob/823906a3efcf66897eac8a4c89052d9153bca49e/pymc3/distributions/continuous.py#L1138-L1162

Note that the explicit bound parameter checks were added only recently in #4421 and were not in the original implementation of the logcdf method. In fact, they overwrite several of the degenerate lam == 0 checks as well as some implicit (I think) value >= mu & mu == 0 checks.

Also, AFAIK these degenerate conditions are not being tested anywhere.

Unless there is a good reason for it, I would suggest stripping away the degenerate case switches, and simply have something like the following (which I haven't tested yet):

return bound(
    a + tt.log1p(tt.exp(b - a)),
    0 < value, 
    0 < mu,
    0 < lam,
    0 <= alpha,
)
@Spaak
Copy link
Member

Spaak commented Mar 1, 2021

That seems like a good simplification to me. What is the worst that can happen if the degenerate case holds? If no untraceable disaster, then EAFP.

@ricardoV94
Copy link
Member Author

The degenerate case is not supposed to be allowed as per the docstrings / conventional definition of parameter support (e.g., Wikipedia). In this case it will simply be captured by the bound and return -np.inf. This is no worse than what happens with a Normal with sigma=0 (that one actually raises a ZeroDivisionError).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants