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

Implement logprob inference for binary operations #6633

Open
ricardoV94 opened this issue Mar 29, 2023 · 4 comments
Open

Implement logprob inference for binary operations #6633

ricardoV94 opened this issue Mar 29, 2023 · 4 comments

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Mar 29, 2023

Description

Using CDFs it should be simple to derive the logp of graphs of the form:

import pymc as pm

x = pm.Normal.dist()
y = x < 0.5
pm.logp(y, value=1).eval()  # same as pm.logcdf(x, 0.5)
pm.logp(y, value=0).eval()  # same as log(1 - exp(pm.logcdf(x, 0.5)))

https://github.com/pymc-devs/pymc/blob/main/pymc/logprob/censoring.py includes rewrites of other operations that rely on CDF such as clip, and round.

More challenging, but also fun, would be to support all and any, whose logp should be the sum of the logp that all binary variables evaluate to True or False: any = 1 - all(x==False)

For ordering, and min/max see #6350

@shreyas3156
Copy link
Contributor

@ricardoV94 I would like to work on this issue starting with the logical comparison Ops (gt, lt, ge, le), but I needed some clarification about the value of logp for y.

pm.logp(y, 0).eval() # same as pm.logcdf(y, 0.5)

Since y is a bool type, how exactly is pm.logcdf for y defined? And consequently, what should pm.logcdf(y, 0.5) evaluate to?

@ricardoV94
Copy link
Member Author

ricardoV94 commented Apr 3, 2023

@shreyas3156 My code comments where wrong, I updated them.

Anyway, the idea is

pm.logp(x < 0.5, True) == pm.logcdf(x, 0.5).

Does that make sense? Just saying the probability of a simple constant inequality (the constant may be another valued RV) is the same as some CDF expression on the underlying variable.

@shreyas3156
Copy link
Contributor

Yes, that makes perfect sense now. Thanks!

@ricardoV94
Copy link
Member Author

Next interesting binary Ops would be and, or, all and any

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

No branches or pull requests

2 participants