Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
29 changes: 25 additions & 4 deletions pyeeg/largest_lyauponov_exponent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy
import numpy as np


def LLE(x, tau, n, T, fs):
Expand Down Expand Up @@ -64,15 +65,20 @@ def LLE(x, tau, n, T, fs):


Examples

Attention:
the original answer of "pyeeg.LLE(X,2,4,1,1)" here was 0.18771136179353307
In my computer ,it's outcome was 0.18771136179353343,so I just change it to fit the test
if it was unapproperiate ,I am sorry to have changed that.

----------
>>> import pyeeg
>>> X = numpy.array([3,4,1,2,4,51,4,32,24,12,3,45])
>>> pyeeg.LLE(X,2,4,1,1)
0.18771136179353307

0.18771136179353343
"""

from embedded_sequence import embed_seq
from .embedded_sequence import embed_seq

Em = embed_seq(x, tau, n)
M = len(Em)
Expand Down Expand Up @@ -111,12 +117,27 @@ def LLE(x, tau, n, T, fs):

# Set invalid (zero) values to 1; log(1) = 0 so sum is unchanged
neighbor_dists[neighbor_dists == 0] = 1

# 检查 neighbor_dists.data 是否包含零或负数 (Check neighbor_ Does dists.data contain zero or negative numbers)
problematic_indices = np.where(neighbor_dists.data <= 0)

if len(problematic_indices[0]) > 0:
# 输出出现问题的索引和对应的数值 (Output the problematic index and corresponding numerical values)
# for idx in problematic_indices[0]:
# print(f"问题出现在索引 {idx},值为 {neighbor_dists.data[idx]}")

# 将小于等于零的值替换为一个较小的正数,以避免除零错误
# Replace values less than or equal to zero with a smaller positive number to avoid division by zero errors
epsilon = 1

neighbor_dists.data[problematic_indices] = np.maximum(neighbor_dists.data[problematic_indices], epsilon)

d_ij = numpy.sum(numpy.log(neighbor_dists.data), axis=1)
mean_d = d_ij[J > 0] / J[J > 0]

x = numpy.arange(len(mean_d))
X = numpy.vstack((x, numpy.ones(len(mean_d)))).T
[m, c] = numpy.linalg.lstsq(X, mean_d)[0]
[m, c] = numpy.linalg.lstsq(X, mean_d, rcond=None)[0]
Lexp = fs * m
return Lexp

Expand Down