-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
allow lp functions in transformed parameters #767
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to remove allowing _lupdf
in _lp functions as well https://github.com/stan-dev/stanc3/pull/767/files#diff-ac78bfdef130e5ec4b7b3b245cddf78d3e7cb992ea1849fadafb2a70e248a0ffL263
Hm. And this would also be allowed then:
|
Good catch. |
If we are not allowing I guess one possible solution is to check that a _lp function used in TP does not have _lupdf/tilde but that can get messy and its also pretty tricky. |
lupdf in a tilde statement is not a problem because
Yeah, I don't think special restriction based call-site are a good idea. |
I am not sure I completely understand, so allow me another question. Allowing functions {
real lprob_lp(real x) {
return normal_lupdf(x | 0, 1);
}
}
parameters {
real x;
}
transformed parameters {
real ll = lprob_lp(x);
}
model {
target += ll;
} and not allowing this case is the reason we have lupdf restrictions. With the tilde statement this would only be a problem if someone did this right? functions {
real lprob_lp(real x) {
x ~ normal(0, 1);
return target();
}
}
parameters {
real x;
}
transformed parameters {
real ll = lprob_lp(x);
}
model {
target += ll;
} Which is what stanc2 allows. |
Yes, that looks right. So the inconsistency with unnormalized distributions was present already in stanc2, it was just difficult to find. |
Yeah. So we either: a) allow _lp in TP, restrict _lupdf and reveal back the difficult to find inconsistency which is present in stanc2 All bad options :) a) is I guess the least bad? Though b) is the only bug-free option here. |
It's also possible to forbid I'm not sure what is the use case for |
Pushed a change to disallow _lupdfs in _lp functions. With that the only nondeterminism is confined in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
Prompted by issue #748
One line change because
write_array()
method already hadlp_accum__
variable. The fact that it's not needed for anything other than_lp
functions suggest that this may have been intented all along.In any case, this is a backwards compatibility gotcha and per discussion on the forum something like this is needed.
Release notes
Allow calling lp functions in transformed parameters block.
Copyright and Licensing
Copyright holder: Niko Huurre
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)