def eemd2d(img, goal, nos_wn): # 2-D EEMD, an implenmation of HHT # written by Neil Po-Nan Li @ Inst. of Physics, Academia Sinica, Taiwan # v1. 2012/10/6 # v2. 2014/3/10 bug fixes # v2.1 2014/3/17 stablity issue fixed import numpy as np from PyEMD import EEMD sz = np.shape(img) n1 = sz[0] n2 = sz[1] nimf = goal eemd = EEMD() eemd.trials = goal eemd.noise_width = nos_wn emd = eemd.EMD emd.extrema_detection = "parabol" std_img = np.std(img) img = img / std_img #% 2-D EEMD dim#1 G = np.zeros([n1, n2, nimf + 1]) for u in range(0, n1 - 1): row_modes = eemd(img[u, :], max_imf=goal) if not row_modes.all: print("error in dim 1") row_modes[np.isnan(row_modes)] = 0 tz = np.shape(row_modes) nf = tz[0] G[u, :, 0:nf] = np.transpose(row_modes) # G = Gtmp[:,:,0:nimf] #% 2-D EEMD dim#2 D = np.zeros([n1, n2, nimf + 1, nimf + 1]) for m in range(0, nimf): print('Solving mode ', m + 1, '/', nimf) # solve and store for v in range(0, n2 - 1): col_modes = eemd(G[:, v, m], max_imf=goal) if not col_modes.all: print("error in dim 2") col_modes[np.isnan(col_modes)] = 0 tz = np.shape(col_modes) nf = tz[0] D[:, v, m, 0:nf] = np.transpose(col_modes) # D = Dtmp[:,:,0:nimf,0:nimf] #% Combine modes H = np.zeros([n1, n2, nimf]) for m in range(0, nimf): for k in range(m, nimf): H[:, :, m] = H[:, :, m] + D[:, :, m, k] H[:, :, m] = H[:, :, m] + D[:, :, k, m] H[:, :, m] = H[:, :, m] - D[:, :, m, m] # for m = (goal+1):-1:1 # H(:,:,m) = sum( sum( D(:,:,m:end,m:end), 4), 3); # if m < (goal+1) # H(:,:,m) = H(:,:,m) - sum( H(:,:, (m+1):end ), 3); # end # end modes = H * std_img # return modes return G, D, H
from PyEMD import EEMD, CEEMDAN import numpy as np import pandas as pd from bokeh.plotting import figure, output_file, show df = pd.read_csv(f'training_datas/ETH-USD.csv', names=['time', 'low', 'high', 'open', 'close', 'volume']) # output to static HTML file output_file("viz/lines.html") eemd = EEMD() trials = 100 eemd.trials = trials eemd.noise_width = 0.08 #np.std(df['close'].values[300:300+(60*5)]) print(eemd.noise_width) # create a new plot with a title and axis labels p = figure(title="simple line example", x_axis_label=f"{trials}", y_axis_label='price', plot_width=1000, plot_height=1000) ''' for a in df.columns.values[1:-1]: eemd_arrays = eemd(df[a].values[300:300+(60*5)]) p.line(range(len(eemd_arrays[-1])), df[a].values[300:300+(60*5)], legend=f"{a}", line_width=2, line_color=colors[count % len(colors)]) p.line(range(len(eemd_arrays[-1])), eemd_arrays[-1] + df[a].iloc[300] - eemd_arrays[-1][0], legend=f"EEMD-{a}", line_width=2, line_color=colors[count % len(colors)]) count += 1 ''' #series = eemd(df['close'].values[300:300+(60*5)])
# S_red = S_red.astype(DTYPE) # print("Input S_infrared.dtype: " + str(S_infrared.dtype)) # print("Input S_red.dtype: " + str(S_red.dtype)) # emd.FIXE_H = 5 # emd.nbsym = 2 # emd.spline_kind = 'cubic' # emd.DTYPE = DTYPE # --------------------------------------------------------------------------------------- # 进行EMD,并且画出结果 # -------------------------------------------------------------------------------------- # emd = EMD() eemd = EEMD() eemd.trials = 50 eemd.noise_seed(12345) eemd.noise_width = 0.01 imfs1 = eemd.eemd(S=S_infrared, T=None, max_imf=-1) imfNo1 = imfs1.shape[0] imfs2 = eemd.eemd(S=S_red, T=None, max_imf=-1) imfNo2 = imfs2.shape[0] c = np.floor(np.sqrt(imfNo1 + 1)) r = np.ceil((imfNo1 + 1) / c) plt.ioff() plt.subplot(r, c, 1) plt.plot(T, S_infrared, 'r') plt.xlim((tMin, tMax)) plt.title("Original signal")