{"action":"created","issue":{"url":"https://api.github.com/repos/probmods/webppl/issues/169","labels_url":"https://api.github.com/repos/probmods/webppl/issues/169/labels{/name}","comments_url":"https://api.github.com/repos/probmods/webppl/issues/169/comments","events_url":"https://api.github.com/repos/probmods/webppl/issues/169/events","html_url":"https://github.com/probmods/webppl/pull/169","id":103042017,"number":169,"title":"Refactored MH & SMC","user":{"login":"null-a","id":9109012,"avatar_url":"https://avatars.githubusercontent.com/u/9109012?v=3","gravatar_id":"","url":"https://api.github.com/users/null-a","html_url":"https://github.com/null-a","followers_url":"https://api.github.com/users/null-a/followers","following_url":"https://api.github.com/users/null-a/following{/other_user}","gists_url":"https://api.github.com/users/null-a/gists{/gist_id}","starred_url":"https://api.github.com/users/null-a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/null-a/subscriptions","organizations_url":"https://api.github.com/users/null-a/orgs","repos_url":"https://api.github.com/users/null-a/repos","events_url":"https://api.github.com/users/null-a/events{/privacy}","received_events_url":"https://api.github.com/users/null-a/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":23,"created_at":"2015-08-25T15:03:10Z","updated_at":"2015-09-18T16:42:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/probmods/webppl/pulls/169","html_url":"https://github.com/probmods/webppl/pull/169","diff_url":"https://github.com/probmods/webppl/pull/169.diff","patch_url":"https://github.com/probmods/webppl/pull/169.patch"},"body":"As discussed in #64. I don't think there are any significant changes left to make so now seems a good time to open a PR.\r\n\r\n**Changes**\r\n\r\n* `MH` and `HashMH` are replaced by a new `MCMC` routine which is parameterized by a transition kernel. The important features of both `MH` and `HashMH` have been retained, and [performance is expected to be very similar](https://github.com/probmods/webppl/issues/64#issuecomment-133002277) to that of `HashMH`. The intention is that this can be used with other kernels though at present there is only `MHKernel`. (I've not tried to make this work with `HMC` or `IncrementalMH` yet.)\r\n* `ParticleFilter` and `ParticleFilterRejuv` are replaced by a new `SMC` routine. This optionally takes a transition kernel and uses it to do rejuvenation. Performance is very similar [or better](https://github.com/probmods/webppl/issues/64#issuecomment-134285022) than the corresponding `ParticleFilter` and `ParticleFilterRejuv` methods.\r\n\r\nI've also endeavored to improve readability and reduce duplication where I can. I hope this is evident when you look at the code, but if not let me know and I'll point out some areas where I think things have improved.\r\n\r\n**Interface**\r\n\r\nUsing the new methods looks like this:\r\n\r\n```\r\nMCMC(model, { samples: 1000 });\r\nMCMC(model, { samples: 1000, lag: 5, burn: 100, kernel: MHKernel });\r\nMCMC(model, { samples: 1000, verbose: true }); // Shows current iteration and acceptance ratio.\r\nMCMC(model, { samples: 1000, onlyMAP: true });\r\nMCMC(model, { samples: 1000, justSample: true });\r\n\r\nSMC(model, { particles: 1000 });\r\nSMC(model, { particles: 1000, rejuvSteps: 10 });\r\nSMC(model, { particles: 1000, rejuvSteps: 10, rejuvKernel: MHKernel });\r\n```\r\n\r\nThe hope is that this will work nicely with the interface changes proposed in #86. I've created wrappers `MH`, `ParticleFilter` and `ParticleFilterRejuv` for backwards compatibility.\r\n\r\n**Minor Changes**\r\n\r\n* `MCMC` takes an option `samples` which specifies how many samples you want back, rather than the number of iterations to perform. The number of iterations is computed from `samples`, `lag` and `burn`.\r\n* The `justSample` option of `MCMC` returns the MAP estimate, not just the samples. This part of the interface still needs work. (See [#86](https://github.com/probmods/webppl/issues/86#issuecomment-100244114), #140.)\r\n* I've reworked the handling of variable numbers of factors in the particle filter. Instead of checking whether each particle is active when manipulating `particleIndex` I partition the particles into two sets - active and complete. This implements the same strategy but might be easier to understand, though I'm not sure. I left it in for people to have a look at.\r\n* I've removed the `varFactors` tests from `ParticleFilterRejuv`. The `varFactors1` test wasn't actually doing any rejuvenation and it fails when this is corrected. ([Related discussion](https://github.com/probmods/webppl/issues/20#issuecomment-133129248).)\r\n* We no longer have the `diagnostics` option which was part of `MH`. Instead `justSample` can be used to get all of the samples in order to perform convergence checks etc.\r\n\r\n**Also Fixed**\r\n\r\n* #51\r\n* #120\r\n* #145\r\n* #147\r\n* #149\r\n* #151\r\n* #155 (`IncrementalMH` needs the fix too.)\r\n* #156\r\n"},"comment":{"url":"https://api.github.com/repos/probmods/webppl/issues/comments/141503945","html_url":"https://github.com/probmods/webppl/pull/169#issuecomment-141503945","issue_url":"https://api.github.com/repos/probmods/webppl/issues/169","id":141503945,"user":{"login":"stuhlmueller","id":382515,"avatar_url":"https://avatars.githubusercontent.com/u/382515?v=3","gravatar_id":"","url":"https://api.github.com/users/stuhlmueller","html_url":"https://github.com/stuhlmueller","followers_url":"https://api.github.com/users/stuhlmueller/followers","following_url":"https://api.github.com/users/stuhlmueller/following{/other_user}","gists_url":"https://api.github.com/users/stuhlmueller/gists{/gist_id}","starred_url":"https://api.github.com/users/stuhlmueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuhlmueller/subscriptions","organizations_url":"https://api.github.com/users/stuhlmueller/orgs","repos_url":"https://api.github.com/users/stuhlmueller/repos","events_url":"https://api.github.com/users/stuhlmueller/events{/privacy}","received_events_url":"https://api.github.com/users/stuhlmueller/received_events","type":"User","site_admin":false},"created_at":"2015-09-18T16:42:55Z","updated_at":"2015-09-18T16:42:55Z","body":"I just realized that the MCMC code can be simplified a little bit more—see [here](https://gist.github.com/stuhlmueller/1ee91b12b2f940509882)."}}