From 2d1fae2cdba0607169137523dcf7ec6d621169a7 Mon Sep 17 00:00:00 2001 From: ZhangQi <2801038431@qq.com> Date: Thu, 18 Jan 2024 11:50:12 +0800 Subject: [PATCH] Changed the way the 'embedded_sequence' package is called and modified the method of calculating the maximum Lyapunov exponent to avoid nans --- .DS_Store | Bin 0 -> 6148 bytes pyeeg/largest_lyauponov_exponent.py | 29 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..cb9aeb7b874303b88b24d3148a8b5f0ee4761bba GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO({YT3Oz1(Em&Kr6fdFH7cim+m6)`l4aRKgk3mWyXMG``#OHBl zcdORglOVJCiWqhMf!mu-2q|2v7n53zaZaz~Kj>ebOb#=#?BIlh5dY2Oa1` z0Pd2vSy)E~==<(_gqHr{>R^M1Ao7>vXTY0N!-8y}d zIAd=-8MVCOHO(%Bi2S+j`IljkxTW1w5s$qv4u&!y>;~v^a}~y2k+j4l?v7-vqc*I9 zRd7q?>9p2tRCvAFoK^U=S*up~QN1yn6|BAegOhXjK6;47v!ayY*C%C1;~ZYlSdrbM zGmIk<_t1l)w`BeSe!0Ch$@}=1d4I|1Tds3<3>pRu1Dnf$zBR4l=2BoXHw+jCRxm*K z14kvaHKq#X)q#U-0TAgoQVQDCOHd5gXlqOr;tmQ^p@=G!=@x^ja9row&(@eKRN=sM z^TG6+neI@Sd^OU zx|AH%T8?^$N>> 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