diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..cb9aeb7 Binary files /dev/null and b/.DS_Store differ diff --git a/pyeeg/largest_lyauponov_exponent.py b/pyeeg/largest_lyauponov_exponent.py index d5ca469..4723f22 100644 --- a/pyeeg/largest_lyauponov_exponent.py +++ b/pyeeg/largest_lyauponov_exponent.py @@ -1,4 +1,5 @@ import numpy +import numpy as np def LLE(x, tau, n, T, fs): @@ -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) @@ -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