I’m trying to obtaining lyapunov exponent through python code
(1) I have a 3D data, so used Euclid distance to gain the distance between two spots.
I wanna find nearest point against current point and get through 500 points. -> 1 array
And make a big array by concentrating these arrays.
from math import dist
ITP = 100
bigarray = pd.DataFrame(columns=range(1, ITP+1))
array = pd.DataFrame(columns=range(1, ITP+1)) #make array
for i in range(len(data_final)-ITP):
current_point = data_final[i]
min_distance = float('inf')
nearest_point = None #initiate
for j in range(len(data_final)-ITP): #find closest spot
distance = dist(current_point, data_final[j]) # Euclid distance
if i != j and distance < min_distance: #
min_distance = distance # update min_distance
nearest_point = j # update nearest_point
for k in range(ITP): # make array
array.loc[0, k+1] = dist(data_final[i+k], data_final[nearest_point+k])
bigarray = pd.concat([bigarray, array], ignore_index=True)
array = pd.DataFrame(columns=range(1, ITP+1))
(2) After that, I got every average about the 100(ITP) columns and get a log values.
import math
mean_final = [0 for i in range(ITP)]
for i in range(1, ITP+1):
mean_final[i-1] = (bigarray[i].mean())
for i in range(0, ITP) :
mean_final[i] = math.log(mean_final[i])
mean_final
Actually, by some data,
I got this kind of graph.
enter image description here
import matplotlib.pyplot as plt
rng1 = ITP
plt.subplot(1, 2, 2)
plt.plot(range(len(mean_final[0:rng1])), mean_final[0:rng1], label='Lyapunov Exponent', color='red')
plt.title('Lyapunov Exponent over Time')
plt.xlabel('Index')
plt.ylabel('Lyapunov Exponent')
plt.show()
So is this correct answer with calculating lyapunov exponent??
이다은 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2