Simple Random Walk
Defining the problem
First, let us define the problem formally.
To implement a 1-D simulation of random walk within period in sample space , with discrete stochastic process called steps of the random walk with the constrain .
The random walk can be formally defined as follow:
represents the initial value or start point of the random walk. Also, select that each elements of can take on integer values between -5 and 5.
This simulation is equivalent to plotting against .
import numpy as np import matplotlib.pyplot as plt # Generate random numbers within the range -5 to 5 # Note that randint(-5, high=6) generate range -5 to 5 N =5100 ; MIN_STEP = -5; MAX_STEP = 6; S_0 = 0; # Define parameters of the simulation X_T = np.random.randint(MIN_STEP , high=MAX_STEP , size=N+1) # Generate the discrete stochastic process t = np.linspace(0, N, N+1) # Time domain S = [S_0 + np.sum(X_T[0:i]) for i in xrange(N+1)] # Calculate each S(t) of the random walk plt.plot(t, S, '-') # Plot
2D Random Flight
In this example, we select that each elements to follows . It is, however, possible to introduce various other constrain to the process w.r.t. the application of your application.
It is also worthwhile to note that both and fulfills the definition of stochastic process with the state space being different.