An interesting application of Monte Carlo methods is estimating the value of pi. By estimating the area of a unit circle and using the equation of the area of a circle, we can find pi. This is part of exercise 6.5 in the computational physics textbook by Landau (2015)1 on Monte Carlo integration.
To demonstrate multi dimentsional Monte Carlo methods, we try to find the value of pi by approximating the area of a circle. To do this, we take a circle inscribed inside a square with lengths in interval [-1, 1]. By throwing random points within the interval and finding the ratio between the number of points inside the circle and the total number of points, we can approximate the area. Since the radius of the circle is 1, the area that we retrieve in this method should converge to pi.
Randomness in computers are usually implemented using pseudo-random sequences. Although it is possible to use numbers generated using pseudo-random sequences for Monte Carlo methods, it is possible to achieve faster convergence using quasi-random sequences instead. Quasi-random sequences, also known as low-discrepancy sequence provide an improvement as it covers the space more evenly than normal random sequences.
The Halton sequence is generated by choosing a base number and dividing the chosen interval up by that base number. Each dimension is then generated with this sequence by choosing base numbers that are coprime for each dimension. For example, if we chose 2 as the base number and an interval (0,1), we would get this sequence:
We could then chose 3 as the base number for the next dimension to get this sequence:
The implementation of the sobol sequence follows the paper by Bratley and Fox (1988)2.
Suppose we want to generate a sequence
To do this, we first generate "direction numbers"
with coefficients
where ^ is the bitwise XOR operator and >> is the bitwise right shift operator (shifting right by
We can then define the recurrence relation in terms of
With this, we can then get the points for the sobol sequence as
where
The direction numbers are prrovided by Stephen Joe and Frances Kuo3. Although we require only 2 dimensions, the numbers provided support up to 21201 dimensions. The file includes dimension
We find that the sobol sequence is superior in terms of convergence compared to the other generators and get very close to the correct number of pi to 2 decimal points with only 10,000 points. (To be done: scrambled sobol sequence)