Clipped acceptance reweighting identity (source code)

= Clipped acceptance reweighting identity
{title2=$p_{\mathrm{out}}(x)=q(x)a(x)/\mathbb E_q[a(Y)]$}

Draw proposals with <probability density function> or <probability mass function> $q$, independently draw $U$ from the <uniform distribution> on $(0,1)$, and repeat until $U\leq h(Y)$ for a nonnegative threshold $h$. The actual acceptance <probability> given $Y=y$ is $a(y)=\min(1,h(y))$. If $A=\mathbb E_q[a(Y)]>0$, the returned <probability distribution> has density or mass $q(y)a(y)/A$. Indeed the joint law of a proposal and acceptance has density or mass $q(y)a(y)$, and conditioning on acceptance divides by $A$. Summing over failed trials gives the same law and expected trial count $1/A$. Thresholds exceeding one cannot be used as unbounded reweighting factors.