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_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 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()
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') plt.xlim((tMin, tMax)) plt.title("Original signal") for num in range(imfNo): plt.subplot(r,c,num+2) plt.plot(T, imfs[num], 'g')
# 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") plt.show()
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): plt.subplot(nIMFs+2, 1, n+2) plt.plot(t, eIMFs[n], 'g')