Cauchy Random Walks, 2D and 3D

1 million steps, with step size determined by a Cauchy distribution, and angle(s) by a flat distribution.

In [1]:
T = 1000000
X = np.zeros((T,2))

figsize(10,10)

for t in range(T-1):
    stepSize = np.random.standard_cauchy()
    direction = np.random.rand()*2*math.pi
    xStep, yStep = cos(direction)*stepSize, sin(direction)*stepSize
    X[t+1,0] = X[t,0] + xStep
    X[t+1,1] = X[t,1] + yStep
    
plt.plot(X[:,0],X[:,1],lw=2)
plt.show()
In [2]:
X = np.zeros((T,3))

for t in range(T-1):
    stepSize = np.random.standard_cauchy()
    direction1 = np.random.rand()*2*math.pi
    direction2 = np.random.rand()*2*math.pi

    xStep = cos(direction2)*cos(direction1)*stepSize
    yStep = sin(direction1)*stepSize
    zStep = sin(direction2)*cos(direction1)*stepSize
    
    X[t+1,0] = X[t,0] + xStep
    X[t+1,1] = X[t,1] + yStep
    X[t+1,2] = X[t,2] + zStep
    
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')  
ax.plot(X[:,0],X[:,1],X[:,2])
frame1 = plt.gca()
frame1.axes.set_xticklabels([])
frame1.axes.set_yticklabels([])
frame1.axes.set_zticklabels([])

plt.show()

Leave a Reply

Your email address will not be published. Required fields are marked *