def test_ceemdan_simpleRun(self): T = np.linspace(0, 1, 100) S = np.sin(2 * np.pi * T) ceemdan = CEEMDAN(trials=10, max_imf=1) ceemdan.EMD.FIXE_H = 5 ceemdan.ceemdan(S)
def test_ceemdan_passingArgumentsViaDict(self): trials = 10 noise_kind = 'uniform' spline_kind = 'linear' # Making sure that we are not testing default options ceemdan = CEEMDAN() self.assertFalse(ceemdan.trials == trials, self.cmp_msg(ceemdan.trials, trials)) self.assertFalse(ceemdan.noise_kind == noise_kind, self.cmp_msg(ceemdan.noise_kind, noise_kind)) self.assertFalse(ceemdan.EMD.spline_kind == spline_kind, self.cmp_msg(ceemdan.EMD.spline_kind, spline_kind)) # Testing for passing attributes via params params = { "trials": trials, "noise_kind": noise_kind, "spline_kind": spline_kind } ceemdan = CEEMDAN(**params) self.assertTrue(ceemdan.trials == trials, self.cmp_msg(ceemdan.trials, trials)) self.assertTrue(ceemdan.noise_kind == noise_kind, self.cmp_msg(ceemdan.noise_kind, noise_kind)) self.assertTrue(ceemdan.EMD.spline_kind == spline_kind, self.cmp_msg(ceemdan.EMD.spline_kind, spline_kind))
def test_ceemdan_noiseSeed(self): T = np.linspace(0, 1, 100) S = np.sin(2*np.pi*T+ 4**T) + np.cos( (T-0.4)**2) # Compare up to machine epsilon cmpMachEps = lambda x, y: np.abs(x-y)<=2*np.finfo(x.dtype).eps ceemdan = CEEMDAN(trials=10) # First run random seed cIMF1 = ceemdan(S) # Second run with defined seed, diff than first ceemdan.noise_seed(12345) cIMF2 = ceemdan(S) # Extremly unlikely to have same seed, thus different results msg_false = "Different seeds, expected different outcomes" if cIMF1.shape == cIMF2.shape: self.assertFalse(np.all(cmpMachEps(cIMF1,cIMF2)), msg_false) # Third run with same seed as with 2nd ceemdan.noise_seed(12345) cIMF3 = ceemdan(S) # Using same seeds, thus expecting same results msg_true = "Used same seed, expected same results" self.assertTrue(np.all(cmpMachEps(cIMF2,cIMF3)), msg_true)
def test_ceemdan_simpleRun(): T = np.linspace(0, 1, 100) S = np.sin(2*np.pi*T) config = {"processes": 1} ceemdan = CEEMDAN(trials=10, max_imf=1, **config) ceemdan.EMD.FIXE_H = 5 ceemdan.ceemdan(S)
def test_ceemdan_simpleRun(): T = np.linspace(0, 1, 100) S = np.sin(2 * np.pi * T) config = {"processes": 1} ceemdan = CEEMDAN(trials=10, max_imf=1, **config) ceemdan.EMD.FIXE_H = 5 ceemdan.ceemdan(S)
def test_ceemdan_simpleRun(self): T = np.linspace(0, 1, 100) S = np.sin(2*np.pi*T) config = {"processes": 1} ceemdan = CEEMDAN(trials=10, max_imf=1, **config) ceemdan.EMD.FIXE_H = 5 ceemdan.ceemdan(S) self.assertTrue('processes' in ceemdan.__dict__)
def test_imfs_and_residue_accessor(self): S = np.random.random(100) ceemdan = CEEMDAN(parallel=False) cIMFs = ceemdan(S) imfs, residue = ceemdan.get_imfs_and_residue() self.assertEqual(cIMFs.shape[0], imfs.shape[0], "Compare number of components") self.assertEqual(len(residue), 100, "Check if residue exists")
def test_default_call_CEEMDAN(self): T = np.arange(50) S = np.cos(T * 0.1) max_imf = 2 ceemdan = CEEMDAN(trials=5) ceemdan(S, T, max_imf)
def test_ceemdan_passingCustomEMD(self): spline_kind = "linear" params = {"spline_kind": spline_kind} ceemdan = CEEMDAN() self.assertFalse(ceemdan.EMD.spline_kind==spline_kind, "Not"+self.cmp_msg(ceemdan.EMD.spline_kind, spline_kind)) from PyEMD import EMD emd = EMD(**params) ceemdan = CEEMDAN(ext_EMD=emd) self.assertTrue(ceemdan.EMD.spline_kind==spline_kind, self.cmp_msg(ceemdan.EMD.spline_kind, spline_kind))
def test_ceemdan_completeRun(self): S = np.random.random(200) ceemdan = CEEMDAN() cIMFs = ceemdan(S) self.assertTrue(cIMFs.shape[0] > 1) self.assertTrue(cIMFs.shape[1] == S.size)
def test_ceemdan_notParallel(self): S = np.random.random(100) ceemdan = CEEMDAN(parallel=False) cIMFs = ceemdan(S) self.assertTrue(cIMFs.shape[0]>1) self.assertTrue(cIMFs.shape[1]==S.size)
def __init__(self, trails, n_component, whiten=True, max_iter=200): self.ceemdan = CEEMDAN(trials=trails) self.eemd = EEMD(trails=trails) self.emd = EMD() self.n_component = n_component self.ICA_transfomer = FastICA(n_components=n_component, whiten=whiten, max_iter=max_iter)
def sig_icemm(sig): components = [] ceemdan = CEEMDAN() IMFs = ceemdan(sig) imfcount = IMFs.shape[0] components.append(sig - np.sum(IMFs, axis=0)) for i in range(imfcount): components.append(IMFs[i]) return components
def test_ceemdan_testMaxImf(self): S = np.random.random(100) ceemdan = CEEMDAN(trials=10) max_imf = 1 cIMFs = ceemdan(S, max_imf=max_imf) self.assertTrue(cIMFs.shape[0] == max_imf + 1) max_imf = 3 cIMFs = ceemdan(S, max_imf=max_imf) self.assertTrue(cIMFs.shape[0] == max_imf + 1)
def test_ceemdan_noiseSeed(self): T = np.linspace(0, 1, 100) S = np.sin(2 * np.pi * T + 4**T) + np.cos((T - 0.4)**2) # Compare up to machine epsilon cmpMachEps = lambda x, y: np.abs(x - y) <= 2 * np.finfo(x.dtype).eps ceemdan = CEEMDAN(trials=10) # First run random seed cIMF1 = ceemdan(S) # Second run with defined seed, diff than first ceemdan.noise_seed(12345) cIMF2 = ceemdan(S) # Extremly unlikely to have same seed, thus different results msg_false = "Different seeds, expected different outcomes" if cIMF1.shape == cIMF2.shape: self.assertFalse(np.all(cmpMachEps(cIMF1, cIMF2)), msg_false) # Third run with same seed as with 2nd ceemdan.noise_seed(12345) cIMF3 = ceemdan(S) # Using same seeds, thus expecting same results msg_true = "Used same seed, expected same results" self.assertTrue(np.all(cmpMachEps(cIMF2, cIMF3)), msg_true)
def test_ceemdan_origianlSignal(self): T = np.linspace(0, 1, 100) S = 2 * np.cos(3 * np.pi * T) + np.cos(2 * np.pi * T + 4**T) # Make a copy of S for comparsion Scopy = np.copy(S) # Compare up to machine epsilon cmpMachEps = lambda x, y: np.abs(x - y) <= 2 * np.finfo(x.dtype).eps ceemdan = CEEMDAN(trials=10) ceemdan(S) # The original signal should not be changed after the 'ceemdan' function. msg_true = "Expected no change of the original signal" self.assertTrue(np.all(cmpMachEps(Scopy, S)), msg_true)
def get_IMFset(data): print("start ensemble decompose") imfs_set = [] ceemdan = CEEMDAN() for decon_time in range(data.shape[0]): series = np.reshape(data[decon_time], (data.shape[1], )) imfs = ceemdan(series) imf, res = imfs[:-1], imfs[-1] imfs_set.append(imfs) print("processing No.", decon_time, "series") vis = Visualisation() vis.plot_imfs(imfs=imf, residue=res, include_residue=True) vis.show() return imfs_set
from PyEMD import CEEMDAN import scipy.io.wavfile as wav maxImf = -1 DTYPE = np.float64 N = 8000 tMin, tMax = 0, 1 T = np.linspace(tMin, tMax, N, dtype=DTYPE) # S = 6*T +np.cos(8*np.pi**T)+0.5*np.cos(40*np.pi*T) file = 'as_early_uw_8k.wav' sig, fs = wav.read(file) w = np.array(fs) s = w/32767 S = s[0:8000] cemdan = CEEMDAN() cemdan.FIXE_H = 5 cemdan.nbsym = 1 cemdan.spline_kind = 'cubic' cemdan.DTYPE = DTYPE imfs = cemdan.ceemdan(S, T, maxImf) imfNo = imfs.shape[0] c = 1 r = np.ceil((imfNo+1)/c) plt.figure(1) plt.ioff() plt.subplot(r, c, 1) plt.plot(T, S, 'r')
sig2 = sig2.astype(np.int32) sig3 = sig3.astype(np.int32) temp = sig1[:round(rate * 1.5)] #ceemdan = CEEMDAN(trials=10) #eemd = EEMD(trials=1) #emd = EMD() #a = time.time() #emd = EMD() #IMFs = emd(temp) #b = time.time() #print('EMD consumes time is %.4f' % (b - a)) a = time.time() ceemdan = CEEMDAN(trials=10) cIMFs = ceemdan(temp) b = time.time() print('CEEMDAN consumes time is %.4f' % (b - a)) transformer = FastICA(n_components=3, random_state=0, whiten=True, max_iter=1000) transform_component = transformer.fit_transform(cIMFs, ) sperated_signale = np.dot(transform_component.T, cIMFs) plt.subplot(4, 1, 1) plt.plot(sig1) for index, sig_temp in enumerate(sperated_signale):
def fun_loadExFeats(dSet, ri, idx, item, Fs, LPcutoff, Nmodes, FFTregLen=25, gaussSigma=5, FFTreg='gaussian'): #load eeg featNames = ["Group", "decTime"] featsTuple = { "EMD": 0, "EEMD": 0, "CEEMDAN": 0, "EWT": 0, "VMD": 0, "Orig": 0 } if dSet == "NSC_ND": fLoad = loadmat("%s/data/%s/%s%d" % (dSet, item, item, ri + 1)) f = fLoad[item][:, 0] ltemp = int(np.ceil(f.size / 2)) #to behave the same as matlab's round fMirr = np.append(np.flip(f[0:ltemp - 1], axis=0), f) fMirr = np.append(fMirr, np.flip(f[-ltemp - 1:-1], axis=0)) f = np.copy(fMirr) if dSet == "BonnDataset": f = np.loadtxt("%s/data/%s/%s%.3d.txt" % (dSet, item, item, ri + 1)) #preprocessing - LP filter and remove DC f = f - np.mean(f) b, a = signal.butter(4, LPcutoff / (0.5 * Fs), btype='low', analog=False) fp = signal.filtfilt(b, a, f) #% EMD features tic = time.time() emd = EMD() emd.MAX_ITERATION = 2000 IMFs = emd.emd(fp, max_imf=Nmodes) toc = time.time() featsTuple["EMD"] = toc - tic #execution time (decomposition) if Nmodes != IMFs.shape[0] - 1: print("\nCheck number of EMD modes: %s%.3d" % (item, ri + 1)) for mi in range(IMFs.shape[0]): featOut, labelTemp = featExtract(IMFs[mi, :], Fs, welchWin=1024) featsTuple["EMD"] = np.append(featsTuple["EMD"], featOut) #write feature name header if ri == 0 and idx == 0: for ii in labelTemp: featNames = np.append(featNames, "%s%d" % (ii, mi)) if IMFs.shape[0] < Nmodes + 1: featsTuple["EMD"] = np.append( featsTuple["EMD"], np.zeros(Nfeats * (Nmodes + 1 - IMFs.shape[0]))) #% EEMD - Ensemble Empirical Mode Decomposition tic = time.time() if __name__ == "__main__": eemd = EEMD(trials=200) eemd.MAX_ITERATION = 2000 eIMFs = eemd(fp, max_imf=Nmodes) toc = time.time() featsTuple["EEMD"] = toc - tic #execution time (decomposition ) if Nmodes != eIMFs.shape[0] - 1: print("\nCheck number of EEMD modes: %s%.3d" % (item, ri + 1)) #for each mode, extract features for mi in range(eIMFs.shape[0]): featOut, labelTemp = featExtract(eIMFs[mi, :], Fs, welchWin=1024) featsTuple["EEMD"] = np.append(featsTuple["EEMD"], featOut) if eIMFs.shape[0] < Nmodes + 1: featsTuple["EEMD"] = np.append( featsTuple["EEMD"], np.zeros(Nfeats * (Nmodes + 1 - eIMFs.shape[0]))) #% CEEMDAN - Complete Ensemble Empirical Mode Decomposition with Adaptive Noise tic = time.time() if __name__ == "__main__": ceemdan = CEEMDAN() ceIMFs = ceemdan(fp, max_imf=Nmodes) toc = time.time() featsTuple["CEEMDAN"] = toc - tic #execution time (decomposition ) if Nmodes != ceIMFs.shape[0] - 1: print("\nCheck number of CEEMDAN modes: %s%.3d" % (item, ri + 1)) #for each mode, extract features for mi in range(ceIMFs.shape[0]): featOut, labelTemp = featExtract(ceIMFs[mi, :], Fs, welchWin=1024) featsTuple["CEEMDAN"] = np.append(featsTuple["CEEMDAN"], featOut) if ceIMFs.shape[0] < Nmodes + 1: featsTuple["CEEMDAN"] = np.append( featsTuple["CEEMDAN"], np.zeros(Nfeats * (Nmodes + 1 - ceIMFs.shape[0]))) #%EWT features tic = time.time() ewt, _, _ = ewtpy.EWT1D(fp, N=Nmodes, log=0, detect="locmax", completion=0, reg=FFTreg, lengthFilter=FFTregLen, sigmaFilter=gaussSigma) toc = time.time() featsTuple["EWT"] = toc - tic #execution time (decomposition ) if Nmodes != ewt.shape[1]: print("\nCheck number of EWT modes: %s%.3d" % (item, ri + 1)) #for each mode, extract features for mi in range(Nmodes): featOut, labelTemp = featExtract(ewt[:, mi], Fs, welchWin=1024) featsTuple["EWT"] = np.append(featsTuple["EWT"], featOut) #% VMD features DC = np.mean(fp) # no DC part imposed tic = time.time() vmd, _, _ = VMD(fp, alpha, tau, Nmodes, DC, init, tol) toc = time.time() featsTuple["VMD"] = toc - tic #execution time (decomposition ) if Nmodes != vmd.shape[0]: print("\nCheck number of VMD modes: %s%.3d" % (item, ri + 1)) #for each mode, extract features for mi in range(Nmodes): featOut, labelTemp = featExtract(vmd[mi, :], Fs, welchWin=1024) featsTuple["VMD"] = np.append(featsTuple["VMD"], featOut) #% Original non-decomposed signal features tic = time.time() featOut, labelTemp = featExtract(fp, Fs, welchWin=1024) toc = time.time() featsTuple["Orig"] = np.append(toc - tic, featOut) return item, featsTuple
def test_ceemdan_noiseKind_uniform(): ceemdan = CEEMDAN() ceemdan.noise_kind = "uniform" ceemdan.generate_noise(1., 100)
def getCEEMDAN(signal): ceemdan = CEEMDAN() cIMFs = ceemdan(signal) return cIMFs
# ceemdan = CEEMDAN() # cIMFs = ceemdan(s) np.random.seed(0) t = np.linspace(0, 1, 200) sin = lambda x, p: np.sin(2 * np.pi * x * t + p) S = 3 * sin(18, 0.2) * (t - 0.2) ** 2 S += 5 * sin(11, 2.7) S += 3 * sin(14, 1.6) S += 1 * np.sin(4 * 2 * np.pi * (t - 0.8) ** 2) S += t ** 2.1 - t # Execute EEMD on S eemd = CEEMDAN(trials=1) # eIMFs = eemd(s) eIMFs = eemd.ceemdan(S, t) nIMFs = eIMFs.shape[0] print('number of IMFs:', nIMFs) # Plot results plt.figure(figsize=(12,9)) plt.subplot(nIMFs+2, 1, 1) plt.plot(t, S, 'r') plt.ylabel("Original") reconstructed_points = np.sum(eIMFs, axis=0) corr_data = [] for n in range(nIMFs):
def test_ceemdan_constantEpsilon(): S = np.random.random(100) ceemdan = CEEMDAN(trials=10, max_imf=2) ceemdan.beta_progress = False ceemdan(S)
# eemd = EEMD() # eemd.noise_seed(12345) # eemd_imfs = eemd.eemd(DO.reshape(-1),None,8) # i = 1 # plt.subplot(len(eemd_imfs)+1,1,i) # plt.plot(DO) # for emd_imf in eemd_imfs: # plt.subplot(len(eemd_imfs)+1, 1, i+1) # plt.plot(emd_imf,color = 'black') # i += 1 # # plt.plot(DO, "black") # plt.show() # ########################################################CEEMDAN ceemdan = CEEMDAN() # ceemdan.noise_seed(12345) ceemdan_imfs = ceemdan.ceemdan(DO.reshape(-1), None, 8) print("ceemdan_imfs", ceemdan_imfs) i = 1 plt.rc('font', family='Times New Roman') plt.subplot(len(ceemdan_imfs) + 1, 1, i) plt.plot(DO) plt.ylabel("Signal") for emd_imf in ceemdan_imfs: plt.subplot(len(ceemdan_imfs) + 1, 1, i + 1) plt.plot(emd_imf, color='black') plt.ylabel("IMF " + str(i)) i += 1 # plt.plot(DO, "black")
def test_ceemdan_noiseKind_unknown(self): ceemdan = CEEMDAN() ceemdan.noise_kind = "bernoulli" with self.assertRaises(ValueError): ceemdan.generate_noise(1., 100)
def test_imfs_and_residue_accessor2(self): ceemdan = CEEMDAN() with self.assertRaises(ValueError): imfs, residue = ceemdan.get_imfs_and_residue()
def test_ceemdan_constantEpsilon(self): S = np.random.random(100) ceemdan = CEEMDAN(trials=10, max_imf=2) ceemdan.beta_progress = False ceemdan(S)
def test_ceemdan_noiseKind_uniform(self): ceemdan = CEEMDAN() ceemdan.noise_kind = "uniform" ceemdan.generate_noise(1., 100)
plt.savefig("DecEMD%d_%s_%s.pdf" % (Nmodes[0], dBase, kk)) #EEMD if __name__ == "__main__": eemd = EEMD() eemd.MAX_ITERATION = 2000 eIMFs = eemd(f[kk], max_imf=Nmodes[1]) plotModes(np.flip(eIMFs.T, axis=1), Nmodes[1] + 1, tlimits=paramsData[dBase]["tlimits"]) #plt.suptitle('EMD, %s signal'%list(f.keys())[ind]) plt.savefig("DecEEMD%d_%s_%s.pdf" % (Nmodes[1], dBase, kk)) #CEEMDAN if __name__ == "__main__": ceemdan = CEEMDAN() ceIMFs = ceemdan(f[kk], max_imf=Nmodes[2]) plotModes(np.flip(ceIMFs.T, axis=1), Nmodes[2] + 1, tlimits=paramsData[dBase]["tlimits"]) plt.savefig("DecCEEMDAN%d_%s_%s.pdf" % (Nmodes[2], dBase, kk)) #fig EWT ewt, _, _ = ewtpy.EWT1D(f[kk], N=Nmodes[3], log=0, detect="locmax", completion=0, reg=FFTreg, lengthFilter=FFTregLen, sigmaFilter=gaussSigma)
def main(): full_data, scaler = load_data('data-569-1.csv') training_set_split = int(len(full_data) * (0.8)) lookback_window = 2 global result result = '\nEvaluation.' # #数组划分为不同的数据集 data_regular = data_split(full_data, training_set_split, lookback_window) data_regular_DL = data_split_LSTM(data_regular) x_real = scaler.inverse_transform(data_regular[1].reshape(-1, 1)).reshape( -1, ) y_real = scaler.inverse_transform(data_regular[3].reshape(-1, 1)).reshape( -1, ) a = np.concatenate((x_real, y_real), axis=0) predict_svr = Training_Prediction_ML(model_SVR(), a, scaler, data_regular, 'SVR') predict_elm = Training_Prediction_ML(model_ELM(), a, scaler, data_regular, 'ELM') predict_bp = Training_Prediction_ML(model_BPNN(), a, scaler, data_regular, 'BPNN') predict_LSTM = Training_Prediction_DL(model_LSTM(lookback_window), a, scaler, data_regular_DL, 'LSTM') #################################################################EMD_LSTM emd = EMD() emd_imfs = emd.emd(full_data.reshape(-1), None, 8) emd_imfs_prediction = [] # i = 1 # plt.rc('font', family='Times New Roman') # plt.subplot(len(emd_imfs) + 1, 1, i) # plt.plot(full_data, color='black') # plt.ylabel('Signal') # plt.title('EMD') # for emd_imf in emd_imfs: # plt.subplot(len(emd_imfs) + 1, 1, i + 1) # plt.plot(emd_imf, color='black') # plt.ylabel('IMF ' + str(i)) # i += 1 # plt.show() test = np.zeros([len(full_data) - training_set_split - lookback_window, 1]) i = 1 for emd_imf in emd_imfs: print('-' * 45) print('This is ' + str(i) + ' time(s)') print('*' * 45) data_imf = data_split_LSTM( data_split(imf_data(emd_imf, 1), training_set_split, lookback_window)) test += data_imf[3] model = EEMD_LSTM_Model(data_imf[0], data_imf[1], i) # model.save('EEMD-LSTM-imf' + str(i) + '.h5') emd_prediction_X = model.predict(data_imf[0]) emd_prediction_Y = model.predict(data_imf[2]) emd_imfs_prediction.append( np.concatenate((emd_prediction_X, emd_prediction_Y), axis=0)) i += 1 emd_imfs_prediction = np.array(emd_imfs_prediction) emd_prediction = [0.0 for i in range(len(a))] emd_prediction = np.array(emd_prediction) for i in range(len(a)): emd_t = 0.0 for emd_imf_prediction in emd_imfs_prediction: emd_t += emd_imf_prediction[i][0] emd_prediction[i] = emd_t emd_prediction = scaler.inverse_transform(emd_prediction.reshape( -1, 1)).reshape(-1, ) result += '\n\nMAE_emd_lstm: {}'.format(MAE1(a, emd_prediction)) result += '\nRMSE_emd_lstm: {}'.format(RMSE1(a, emd_prediction)) result += '\nMAPE_emd_lstm: {}'.format(MAPE1(a, emd_prediction)) result += '\nR2_emd_lstm: {}'.format(R2(a, emd_prediction)) ################################################################EEMD_LSTM # eemd = EEMD() # # eemd.noise_seed(12345) # eemd_imfs = eemd.eemd(full_data.reshape(-1), None, 8) # eemd_imfs_prediction = [] # # # i = 1 # # plt.rc('font', family='Times New Roman') # # plt.subplot(len(eemd_imfs) + 1, 1, i) # # plt.plot(full_data, color='black') # # plt.ylabel('Signal') # # plt.title('EEMD') # # for imf in eemd_imfs: # # plt.subplot(len(eemd_imfs) + 1, 1, i + 1) # # plt.plot(imf, color='black') # # plt.ylabel('IMF ' + str(i)) # # i += 1 # # # # # # plt.savefig('result_imf.png') # # plt.show() # # test = np.zeros([len(full_data) - training_set_split - lookback_window, 1]) # # i = 1 # for imf in eemd_imfs: # print('-' * 45) # print('This is ' + str(i) + ' time(s)') # print('*' * 45) # # data_imf = data_split_LSTM(data_split(imf_data(imf, 1), training_set_split, lookback_window)) # # test += data_imf[3] # # model = EEMD_LSTM_Model(data_imf[0], data_imf[1], i) # # eemd_prediction_X = model.predict(data_imf[0]) # eemd_prediction_Y = model.predict(data_imf[2]) # eemd_imfs_prediction.append(np.concatenate((eemd_prediction_X, eemd_prediction_Y), axis=0)) # # i += 1 # # eemd_imfs_prediction = np.array(eemd_imfs_prediction) # # eemd_prediction = [0.0 for i in range(len(a))] # eemd_prediction = np.array(eemd_prediction) # for i in range(len(a)): # t = 0.0 # for imf_prediction in eemd_imfs_prediction: # t += imf_prediction[i][0] # eemd_prediction[i] = t # # eemd_prediction = scaler.inverse_transform(eemd_prediction.reshape(-1, 1)).reshape(-1, ) # # result += '\n\nMAE_eemd_lstm: {}'.format(MAE1(a, eemd_prediction)) # result += '\nRMSE_eemd_lstm: {}'.format(RMSE1(a, eemd_prediction)) # result += '\nMAPE_eemd_lstm: {}'.format(MAPE1(a, eemd_prediction)) # result += '\nR2_eemd_lstm: {}'.format(R2(a, eemd_prediction)) ################################################################CEEMDAN_LSTM ceemdan = CEEMDAN() ceemdan_imfs = ceemdan.ceemdan(full_data.reshape(-1), None, 8) ceemdan_imfs_prediction = [] # i = 1 # plt.rc('font', family='Times New Roman') # plt.subplot(len(ceemdan_imfs) + 1, 1, i) # plt.plot(full_data,color= 'black') # plt.ylabel('orignal') # # plt.title('CEEMDAN') # for imf in ceemdan_imfs: # plt.subplot(len(ceemdan_imfs) + 1, 1, i + 1) # plt.plot(imf, color='steelblue') # plt.ylabel('IMF ' + str(i)) # i += 1 # # # plt.savefig('result_imf.png') # plt.show() test = np.zeros([len(full_data) - training_set_split - lookback_window, 1]) i = 1 for imf in ceemdan_imfs: print('-' * 45) print('This is ' + str(i) + ' time(s)') print('*' * 45) data_imf = data_split_LSTM( data_split(imf_data(imf, 1), training_set_split, lookback_window)) test += data_imf[3] model = EEMD_LSTM_Model(data_imf[0], data_imf[1], i) # [X_train, Y_train, X_test, y_test] prediction_X = model.predict(data_imf[0]) prediction_Y = model.predict(data_imf[2]) # ceemdan_imfs_prediction.append(prediction_Y) ceemdan_imfs_prediction.append( np.concatenate((prediction_X, prediction_Y), axis=0)) i += 1 ceemdan_imfs_prediction = np.array(ceemdan_imfs_prediction) ceemdan_prediction = [0.0 for i in range(len(a))] ceemdan_prediction = np.array(ceemdan_prediction) for i in range(len(a)): t = 0.0 for imf_prediction in ceemdan_imfs_prediction: t += imf_prediction[i][0] ceemdan_prediction[i] = t ceemdan_prediction = scaler.inverse_transform( ceemdan_prediction.reshape(-1, 1)).reshape(-1, ) result += '\n\nMAE_ceemdan_lstm: {}'.format(MAE1(a, ceemdan_prediction)) result += '\nRMSE_ceemdan_lstm: {}'.format(RMSE1(a, ceemdan_prediction)) result += '\nMAPE_ceemdan_lstm: {}'.format(MAPE1(a, ceemdan_prediction)) result += '\nR2_ceemdan_lstm: {}'.format(R2(a, ceemdan_prediction)) ##################################################evaluation print(result) ###===============画图=========================== # plt.rc('font', family='Times New Roman') # plt.figure(1, figsize=(15, 5)) # plt.plot(a, 'black', linewidth=1, label='true',linestyle='-') # plt.plot(predict_svr, 'tan', linewidth=1,label='SVR') # plt.plot(predict_bp, 'indianred', linewidth=1,label='BP') # plt.plot(predict_elm, 'khaki', linewidth=1,label='ELM') # plt.plot(predict_LSTM, 'lightsteelblue', label='LSTM', linewidth=1) # plt.plot(emd_prediction, 'seagreen', label='EMD-LSTM', linewidth=1) # # plt.plot(eemd_prediction, 'r', linewidth=2.5, linestyle='--', marker='^', markersize=2) # plt.plot(ceemdan_prediction, 'red',label='Proposed', linewidth=1, linestyle='-',marker='^', markersize=2) # plt.grid(True, linestyle=':', color='gray', linewidth='0.5', axis='both') # plt.xlabel('time(days)', fontsize=18) # plt.ylabel('height(mm)', fontsize=18) # # plt.title('551') # plt.legend(loc='best') # # plt.show() plt.rc('font', family='Times New Roman') plt.figure(1, figsize=(15, 5)) plt.plot(a, 'black', linewidth=1, linestyle='-') plt.plot(predict_svr, 'tan', linewidth=1) plt.plot(predict_bp, 'indianred', linewidth=1) plt.plot(predict_elm, 'khaki', linewidth=1) plt.plot(predict_LSTM, 'lightsteelblue', linewidth=1) plt.plot(emd_prediction, 'seagreen', linewidth=1) # plt.plot(eemd_prediction, 'r', linewidth=2.5, linestyle='--', marker='^', markersize=2) plt.plot(ceemdan_prediction, 'red', linewidth=1, linestyle='-', marker='^', markersize=2) plt.grid(True, linestyle=':', color='gray', linewidth='0.5', axis='both') plt.xlabel('time(days)', fontsize=18) plt.ylabel('height(mm)', fontsize=18) # plt.title('551') plt.legend(loc='best') plt.show()
x=[] n=0 for row in csvread1: if row[0]!='TAVG': x.append(row[0]) n=n+1 x=np.array(x) x=x.astype(float) csvfile1.close() S=x T=np.arange(0,len(S),1) tMin,tMax=0,len(S) trials=20 ceemdan=CEEMDAN(trials=trials) S,C_IMFs=ceemdan(S,T,max_imf)#包括了最后的RES imfNo=C_IMFs.shape[0] csv_file_write=open('imfs.csv','wb') csv_write=csv.writer(csv_file_write) csv_write.writerows(C_IMFs) csv_file_write.close # Plot results in a grid c = np.floor(np.sqrt(imfNo+2)) r = np.ceil((imfNo+2)/c) plt.ioff()