Conversation
|
Thanks, that would be great! I'll try to use it. |
neerajprad
left a comment
There was a problem hiding this comment.
This looks great, pending any further review comments from @fritzo.
I think your current setup is fine, but this will be a reasonable restriction to have. I am not sure if there are any use cases for deterministic inside a plate context, but it may be easier to just have it than to reliably disable it. |
Sure, this seems like a simple way to satisfy the intended use case (predicting deterministic quantities in |
pyro/primitives.py
Outdated
| def deterministic(name, value, event_dim=None): | ||
| """ | ||
| Deterministic statement to add a site with `value` to the trace. This does not affect | ||
| the model density. |
There was a problem hiding this comment.
Could you expand the docstring with information about what exactly is added to the trace and when someone might want to use deterministic?
There was a problem hiding this comment.
In case you find it useful, we needed this for the linear regression example to record the mean response, which will be a deterministic function of the coefficients, data and the intercept.
|
@fehiepsi you might want to add to the docstring an EXPERIMENTAL marker and a comment that "this currently converts to a pyro.sample statement, but may change in the future", then we can later create a new site type and remove the |
|
@fehiepsi do you want to make the docs changes? I've been holding off merging because I interpreted your 👍 as "sure I'll make those changes before this merges". But if you want to make those changes in a follow-up PR that is also fine. |
|
@fritzo I want to make the docs changes. I have marked "awaiting response" to remind me that I should do it. :) |
|
@eb8680 @neerajprad @fritzo Sorry for the delay and thanks for your suggestions! |
|
@eb8680 @neerajprad do you have further comments before we merge? |
|
LGTM. |
This PR adds
deterministicprimitive to Pyro to record deterministic values in a trace as requested in pyro-ppl/numpyro#462, #2063 (comment), and here and there in the forum. The functionality is similar to pymc3.Deterministic or Stan's transformed parameters and generated quantities.Note that the implementation is just an alias of
sample(name, dist.Delta(value), obs=value)so it might have some overhead to computing joint density. However, I think that this primitive is mostly used in prediction, so users can remove this overhead by using the patternEdit: It seems that we also need an additional arg
event_dimto explicitly state the event dimension of that deterministic site (see the test) so thatlog_probshape matches those of the other sites. This seems like a bad idea because we only need to record the values of these deterministic sites. Maybe we should require that these deterministic sites should not be used inside a plate statement. In case it is used inside a plate state, an explicit event_dim is required.