The --info option produces a list of used functions and distributions#813
Conversation
|
I do not understand why the changes in this PR cause the following error: It looks unrelated to the |
|
This is unrelated, maybe a one-off error on our test machine or a configuration issue on the machine. In both cases, dont worry about that, we will look into that. EDIT: Passing now, so it was a one-off thing, sorry. Thanks for the PR! Looks nice. Two comments/questions:
|
I do not have a strong opinion but it is easier to add a post-processing phase that merge them than the converse. Moreover, in our Stan to (Num)Pyro compiler with keep the two forms separated and might have a benefit to have access to this information.
It seems that this function does not add the |
That is an interesting question. In these examples, the functions in argument of |
+1, I think it's neat to present additional information that could be helpful. I'm not sure if this is better or worse but we could also structure it something like |
Very good point. Ignore my previous comment. Splitting these up is good.
Ah yes, I was overthinking this. Obviously these call user-defined functions so the current behaviour is fine. We were discussing functors for Stan lib functions in stan-dev/design-docs#35 but we can address that if we actually do start supporting it. |
There was a problem hiding this comment.
Thanks again for working on this!
Sorry I suggested the wrong function in my comment. This is the example (we only care of the StanLib ones):
let possible_names =
List.map ~f:(( ^ ) distribution.name) Utils.distribution_suffices
|> String.Set.of_list
in
if List.exists ~f:(fun (n, _) -> Set.mem possible_names n) ud_dists (* ud_dists is the 'dirichlet' in our case *)
then Fun_kind.UserDefined
else StanLibI am nitpicking here because I think
l ~ dirichlet(c);
target += normal_lpdf(y| 0, 1);should both return functions either with or without the suffix. I prefer with suffix but would be fine without it as well as long as its consistent.
Also please add a test for Stan lib functions in user-defined functions:
functions {
real foo(real a) {
return sin(a);
}
real goo_lpdf(real a) {
return a;
}
}If I then add
y ~ goo();goo should not be listed.
|
Thanks @rok-cesnovar. I have implemented most of your suggestions. But for now we still distinguish distributions with and without post-fix. If you do not like the current solution, I also prefer the solution where the post-fix is added since it is always easy to remove the post-fix later. But in this case, I think that it would be good to expose the function |
|
Thanks! I think we want to have the _lpdf/_lpmf suffixes. My reasoning is that these two models are equivalent, produce the exact same C++ code and should also produce the same output with --info. parameters {
real y;
}
model {
y ~ std_normal();
}
parameters {
real y;
}
model {
target += std_normal_lupdf(y);
}
I would say Middle.Utils but not sure. Do you have a preference @seantalts ? Utils has all the other distribution suffix utilities, idk. |
rok-cesnovar
left a comment
There was a problem hiding this comment.
My above comment got me thinking about another test case. Sorry I missed this earlier.
Co-authored-by: Rok Češnovar <rok.cesnovar@fri.uni-lj.si>
|
In fact, it is not possible to move |
I think so yes. I would also rename |
|
You're welcome! |
Release notes
As part of the issue #808, it was discuss to add the list of "all named functions used". I understood that as the list for functions called from the standard library and the list of used distribution.
This PR adds to the JSON object produced by the
--infooption the two following fields:stanlib_calls: list of functions of the standard library called in the programdistributions: list of distributions to the right of a~statement.Copyright and Licensing
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)