How can I show the acceptance rate when NUTS is used?

Hello,

I calculated sum( trace[‘model_logp’][1:]==trace[‘model_logp’][:-1] )/len(trace[‘model_logp’]), which, I thought, is an acceptance rate. But I found that it approaches zero as the dimension increases.
trace[‘mean_tree_accept’].mean() is close to the given target accept rate, though…
How can I calculate the correct acceptance rate?

Thanks

In classical HMC, we propose one new point and either accept that one point or stay where we started. But in dynamic hmc (nuts) we produce a trajectory in each step, and always sample one point from that whole trajectory (which includes the starting point) using multinomial sampling, where the weights are based on the energy error.

So your first prob sum( trace[‘model_logp’][1:]==trace[‘model_logp’][:-1])/len(trace[‘model_logp’]) is just how likely it is that we end up at the starting point. With no integration error that would just be 1/treesize. The second is the mean multinomial weight, where the starting point has weight 1, and the value that should be close to target_accept.
See section A.4 in https://arxiv.org/pdf/1701.02434.pdf for details.

3 Likes

Thank you so much! I’ll read the reference.

1 Like

Sure :slight_smile:
Feel free to ask if something isn’t clear.