Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just curious, how did you arrive at sqrt(n)? I spent all morning thinking about this in 2 dimensions and I came up with sqrt(n^2 + d^2) where d is the displacement from the original position on the y axis. (Pythagorean theorem)


Central limit theorem. You get to √(n² + d²) if you take n steps to the right and d steps up. But if you take n steps randomly to the left or right, you end up at about αn steps in one direction or the other, on average, because the distribution of your final position is a Gaussian around your original position whose standard deviation grows as √n.

Try it:

    >>> n=1000; sorted(abs(sum(random.randrange(2) for i in range(n)) - n/2) for j in range(128))
As you increase n you can see the distribution of final distances widen by its square root.

As it happens, in two dimensions the distribution is radially symmetric, and its radius is still proportional to the square root of the number of steps. This accounts for the astounding isotropy of lattice-gas automata, whose particles are doing such random walks simultaneously, and for the depressing popularity of Gaussian filtering in image processing, because the Gaussian convolution kernel is the only anisotropic separable kernel, and can be closely approximated in each dimension very cheaply with a different application of the central limit theorem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: