What's the benefit of Box-Muller method?

105 Views Asked by At

Maybe this is a silly question but I'd appreciate the answer. If I have a uniformly distributed number $x\sim U(-1,1)$, then:

$$ y=\mbox{sgn}(x)\sqrt{-\log(|x|)} $$

Should have a gaussian distribution. What is the advantage of using the Box-Muller method over using this technique? Is it that we compute $\sqrt{-\log(|x|)}$ only once for each pair of random values? But this wouldn't require computing $\sin$ and $\cos$ functions and unlike the Marsaglia polar method, it wouldn't reject any samples.

Is there an advantage for the other two methods when $x$ is close to $0$?

1

There are 1 best solutions below

0
On BEST ANSWER

You can try it numerically as follows. Doesn't look normal to me

import numpy as np
import matplotlib.pyplot as plt

N = int(1e6)
xx = 2*np.random.rand(N) - 1
yy = np.sign(xx) * np.sqrt(-np.log(np.abs(xx)))

histplot = plt.hist(yy, 100)

enter image description here


The conceptual issue is how probability densities transform under mappings, as described, e.g., here:

https://en.wikipedia.org/wiki/Probability_density_function#Scalar_to_scalar

You have to also multiply by the inverse of the Jacobian determinant of the mapping.