A Lévy flight, named for French mathematician Paul Lévy, is a random walk in which the step-lengths have a probability distribution that is heavy-tailed. When defined as a walk in a space of dimension greater than one, the steps made are in isotropic random directions.
The term "Lévy flight" was coined by Benoît Mandelbrot, who used this for one specific definition of the distribution of step sizes. He used the term Cauchy flight for the case where the distribution of step sizes is a Cauchy distribution,and Rayleigh flight for when the distribution is a normal distribution(which is not an example of a heavy-tailed probability distribution).
http://www.sitpor.org/wp-content/uploads/2016/08/A-brief-introduction-to-L%C3%A9vy-Process1.pdf
import numpy as np
import matplotlib.pyplot as plt
n = 20
X0 = np.array([[0],[0]])
Displacement1 = np.random.zipf(2, (2,n))
Displacement2 = np.random.zipf(2.5, (2,n))
Displacement3 = np.random.zipf(3, (2,n))
D1 = np.concatenate((X0, np.cumsum(Displacement1, axis=1)), axis=1)
D2 = np.concatenate((X0, np.cumsum(Displacement2, axis=1)), axis=1)
D3 = np.concatenate((X0, np.cumsum(Displacement3, axis=1)), axis=1)
plt.plot(D1[0],D1[1], "yo--", markersize = 2, linewidth =1, label='$Levy, a = 2 $')
plt.plot(D2[0],D2[1], "go--", markersize = 2, linewidth =1, label='$Levy, a = 2.5 $')
plt.plot(D3[0],D3[1], "ro--", markersize = 2, linewidth =1, label='$Levy, a = 3 $')
plt.legend(loc = 'upper left')
plt.xlabel("$x$")
plt.ylabel("$y$")
plt.savefig("GRW1.pdf")
plt.show()
#------------------------plotting different RW--------------------------------------
plt.figure()
plt.subplot(221)
Displacement = np.random.random((2,n))
D = np.concatenate((X0, np.cumsum(Displacement, axis=1)), axis=1)
plt.plot(D[0],D[1], "go--", markersize = 1, linewidth =1, label='uniform [0,1]')
plt.legend(loc = 'upper left')
plt.xlabel("$x$")
plt.ylabel("$y$")
plt.subplot(222)
Displacement = 2*np.random.random((2,n))-1
D = np.concatenate((X0, np.cumsum(Displacement, axis=1)), axis=1)
plt.plot(D[0],D[1], "go--", markersize = 1, linewidth =1, label='uniform [-1,1]')
plt.legend(loc = 'upper left')
plt.xlabel("$x$")
plt.ylabel("$y$")
plt.subplot(223)
Displacement = np.random.normal(0,1, (2, n))
D = np.concatenate((X0, np.cumsum(Displacement, axis=1)), axis=1)
plt.plot(D[0],D[1], "go--", markersize = 1, linewidth =1, label='Normal(0,1) ')
plt.legend(loc = 'upper left')
plt.xlabel("$x$")
plt.ylabel("$y$")
plt.subplot(224)
Displacement = np.random.zipf(3, (2,n))
D = np.concatenate((X0, np.cumsum(Displacement, axis=1)), axis=1)
plt.plot(D[0],D[1], "go--", markersize = 1, linewidth =1, label='Levy, a = 3 ')
plt.legend(loc = 'upper left')
plt.xlabel("$x$")
plt.ylabel("$y$")
plt.savefig("GRW2.pdf")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
N = 50
ens = 10000
rw1 = np.zeros((2, N+1))
rw2 = np.zeros((2, N+1))
for k in range(ens):
X0 = np.array([[0],[0]])
Displacement1 = np.random.zipf(2, (2,N))
Displacement2 = np.random.zipf(3, (2,N))
D1 = np.concatenate((X0, np.cumsum(Displacement1, axis=1)), axis=1)
D2 = np.concatenate((X0, np.cumsum(Displacement2, axis=1)), axis=1)
rw1 += D1
rw2 += D2
D1 =(rw1/ens)
D2 =(rw2/ens)
plt.plot(D1[0],D1[1], "co--", markersize = 2, linewidth =1, label='$Levy, a = 2 $')
plt.plot(D2[0],D2[1], "gs-", markersize = 1, linewidth =1, label='$Levy, a = 3$')
plt.legend(loc = 'upper left')
plt.xlabel("$x$")
plt.ylabel("$y>$")
plt.savefig("GRW3.pdf")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
ens = 10000 #iteration number
n = 100 #number of steps
rw1 = np.zeros(n+1)
rw2 = np.zeros(n+1)
X0 = np.array([0])
for k in range(ens):
Displacement1 = np.random.zipf(2, n)
Displacement2 = np.random.zipf(3, n)
D1 = np.concatenate((X0, np.cumsum(Displacement1)))
D2 = np.concatenate((X0, np.cumsum(Displacement2)))
rw1 += D1
rw2 += D2
X1 = (rw1/ens)
X2 = (rw2/ens)
plt.plot(X1 , "cD", markersize = 1, linewidth =1, label="$Levy, a = 2 $")
plt.plot(X2 , "gs", markersize = 1, linewidth =1, label="$Levy, a = 3 $")
plt.legend( loc = "upper left")
plt.xlabel("$t$")
plt.ylabel("$<x>$")
plt.savefig("GRW4.pdf")
plt.show()
MSD: Mean Square Displacement
import numpy as np
import matplotlib.pyplot as plt
ens = 10000 #iteration number
n = 1000 #number of steps
rw1 = np.zeros(n+1)
rw2 = np.zeros(n+1)
for k in range(ens):
X0 = np.array([0])
Displacement = np.random.zipf(3, n)
D = np.concatenate((X0, np.cumsum(Displacement)))
rw1 += D
rw2 += D**2
xbar2 = (rw1/ens)**2
x2bar = (rw2/ens)
sigma2 =(rw2/ens) - (rw1/ens)**2
plt.plot(xbar2 , "bD", markersize = 1, linewidth =1, label="$<x>^2$")
plt.plot(x2bar , "rs-", markersize = 1, linewidth =1, label="$<x^2>$")
plt.plot(sigma2 , "co", markersize = 1, linewidth =1, label="$MSD= <x^2> - <x>^2$" )
plt.legend( loc = "upper left")
plt.xlabel("$t$")
plt.ylabel("$Behaviour$")
plt.savefig("GRW5.pdf")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
ens = 10000 #iteration number
n = 1000 #number of steps
rw1 = np.zeros(n+1)
rw2 = np.zeros(n+1)
for k in range(ens):
X0 = np.array([0])
Displacement1 = np.random.normal(0, 1, n)
Displacement2 = np.random.zipf(3, n)
D1 = np.concatenate((X0, np.cumsum(Displacement1)))
D2 = np.concatenate((X0, np.cumsum(Displacement2)))
rw1 += D1**2
rw2 += D2**2
sigma21 =(rw1/ens)
sigma22 =(rw2/ens)
plt.figure()
plt.plot(sigma21 , "ro", markersize = 1, linewidth =1, label='MSD of normal')
plt.legend( loc = "upper left")
plt.xlabel("$t$")
plt.ylabel("$<x^2>$")
plt.show()
plt.figure()
plt.plot(sigma22 , "gs", markersize = 1, linewidth =1, label="MSD of Levy" )
plt.legend( loc = "upper left")
plt.xlabel("$t$")
plt.ylabel("$<x^2>$")
plt.show()
plt.figure()
plt.plot(sigma21 , "ro", markersize = 1, linewidth =1, label="MSD of normal, diffusion" )
plt.plot(sigma22 , "gs", markersize = 1, linewidth =1, label="MSD of Levy, superdiffusion" )
plt.legend( loc = "upper left")
plt.xlabel("$t$")
plt.ylabel("$<x^2>$")
plt.savefig("GRW6.pdf")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
ens = 100000 #iteration number
n = 1000 #number of steps
rw1 = np.zeros(n+1)
rw2 = np.zeros(n+1)
for k in range(ens):
X0 = np.array([0])
Displacement1 = np.random.zipf(2, n)
Displacement2 = np.random.zipf(3, n)
D1 = np.concatenate((X0, np.cumsum(Displacement1)))
D2 = np.concatenate((X0, np.cumsum(Displacement2)))
rw1 += D1**2
rw2 += D2**2
sigma21 =(rw1/ens)
sigma22 =(rw2/ens)
plt.plot(sigma21 , "yD", markersize = 2, linewidth =1, label="$MSD= <x^2> a=2$" )
plt.plot(sigma22 , "cP", markersize = 2, linewidth =1, label="$MSD= <x^2> a=3$" )
plt.legend( loc = "upper left")
plt.xlabel("$t$")
plt.ylabel("$Behaviour$")
plt.show()
plt.figure()
plt.loglog(sigma21 , "yD", markersize = 2, linewidth =1, label="$MSD= <x^2> a=2$" )
plt.loglog(sigma22 , "cP", markersize = 2, linewidth =1, label="$MSD= <x^2> a=3$" )
plt.legend( loc = "upper left")
plt.xlabel("$t$")
plt.ylabel("$Behaviour$")
plt.savefig("GRW7.pdf")
plt.show()
abbascarimi@gmail.com