Closed fonnesbeck closed 3 years ago
Hi!
Is it open as a good-first-issue? If yes then I would like to try it.
I haven't used pyro
(only TFP) so I would be grateful if you could point out which examples from http://pyro.ai/examples I can refer to and follow while learning and writing.
Hi @mtsokol, yes this would be a good first issue.
But wait, it looks like the baseball example and the Bayesian Regression II tutorial use MCMC and Predictive
. @fonnesbeck can you suggest how we might improve these tutorials and examples to make Predictive
easier to understand?
EDIT my mistake, it looks like Bayesian Regression II uses Predictive
with SVI rather than with MCMC. @mtsokol WDYT of making a simple tutorial kind of like Bayesian Regression but with a model with pyro.deterministic
sites in it? For example I'm working with a regression model that looks like
where you could examine samples from the deterministic rate
variable.
My mistake--did not notice it in the baseball example. One minor suggestion is for important classes like Predictive
to have links in the API docs to where it is used in the examples. I think Tensorflow does this (not sure if its done automatically or manually).
Hi @fritzo! Sorry for the delay and thank you for a guidance!
I did a short (draft with possible errors and misunderstanding) notebook in a "tutorial" way that utilizes deterministic
, Predictive
and MCMC
with the model you provided. But it's pretty short and it repeats content from existing tutorials so I don't think it's worth it. (However writing it was a great way to familiarize myself with the library!)
I can search for another issue in pyro
or numpyro
or continue this notebook according to your tips if you consider it worthwhile. What do you think?
Links to the notebook: https://nbviewer.jupyter.org/gist/mtsokol/fe00f78bb0b925f986d241622c2ec019 https://gist.github.com/mtsokol/fe00f78bb0b925f986d241622c2ec019
(I focused on explaining deterministic
, rate
variable and GammaPoisson
distribution)
Hi @mtsokol your notebook looks great! Even though it is simple, I still think it is worth publishing it and adding to the index, so feel free to submit a PR.
I think the following additions would also help users:
Predictive
and pyro.deterministic
, so users can see other uses.Predictive
object.Predictive
could be replaced with either replay+trace as in
guide_trace = poutine.trace(guide).get_trace(*args, **kwargs)
model_trace = poutine.trace(poutine.replay(model, guide_trace)).get_trace(*args, **kwargs)
or condition+trace as in
samples = mcmc.get_samples()
vectorize = pyro.plate("particles", num_particles, dim=-model_specific_dim)
trace = poutine.trace(poutine.condition(vectorize(model), samples)).get_trace(*args, **kwargs)
(I find that in complex situations I often need to write custom code like this).
Anyway, don't hesitate to put up a PR even for a small notebook, and thanks for writing this!
Hi @mtsokol
Don't you need to add a bias term in the regression?
Also, it would nice to add a line explaining why GammaPoisson
is appropriate for this example.
Thanks!
Hi @khsibr!
The model I used here was suggested by @fritzo a few comments before so I can't really elaborate why it's designed that way.
I've just opened a PR with updated notebook #2852 where we can continue discussion.
Completed in #2857
There are currently no examples in the docs and tutorials of
Predictive
being used in MCMC sampling. Given its importance in returning deterministic values of interest from models, it would probably be useful for users to be able to see how they are used.