Tuesday, April 10, 2012

Random Walk: Simulation Given Varying Grid Sizes

Related previous post: Random Walk: Foundational Codes

In the previous post, we saw the codes, both in Java and MATLAB, that calculate the number of unit steps in cardinal direction that would take to get to one corner to the other extreme corner of a 10 x 10 grid. The Java codes were altered to create a RandomWalk object class and a driver class. In the driver class, we tested for grid size of 2 to 101 inclusive, and for each size, ran 100,000 trials. The average of the 100K trials was computed for each size and the results are summarized here:

It shows that the size of the grid and the average number of steps follow a quadratic pattern. The high coefficient of determination (R^2) is actually quite deceptive for low values of the size. In fact, when the size is 11 or smaller, the equation's prediction differs by at least 5%. Here are the values for those sizes:

Grid Size Simulation Avg. Eqn. Prediction    Error
2 4.005 1113.372 276.986
3 18.020 961.017 52.330
4 44.527 836.168 17.779
5 85.095 738.825 7.682
6 141.726 668.988 3.720
7 214.755 626.657 1.918
8 305.839 611.832 1.001
9 414.232 624.513 0.508
10 542.374 664.700 0.226
11 690.416 732.393 0.061

For each of the 100 size, 100K trials were run. Each trial on average took just over 38K steps, upon considering this entire range of grid sizes. Overall, that's around 100*100K*38K = 380 billion iterations in this simulation. This simulation took just over 12 hours to finish running on Eclipse.