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

Inf is treated as variable rather than data #15

Closed
xukai92 opened this issue Sep 13, 2019 · 9 comments
Closed

Inf is treated as variable rather than data #15

xukai92 opened this issue Sep 13, 2019 · 9 comments

Comments

@xukai92
Copy link
Member

xukai92 commented Sep 13, 2019

In the MWE below, Inf is treated as a variable rather than the literal Inf.

using Turing

@model mwe() = begin
    m ~ Normal(0, 1)
    Inf ~ Normal(m, 1)
end

sample(mwe(), HMC(0.1, 2), 100)
@xukai92
Copy link
Member Author

xukai92 commented Sep 13, 2019

Reported by @jonasmac16.

@mohamed82008
Copy link
Member

mohamed82008 commented Sep 16, 2019

This is an interesting one, but may I ask how is supporting Inf as data useful?

@xukai92
Copy link
Member Author

xukai92 commented Sep 16, 2019

It's for something like below

res = solve(...)
if res.success
    data ~ dist
else
    Inf ~ dist
end

@mohamed82008
Copy link
Member

Can we achieve the same goal by defining the Impossible distribution? rand(::Impossible) = NaN and logpdf(::Impossible, ::Any) = -Inf.

res = solve(...)
if res.success
    data ~ dist
else
    data ~ Impossible()
end

Supporting Inf on the LHS is also possible.

@xukai92
Copy link
Member Author

xukai92 commented Sep 16, 2019

Yes there are maily work aournds for this. Like the one you post or just pass in a data call data_inf which is Inf. But it's might be cool for the user to do so easily.

@yebai
Copy link
Member

yebai commented Sep 16, 2019

Maybe standardize the compiler API for LHS with concrete values, by e.g. introducing a function operate on Julia expressions (which can be called by the @model macro)? This would allow the user to overload ~ for specific use cases.

@mohamed82008
Copy link
Member

Sounds good.

@mohamed82008 mohamed82008 transferred this issue from TuringLang/Turing.jl Dec 25, 2019
@devmotion
Copy link
Member

As discussed in #57 (comment), I think the more natural way to write the example above would be

res = solve(...)
if !res.success
	@logpdf() = -Inf
	return
end

data ~ dist

So can this issue be closed, @xukai92, or are there other use cases that require a specific fix for Inf?

@xukai92
Copy link
Member Author

xukai92 commented Apr 13, 2020

It makes sense. The issue was originally rasied by a user in slack. Let's close if for now.

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

No branches or pull requests

4 participants