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

Mechanism to reject samples #702

Closed
sdewaele opened this issue Mar 3, 2019 · 9 comments
Closed

Mechanism to reject samples #702

sdewaele opened this issue Mar 3, 2019 · 9 comments
Labels

Comments

@sdewaele
Copy link

sdewaele commented Mar 3, 2019

It would be useful to have a way for a probabilistic program to reject a sample. A possible implementation is that the program throws a specific exception to signal rejection.

@sdewaele
Copy link
Author

sdewaele commented Mar 3, 2019

Just to clarify the relationship with #703: Even with safe mode 'off', the exception that would be thrown for sample rejection would not cause the sampling to fail; only to reject the sample. Anyway, perhaps the dev team will decide on a different implementation than an exception.

@xukai92
Copy link
Member

xukai92 commented Apr 1, 2019

During sampling, at least for HMC, we reject samples for which the energy is Inf or NaN. So, if you simply implement you model such that it returns Inf when you got errors, the inference would work correctly.

Why not exception? Simply because it is slow. But you can always catch error and return Inf in your model definition (or logpdf for customised distribution).

@mohamed82008
Copy link
Member

mohamed82008 commented Dec 9, 2019

One can now do @logpdf() = -Inf; return to reject a sample in #965.

@yebai
Copy link
Member

yebai commented Dec 9, 2019

One can now do @logpdf() = -Inf; return to reject a sample in #965.

Might be worth to add this to the docs.

@yebai yebai added the doc label Dec 9, 2019
@mohamed82008
Copy link
Member

Sure!

@mohamed82008 mohamed82008 reopened this Dec 9, 2019
@sdewaele
Copy link
Author

sdewaele commented Dec 9, 2019

Thanks for implementing this!

@yiyuezhuo
Copy link

yiyuezhuo commented Aug 3, 2020

What's the current way to do it? @logpdf have been removed in fa44e8b#diff-107480759ab6311e0ad3c775750a1047

@devmotion
Copy link
Member

The current way is

Turing.acclogp!(_varinfo, -Inf)

which uses the internal variable _varinfo. In upcoming Turing versions you should use

@addlogprob!(-Inf)

instead (see TuringLang/DynamicPPL.jl#143 and the issue linked therein).

@devmotion
Copy link
Member

Closed by #1391.

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

No branches or pull requests

6 participants