elif model_type == 'dense': data_x = np.empty([1, 1080]) for start_month in range(file_num, file_num + month - interval, interval): predict_data[0] = file_helper_unformatted.read_data_sstaha(start_month) nino34 = [index_calculation.get_nino34(predict_data[0])] # data preprocess z-zero if data_preprocess_method == 'preprocess_Z': predict_data = data_preprocess.preprocess_Z(predict_data, 0) # data preprocess dimensionless if data_preprocess_method == 'dimensionless': redict_data = data_preprocess.dimensionless(predict_data, 0) # data preprocess 0-1 if data_preprocess_method == 'preprocess_01': predict_data = data_preprocess.preprocess_01(predict_data, 0) # data preprocess no month mean if data_preprocess_method == 'nomonthmean': predict_data = data_preprocess.no_month_mean(predict_data, 0) if model_type == 'conv': data_x[0] = predict_data[0] elif model_type == 'dense': data_x[0] = np.reshape(predict_data[0], (1, 1080)) for i in range(prediction_month): if is_seasonal_circle: data_sc[0] = [(start_month+i) % 12] data_x = model.predict([data_x, data_sc]) else: data_x = model.predict(data_x)
mean_absolute_error, mean_squared_error ]) # to train model # the data for training is ssta and ha training_data, testing_data = file_helper_unformatted.load_sstha_for_conv2d( training_start, training_num) # data preprocess z-zero if data_preprocess_method == 'preprocess_Z': training_data = data_preprocess.preprocess_Z(training_data, 0) # data preprocess dimensionless if data_preprocess_method == 'dimensionless': training_data = data_preprocess.dimensionless(training_data, 0) # data preprocess 0-1 if data_preprocess_method == 'preprocess_01': training_data = data_preprocess.preprocess_01(training_data, 0) # data preprocess no month mean if data_preprocess_method == 'nomonthmean': training_data = data_preprocess.no_month_mean(training_data, 0) data_x = training_data[:-1] data_y = training_data[1:] # tesorboard = TensorBoard('..\..\model\\tensorboard\\' + model_name) save_best = ModelCheckpoint('..\..\model\\best\\' + model_name + '@' + 'best.h5', monitor='val_root_mean_squared_error', verbose=1, save_best_only=True, mode='min', period=1) train_hist = model.fit(data_x,
if is_retrain: all_data = file_helper_unformatted.exchange_rows(all_data) if is_seasonal_circle: sc = np.linspace(0, 11, 12, dtype='int32') sc = np.tile(sc, int((all_num - training_start) / 12 + 1)) data_sc = sc[:(all_num - training_start)] # data preprocess z-zero if data_preprocess_method == 'preprocess_Z': all_data = data_preprocess.preprocess_Z(all_data, 0) # data preprocess dimensionless if data_preprocess_method == 'dimensionless': all_data = data_preprocess.dimensionless(all_data, 0) # data preprocess 0-1 if data_preprocess_method == 'preprocess_01': all_data = data_preprocess.preprocess_01(all_data, 0) # data preprocess no month mean if data_preprocess_method == 'nomonthmean': all_data = data_preprocess.no_month_mean(all_data, 0) if model_type == 'conv': data_x = all_data[:-1] data_y = all_data[1:] elif model_type == 'dense': data_x = np.reshape(all_data[:-1], (all_num, 1080)) data_y = np.reshape(all_data[1:], (all_num, 1080)) # for layer in model.layers[:]: # layer.trainable = False # for layer in model.layers[6:20]: # layer.trainable = True
def calculate_12_month(start_month): # for dense_model ssta and ha predict_data = np.empty([1, 20, 27, 2]) data_y = np.empty([1, 20, 27, 2]) data_realistic = np.empty([1, 20, 27, 2]) if is_seasonal_circle: data_sc = np.empty([1, 1], dtype='int32') if model_type == 'conv': data_x = np.empty([1, 20, 27, 2]) else: data_x = np.empty([1, 1080]) predict_data[0] = file_helper_unformatted.read_data_sstaha(start_month) if is_retrain: predict_data = file_helper_unformatted.exchange_rows(predict_data) # data preprocess z-zero if data_preprocess_method == 'preprocess_Z': predict_data = data_preprocess.preprocess_Z(predict_data, 0) # data preprocess dimensionless if data_preprocess_method == 'dimensionless': redict_data = data_preprocess.dimensionless(predict_data, 0) # data preprocess 0-1 if data_preprocess_method == 'preprocess_01': predict_data = data_preprocess.preprocess_01(predict_data, 0) # data preprocess no month mean if data_preprocess_method == 'nomonthmean': predict_data = data_preprocess.no_month_mean(predict_data, 0) if model_type == 'conv': data_x[0] = predict_data[0] else: data_x[0] = np.reshape(predict_data[0], (1, 1080)) ssta_error = np.empty([directly_month]) for i in range(directly_month): if is_seasonal_circle: data_sc[0] = [(start_month + i) % 12] data_x = model.predict([data_x, data_sc]) else: data_x = model.predict(data_x) if model_type == 'conv': data_y[0] = data_x[0] else: data_y[0] = np.reshape(data_x[0], (20, 27, 2)) # data preprocess z-zero if data_preprocess_method == 'preprocess_Z': data_y = data_preprocess.preprocess_Z(data_y, 1) # data preprocess dimensionless if data_preprocess_method == 'dimensionless': data_y = data_preprocess.dimensionless(data_y, 1) # data preprocess 0-1 if data_preprocess_method == 'preprocess_01': data_y = data_preprocess.preprocess_01(data_y, 1) # data preprocess no month mean if data_preprocess_method == 'nomonthmean': data_y = data_preprocess.no_month_mean(data_y, 1) data_realistic[0] = file_helper_unformatted.read_data_sstaha( start_month + i + 1) if is_retrain: data_realistic = file_helper_unformatted.exchange_rows( data_realistic) # ssta_error[i] = calculate_error(data_y[0], data_realistic[0]) ssta_error[i] = math_tool.calculate_rmse(data_y[0], data_realistic[0]) print(ssta_error) ssta_error2 = ssta_error.copy() for i in range(1, directly_month): ssta_error2[i] = (ssta_error[i] - ssta_error[i - 1]) / 10000 ssta_error2[0] = ssta_error2[0] / 10000 return ssta_error2