{"action":"created","issue":{"url":"https://api.github.com/repos/uber/pyro/issues/1058","repository_url":"https://api.github.com/repos/uber/pyro","labels_url":"https://api.github.com/repos/uber/pyro/issues/1058/labels{/name}","comments_url":"https://api.github.com/repos/uber/pyro/issues/1058/comments","events_url":"https://api.github.com/repos/uber/pyro/issues/1058/events","html_url":"https://github.com/uber/pyro/issues/1058","id":316608408,"number":1058,"title":"Getting the posterior predictive samples for a model","user":{"login":"neerajprad","id":1762463,"avatar_url":"https://avatars3.githubusercontent.com/u/1762463?v=4","gravatar_id":"","url":"https://api.github.com/users/neerajprad","html_url":"https://github.com/neerajprad","followers_url":"https://api.github.com/users/neerajprad/followers","following_url":"https://api.github.com/users/neerajprad/following{/other_user}","gists_url":"https://api.github.com/users/neerajprad/gists{/gist_id}","starred_url":"https://api.github.com/users/neerajprad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neerajprad/subscriptions","organizations_url":"https://api.github.com/users/neerajprad/orgs","repos_url":"https://api.github.com/users/neerajprad/repos","events_url":"https://api.github.com/users/neerajprad/events{/privacy}","received_events_url":"https://api.github.com/users/neerajprad/received_events","type":"User","site_admin":false},"labels":[{"id":627803350,"url":"https://api.github.com/repos/uber/pyro/labels/question","name":"question","color":"d4c5f9","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-22T20:00:32Z","updated_at":"2018-04-22T20:49:16Z","closed_at":null,"author_association":"COLLABORATOR","body":"Consider a simple model like:\r\n\r\n```py\r\ndef model(at_bats, hits):\r\n    phi_prior = Uniform(hits.new_tensor(0), hits.new_tensor(1))\r\n    phi = pyro.sample(\"phi\", phi_prior)\r\n    return pyro.sample(\"obs\", Binomial(at_bats, phi), obs=hits)\r\n```\r\n\r\nI have collected some samples into an empirical distribution and want to look at the posterior predictive distribution. Note that I cannot just look at the marginal distribution for \"_RETURN\", which is fixed at \"obs\". One way to do this would be to change the model to:\r\n\r\n```py\r\ndef model(at_bats, hits):\r\n    phi_prior = Uniform(hits.new_tensor(0), hits.new_tensor(1))\r\n    phi = pyro.sample(\"phi\", phi_prior)\r\n    pyro.sample(\"obs\", Binomial(at_bats, phi), obs=hits)\r\n    return Binomial(at_bats, phi).sample()\r\n```\r\n\r\nThis seems somewhat of a hack. Another solution is to use a poutine to convert the observe sites to sample sites and condition the existing sample sites to the joint posterior and then draw samples from this model. This is too circuitous and inefficient. Yet another solution would be to have observe sites only affect `log_prob` but not `sample` (not sure if this would really work). Perhaps, there is a simpler way? @eb8680 - what would you suggest?\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/uber/pyro/issues/comments/383411238","html_url":"https://github.com/uber/pyro/issues/1058#issuecomment-383411238","issue_url":"https://api.github.com/repos/uber/pyro/issues/1058","id":383411238,"user":{"login":"neerajprad","id":1762463,"avatar_url":"https://avatars3.githubusercontent.com/u/1762463?v=4","gravatar_id":"","url":"https://api.github.com/users/neerajprad","html_url":"https://github.com/neerajprad","followers_url":"https://api.github.com/users/neerajprad/followers","following_url":"https://api.github.com/users/neerajprad/following{/other_user}","gists_url":"https://api.github.com/users/neerajprad/gists{/gist_id}","starred_url":"https://api.github.com/users/neerajprad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neerajprad/subscriptions","organizations_url":"https://api.github.com/users/neerajprad/orgs","repos_url":"https://api.github.com/users/neerajprad/repos","events_url":"https://api.github.com/users/neerajprad/events{/privacy}","received_events_url":"https://api.github.com/users/neerajprad/received_events","type":"User","site_admin":false},"created_at":"2018-04-22T20:49:16Z","updated_at":"2018-04-22T20:49:16Z","author_association":"COLLABORATOR","body":"> posterior_trace = sample_and_prune_trace(posterior_traces)\r\n\r\nTo make it a bit more pleasant looking, we can change `__call__` to return traces with `obs` sites removed (as per you suggestion in the PR). Still the fact that we need to write our model differently and use `condition` poutine to do some basic checks, seems like an area of improvement for the model specification API. That will need separate explaining to the users."}}
{"actor":{"display_login":"neerajprad"}}