# for dense_model ssta and ha predict_data = np.empty([1, 20, 27, 2]) data_y = 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]) nino34 = [] for start_month in range( file_num - prediction_month * directly_month, file_num + month - prediction_month * directly_month + 1, interval): 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]
custom_objects={ 'mean_squared_error': mean_squared_error, 'root_mean_squared_error': root_mean_squared_error, 'mean_absolute_error': mean_absolute_error }) print(len(model.layers)) training_start = 0 all_num = 464 batch_size = 32 epochs = 200 data_preprocess_method = name_list.data_preprocess_method all_data, testing_data = file_helper_unformatted.load_sstha_for_conv2d( training_start, all_num) 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
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
# print(len(model.layers)) training_start = 0 training_num = 464 batch_size = 32 epochs = 2000 # data_preprocess_method = name_list.data_preprocess_method all_data, testing_data = file_helper_unformatted.load_sstha_for_conv2d(training_start, training_num) all_data = data_preprocess.data_preprocess(all_data, 0, data_preprocess_method) data_x, data_y = data_preprocess.sequence_data(all_data, input_length=time_step, prediction_month=prediction_month) if is_retrain: data_x = file_helper_unformatted.exchange_rows(data_x) data_y_nino = index_calculation.get_nino34_from_data_y(data_y) # print(data_y_nino) sc = np.linspace(0, 11, 12, dtype='int32') sc = np.tile(sc, int((training_num - training_start) / 12 + 1)) data_sc = sc[:(training_num - training_start - time_step + 1 - prediction_month + 1)] # all_data, testing_data = file_helper_unformatted.load_sstha_for_conv2d(training_start, all_num) # for layer in model.layers[:]: # layer.trainable = False # for layer in model.layers[6:20]: # layer.trainable = True for layer in model.layers: print(layer.trainable) adam = optimizers.Adam(learning_rate=0.00001, beta_1=0.9, beta_2=0.999, amsgrad=False) # adam = optimizers.Adam(lr=0.000005, beta_1=0.9, beta_2=0.999, epsilon=None, decay=1e-6, amsgrad=False)
# for dense_model # predict_data = np.empty([1, 540]) # predict_data[0] = file_helper.read_data(file_num) # file_helper.write_data(file_num, model.predict(predict_data)[0]) # 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 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(file_num) 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':