我试图计算非常具体的时间序列数组的分形维数。
我发现了Higuchi FD算法的实现:
def hFD(a, k_max): #Higuchi FD
L = []
x = []
N = len(a)
for k in range(1,k_max):
Lk = 0
for m in range(0,k):
#we pregenerate all idxs
idxs = np.arange(1,int(np.floor((N-m)/k)),dtype=np.int32)
Lmk = np.sum(np.abs(a[m+idxs*k] - a[m+k*(idxs-1)]))
Lmk = (Lmk*(N - 1)/(((N - m)/ k)* k)) / k
Lk += Lmk
L.append(np.log(Lk/(m+1)))
x.append([np.log(1.0/ k), 1])
(p, r1, r2, s)=np.linalg.lstsq(x, L)
return p[0]
来自https://github.com/gilestrolab/pyrem/blob/master/src/pyrem/univariate.py
和Katz FD算法:
def katz(data):
n = len(data)-1
L = np.hypot(np.diff(data), 1).sum() # Sum of distances
d = np.hypot(data - data[0], np.arange(len(data))).max() # furthest distance from first point
return np.log10(n) / (np.log10(d/L) + np.log10(n))
来自https://github.com/ProjectBrain/brainbits/blob/master/katz.py
我希望两种情况下的结果都是~1,5然而得到2,2和4 ......
hFD(x,4)= 2.23965648024(此处选择k值作为示例,但结果在4-12范围内变化很大:编辑:我能够得到~1,9的结果k = 22,但这仍然没有任何意义);
katz(x)= 4.03911343057
理论上对于1D时间序列阵列来说,这是不可能的。
这里的问题是:Higuchi和Katz算法一般不适合时间序列分析,还是我在做错了什么?还有没有其他python库已经实现和无错算法来验证我的结果?
我感兴趣的数组(每个元素代表时间点t,t + 1,t + 2,...,t + N)
x = np.array([373.4413096546802, 418.58026161917803,
395.7387698762124, 416.21163042783206,
407.9812265426947, 430.2355284504048,
389.66095393296763, 442.18969320408166,
383.7448638776275, 452.8931822090381,
413.5696828065546, 434.45932712853585
,429.95212301648996, 436.67612861616215,
431.10235365546964, 418.86935850068545,
410.84902747247423, 444.4188867775925,
397.1576881118471, 451.6129904245434,
440.9181246439599, 438.9857353268666,
437.1800408012741, 460.6251405281339,
404.3208481355302, 500.0432305427639,
380.49579242696177, 467.72953450552893,
333.11328535523967, 444.1171938340972,
303.3024198243042, 453.16332062153276,
356.9697406524534, 520.0720647379901,
402.7949987727925, 536.0721418821788,
448.21609036718445, 521.9137447208354,
470.5822486372967, 534.0572029633416,
480.03741443274765, 549.2104258193126,
460.0853321729541, 561.2705350421926,
444.52689144575794, 560.0835589548401,
462.2154563472787, 559.7166600213686,
453.42374550322353, 559.0591804941763,
421.4899935529862, 540.7970410737004,
454.34364779193913, 531.6018122709779,
437.1545739076901, 522.4262260216169,
444.6017030695873, 533.3991716674865,
458.3492761150962, 513.1735160522104])
答案 0 :(得分:1)
您尝试估算hDF的阵列太短。您需要获得更长的样本或对当前的样本进行过采样,以获得至少128点的hDF和超过4000点的Katz
import scipy.signal as signal
...
x_res=signal.resample(x,128)
hfd(x_res,4)将是1.74383694265