-
-
Notifications
You must be signed in to change notification settings - Fork 371
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 _lupdf and _lupmf functions in the transformed parameters block #3094
Comments
The compiler error is there for a reason; the _lupdf mechanism in Stan math library is tied to the autodiff and cannot work correctly outside of the model block. This issue was discussed and closed in stanc3 repo. Some context in this Discourse comment. |
Thank you! That makes sense. Closing this issue. |
While it's tied to autodiff, that doesn't mean it can't work outside the model block. The I've found it inconvenient that I can't use The transformed parameters block is just like the model block right down to where the code is generated in the C++. That is, it's generated inside the context where the
This would do exactly what I wanted it to do if you just generated |
Both the model and transformed block are in the same log_prob call with propto = true, yes. However, the actual output for the transformed parameters is calculated in write_array, which does not use auto diff. So in your above case, the target would be updated correctly during sampling/VI, but the output of A weird hack to fix this would be to always generate the calls with _lpdf in write_array only, though that seems like a bad workaround. |
Summary:
Allow
_lupdf
and_lupmf
in the transformed parameters block.Description:
For implementing prior sensitivity checks via power scaling (https://arxiv.org/abs/2107.14054; a paper together with @avehtari), we need to store the prior contributions to the log posterior. For this purpose, we currently define a quantity
log_prior
in the transformed parameters block to which we subsequently add_lpdf
and_lpmf
statements of the priors. This appears to work nicely. However, when I want to use the unnormalized versions_lupdf
and_lupmf
instead, I get a compiler error.Reproducible Steps:
Try to compile
Current Output:
Compiler error:
Expected Output:
Stan compiles this model.
Additional Information:
Provide any additional information here.
Current Version:
v2.28.2
The text was updated successfully, but these errors were encountered: