Computational Methods in Physics ASU Physics PHY 494 (Spring 2020)

06 Random Walk with NumPy

A random walk is a mathematical object, known as a stochastic or random process, that describes a path that consists of a succession of random steps on some mathematical space such as the integers.

A popular random walk model is that of a random walk on a regular lattice, where at each step the location jumps to another site according to some probability distribution. In a simple random walk, the location can only jump to neighboring sites of the lattice, forming a lattice path. In simple symmetric random walk on a locally finite lattice, the probabilities of the location jumping to each one of its immediate neighbors are the same.1

1D random walk. Source: SciPy Lectures 1.3.2 NumPy: Numerical
  operations on arrays: Reductions by Emmanuelle Gouillart, Didrik
  Pinte, Gaël Varoquaux, and Pauli
  Virtanen. Simple 1D random walk. At every time step, a particle can hop to the left or right with equal probability. How far from the origin will it have moved after time t, expressed as the distance \(d(t)\)? Image Source: SciPy Lectures 1.3.2 NumPy: Numerical operations on arrays: Reductions by Emmanuelle Gouillart, Didrik Pinte, Gaël Varoquaux, and Pauli Virtanen.

Today, we are going to use the NumPy package to implement the 1D (example), 2D (skeleton and solutions) random walk models.

Class material

The class will be live-coded in a Jupyter notebook.

You can load the notebook yourself: first update your local PHY494-resources repository2

cd ~/PHY494-resources
git pull

Copy the notebooks to your work directory

cd
mkdir ~/PHY494/random-walk
cd ~/PHY494/random-walk
cp ~/PHY494-resources/random-walk/* .

and launch the Jupyter notebook interface in your web browser3:

jupyter notebook

Notebooks

Resources


Footnotes

  1. Wikipedia: Random Walk 

  2. If you have not set up your PHY494-resources repository then revisit Git Basics: Class resources

  3. If you have problems launching the notebook interface on Mac OS X, try

     jupyter notebook --ip=127.0.0.1
    

    If problems persist, google for the error message and ask for help.