MCMC - accept or reject simple sample using step function

I am looking for the example where I am able to decide whether to accept or reject the sample drawn from MCMC. I am using Hamiltonian MC.

It is mentioned in the documents that one can use a custom step function. But it is not clear

  • How to get the currently sampled value from the distribution
  • How to accept or reject this value? As in where? Step function? What if step function is dependent on the other parameters as well, how to pass those?
  • How to update the distribution based on acceptance? Like once I accept the sample, I should be able to update the distribution (which will eventually become my posterior over the period of time)

These are pretty broad questions, I suggest you to read Mike Betancourt’s introduction to statistical computing and Hamiltonian Monte Carlo, which is very comprehensive. Also see http://docs.pymc.io/notebooks/sampling_compound_step.html

Here are some quick pointers:

Not clear what you meant by the distribution here. I assume you mean posterior? In that case, you don’t really “get” a sampled value (ie proposal) from the posterior, instead, the sampler make a suggestion using some rules (eg, sample from a normal distribution with the mean being the last sample), and you use the posterior distribution to accept or reject the proposal.

Not sure what you meant by Step function here - assume you mean step method. The accept/reject is done within each step method yes, it evaluate posterior using the proposal as input, and compare to logp value of the previous sample.
If the step function depends on other parameters, it doesnt really matter because within the same model what is being computed is still the model logp.

You dont update the distribution. You merely save the accepted (or rejected) samples, and after a while these samples distributed as your posterior.

@junpenglao, thank you very much for taking time to answer me. I have asked much specific and clear question here. I think you are very educated about pymc3, so i request to answer this question as well.

And thank you for the resources well. Paper you suggest is very useful to me