The Box-Muller transform converts pairs of independent uniform random variables into pairs of independent standard normal random variables. In population-based metaheuristics, it provides a two-dimensional Gaussian sampling method for generating initial solutions. section 7.1
A NumPy implementation follows two parallel calculations:
- Generate uniform arrays u1 and u2. section 7.1
- Compute x = sqrt(-2 log(u1)) cos(2πu2). section 7.1
- Compute y = sqrt(-2 log(u1)) sin(2πu2). section 7.1
Sampling an initial population
With N = 200, NumPy generates two length-N uniform arrays and produces P_BM_x and P_BM_y. A scatter plot compares their distribution with pseudo-random, central-limit, Sobol, and Latin-hypercube sampling. section 7.1
u1 = np.random.uniform(size=(N)) #1 u2 = np.random.uniform(size=(N)) #1 P_BM_x = np.sqrt(-2*np.log(u1))*np.cos(2*math.pi*u2) #2 P_BM_y = np.sqrt(-2*np.log(u1))*np.sin(2*math.pi*u2) #2
Inspect the direct NumPy formulas for both Gaussian coordinates. section 7.1
