Sampling – How to Sample from Truncated Normal Distribution

bayesiansamplingtruncated normal distribution

I am trying to sample from a truncated normal using the standard probability integral transform as described on wikipedia with
$$ x = \Phi^{-1} ( \Phi(\alpha) + U*( \Phi(\beta) – \Phi(\alpha)))*\sigma + \mu $$ with $U \sim Uniform(0,1)$, $\alpha = (a-\mu)/\sigma$ and $\beta = (b-\mu)/\sigma$. In my application, $a = 0.0$ and $b = \infty$.

However, this method fails for instance if $\mu = -0.4$ and $\sigma = 0.05$. I know that sampling positive values with these parameters is highly unlikely. Therefore, I guess I run into errors caused by numerical overflow. I use the GSL library in C to sample the values.

Can you recommend any routine to sample values nevertheless? The PIT yields for instance $\infty$ as sample, which I can obviously not process.

This one I already used:
Truncated Normal by John Burkardt

Best Answer

If you're sampling the extreme tail, a version of the accept reject method X'ian describes in the paper linked in his answer at that earlier question (basically using an exponential proposal) should work really well.

[The comment containing the link was deleted. I mean this earlier Q]

Plot of upper tail of normal with exponential majorizing function

Out this far, the rejection rate should only be about 2.5%; that's pretty decent; you would be generating about 41 exponentials for every 40 truncated normal values you keep.

Related Question