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
Add unnormalized distributions to the language #63
Comments
just hitting this now - should this actually be inverted? We have a |
I think we should support marked cases and leave the unmarked cases the same. So the following two groups would contain equivalent statements, leading off with our existing forms.
You can think of the first statement in each of these two groups as syntactic sugar and the I could be convinced that |
Oh, for supporting these for users? Sure, makes sense. I'm having trouble parsing the two groups. Are you saying y ~ foo(theta) = target += foo_lpdf(y | theta) and so on, line 1 = line 1, line 2= line 2, line 3 = line 3? Or also that line 1 = line 2 = line 3? |
@VMatthijs likes "_unnormalized" and Bob likes "_propto." Unfortunately I don't really care - propto is nice in that it's what we use in code gen |
Fix #63, which fixed low_dim_gauss_mix
I don't really care either. Let's go with _propto. |
I don't think these have been exposed to the language yet. They're in the backend now, but the type checker should still be made to accept them. |
Yep, sorry about that. |
Our current y ~ foo(theta) is propto/unnormalized.
Our current target += foo_lpdf(y | theta) is normalized.
The ones grouped together are equivalent.
I don't really care so much about propto vs. unnormalized. I can see arguments either way. We should ask a wider group of statisticians about what they think is natural.
|
Agreed! I'll write up a discourse post. |
Just a reminder to ourselves that whatever ends up being implemented should be documented in the wiki. (And then in the manual when we are ready to release.) |
Does anyone remember why we wanted to expose this to the end users in the language? Was there a motivating use-case for when you needed to use |
@bob-carpenter , weren't you concerned about the normalizing constant of a gamma distribution being expensive to compute or something like that? |
Yes, in general there's a lot of expensive computation that's avoided if we can do unnormalized/propto computations. But then in some contexts, like mixtures, we need the normalized forms.
Also, if we want to reduce sampling statements to target increment statements, then we need this flexibility to be able to actually implement the sampling statements as they're currently implemented (unnormalized, that is).
|
We don't actually need this exposed to end users to do that, right?
Agreed, but are there cases where you can't use In other words, are there specific motivating examples for exposing this to end users of the Stan language? |
Based on discussions with @seantalts and @bob-carpenter :
For each distribution, e.g.
poisson_lpmf
, make the compiler accept the function namepoisson_unnormalized_lpmf
as well.This should code gen to
poisson_lpmf<true>
.This allows us to treat
x ~ poisson(42);
as syntactic sugar for
target += poisson_unnormalized_lpmf(x| 42);
.This is related to issue stan-dev/stan#1299 .
Also make sure that algebraic optimizations like
bernoulli_lpmf(x|inv_logit(theta))->bernoulli_logit_lpmf(x|theta)
and automatic vectorization optimizations apply to these unnormalized distributions as well.The text was updated successfully, but these errors were encountered: