From 62892ae0f0bcb3cf722ba8c391dc78361b2edabf Mon Sep 17 00:00:00 2001 From: sanginnwoo Date: Fri, 21 Oct 2022 12:58:10 +0900 Subject: [PATCH] From the mac --- batch_process.py | 73 +++++++++++++++++---------------- error_analysis.py | 14 ++++++- settle_prediction_steps_main.py | 20 ++++----- 3 files changed, 60 insertions(+), 47 deletions(-) diff --git a/batch_process.py b/batch_process.py index 8a92e61..666147d 100644 --- a/batch_process.py +++ b/batch_process.py @@ -2,51 +2,52 @@ import settle_prediction_steps_main import pandas as pd import os -input_dir = 'data_1' -output_dir = 'output_1' +# 입력 파일이 있는 폴더명 지정: 사용자 직접 지정 필요 +input_dir = 'data' + +# 침하 예측 결과 파일을 저장할 폴더명 지정: 사용자 직접 지정 필요 +output_dir = 'output' + +# 에러 분석 결과 파일을 저장할 폴더명 지정: 사용자 직접 지정 필요 +output_error = 'error' + +# 입력 파일의 이름을 저장할 리스트 초기화 input_files = [] -df_overall = pd.DataFrame(columns=['File', 'Data_usage', - 'RMSE_hyper_original', - 'RMSE_hyper_nonlinear', - 'Final_error_hyper_original', - 'Final_error_hyper_nonlinear']) +# 일단 및 다단 성토를 포함한 예측의 에러를 저장할 데이터프레임 초기화 +df_overall = pd.DataFrame(columns=['File', 'Data_usage', 'RMSE_hyper_original', 'RMSE_hyper_nonlinear', + 'Final_error_hyper_original', 'Final_error_hyper_nonlinear']) -df_multi_step = pd.DataFrame(columns=['File', 'Data_usage', - 'RMSE_hyper_original', - 'RMSE_hyper_nonlinear', - 'RMSE_step', - 'Final_error_hyper_original', - 'Final_error_hyper_nonlinear', - 'Final_error_step']) +# 다단 성토만의 예측의 에러를 저장할 데이터프레임 초기화 +df_multi_step = pd.DataFrame(columns=['File', 'Data_usage', 'RMSE_hyper_original', 'RMSE_hyper_nonlinear', 'RMSE_step', + 'Final_error_hyper_original', 'Final_error_hyper_nonlinear', 'Final_error_step']) +# 입력 파일 저장 폴더에서 입력 파일의 이름을 파악하여 배열에 저장 +for (root, directories, files) in os.walk(input_dir): # 입력 파일 안의 모든 파일에 대해서 + for file in files: # 모든 파일 중 하나의 파일에 대해서 + file_path = os.path.join(root, file) # 파일 경로를 포함한 파일명 설정 + input_files.append(file_path) # 파일명을 배열에 저장 -for (root, directories, files) in os.walk(input_dir): - for file in files: - file_path = os.path.join(root, file) - input_files.append(file_path) - +# 입력 파일명 저장소의 파일 하나에 대해서 예측을 수행하고, 결과값으로 잔차값을 받아서 저장 for input_file in input_files: + + # 최종 성토 이후 데이터 사용 영역에 대해서 [20 30 40 50 60 70 80 90] for i in range(20, 100, 10): - RETURN_VALUES = settle_prediction_steps_main.\ + # 침하 예측을 수행하고 반환값 저장 + return_values = settle_prediction_steps_main.\ run_settle_prediction(input_file, output_dir, i, 100, False, False) - df_overall.loc[len(df_overall.index)] = [input_file, i, - RETURN_VALUES[0], - RETURN_VALUES[1], - RETURN_VALUES[3], - RETURN_VALUES[4]] + # 데이터프레임에 일단 및 다단 성토를 포함한 예측의 에러를 저장 + df_overall.loc[len(df_overall.index)] = [input_file, i, return_values[0], return_values[1], + return_values[3], return_values[4]] - if RETURN_VALUES[6]: - df_multi_step.loc[len(df_overall.index)] = [input_file, i, - RETURN_VALUES[0], - RETURN_VALUES[1], - RETURN_VALUES[2], - RETURN_VALUES[3], - RETURN_VALUES[4], - RETURN_VALUES[5]] + # 데이터프레임에 다단 성토만에 대한 예측의 에러를 저장 + if return_values[6]: + df_multi_step.loc[len(df_multi_step.index)] = [input_file, i, return_values[0], return_values[1], + return_values[2], return_values[3], + return_values[4], return_values[5]] -# 에러 파일 출력 -df_overall.to_csv('Error_overall.csv') -df_multi_step.to_csv('Error_multi_step.csv') +# 에러 파일을 출력 +df_overall.to_csv(output_error + '/error_overall.csv') +df_multi_step.to_csv(output_error + 'error_multi_step.csv') diff --git a/error_analysis.py b/error_analysis.py index 7fe4eca..12c3a53 100644 --- a/error_analysis.py +++ b/error_analysis.py @@ -11,7 +11,7 @@ import matplotlib.pyplot as plt ''' # CSV 파일 읽기 (일단, 다단 성토 포함) -df_overall = pd.read_csv('Error_overall.csv', encoding='euc-kr') +df_overall = pd.read_csv('error_overall.csv', encoding='euc-kr') # 통계량 저장소 statistics 초기화 statistic =[] @@ -23,6 +23,9 @@ statistic =[] # FE (O) # FE (NL) +# 카운트 초기화 +count = 0 + # 최종 성토 단계에서 각 침하 데이터 사용 영역에 대해서 다음을 수행 for data_usage in range(20, 100, 10): @@ -83,6 +86,9 @@ for data_usage in range(20, 100, 10): plt.savefig('error_analysis/error_nonstep(%i percent).png' % data_usage, bbox_inches='tight') + # 카운트 증가 + count = count + 1 + # 데이터 사용 영역 설정 data_usages = range(20, 100, 10) @@ -163,6 +169,9 @@ statistic_step =[] # FE (NL) # FE (S) +# 카운트 초기화 +count = 0 + # 최종 성토 단계에서 각 침하 데이터 사용 영역에 대해서 다음을 수행 for data_usage in range(20, 100, 10): @@ -239,6 +248,9 @@ for data_usage in range(20, 100, 10): plt.savefig('error_analysis/error_step(%i percent).png' % data_usage, bbox_inches='tight') + # 카운트 증가 + count = count + 1 + # 데이터 사용 영역 배열 설정 data_usages = range(20, 100, 10) diff --git a/settle_prediction_steps_main.py b/settle_prediction_steps_main.py index 5e8b730..a2ce0a8 100644 --- a/settle_prediction_steps_main.py +++ b/settle_prediction_steps_main.py @@ -309,15 +309,15 @@ def run_settle_prediction(input_file, output_dir, final_step_monitor_end_index - final_step_predict_end_index] # RMSE 산정 (단계, 비선형 쌍곡선, 기존 쌍곡선) - RMSE_step = fun_rmse(sm_rmse, sp_step_rmse) - RMSE_hyper_nonlinear = fun_rmse(sm_rmse, sp_hyper_nonlinear_rmse) - RMSE_hyper_original = fun_rmse(sm_rmse, sp_hyper_original_rmse) + rmse_step = fun_rmse(sm_rmse, sp_step_rmse) + rmse_hyper_nonlinear = fun_rmse(sm_rmse, sp_hyper_nonlinear_rmse) + rmse_hyper_original = fun_rmse(sm_rmse, sp_hyper_original_rmse) # RMSE 출력 (단계, 비선형 쌍곡선, 기존 쌍곡선) if print_values: - print("RMSE (Nonlinear Hyper + Step): %0.3f" % RMSE_step) - print("RMSE (Nonlinear Hyperbolic): %0.3f" % RMSE_hyper_nonlinear) - print("RMSE (Original Hyperbolic): %0.3f" % RMSE_hyper_original) + print("RMSE (Nonlinear Hyper + Step): %0.3f" % rmse_step) + print("RMSE (Nonlinear Hyperbolic): %0.3f" % rmse_hyper_nonlinear) + print("RMSE (Original Hyperbolic): %0.3f" % rmse_hyper_original) # (최종 계측 침하량 - 예측 침하량) 계산 final_error_step = np.abs(settle[-1] - sp_step_rmse[-1]) @@ -442,9 +442,9 @@ def run_settle_prediction(input_file, output_dir, mybox = {'facecolor': 'white', 'edgecolor': 'black', 'boxstyle': 'round', 'alpha': 0.2} plt.text(max(time), 0.25 * min(-settle), "Root Mean Squared Error" - + "\n" + "Nonlinear + Step Loading: %0.3f" % RMSE_step - + "\n" + "Nonlinear Hyperbolic: %0.3f" % RMSE_hyper_nonlinear - + "\n" + "Original Hyperbolic: %0.3f" % RMSE_hyper_original, + + "\n" + "Nonlinear + Step Loading: %0.3f" % rmse_step + + "\n" + "Nonlinear Hyperbolic: %0.3f" % rmse_hyper_nonlinear + + "\n" + "Original Hyperbolic: %0.3f" % rmse_hyper_original, color='r', horizontalalignment='right', verticalalignment='top', fontsize='12', bbox=mybox) @@ -484,7 +484,7 @@ def run_settle_prediction(input_file, output_dir, is_multi_step = False # 반환 - return [RMSE_hyper_original, RMSE_hyper_nonlinear, RMSE_step, + return [rmse_hyper_original, rmse_hyper_nonlinear, rmse_step, final_error_hyper_original, final_error_hyper_nonlinear, final_error_step, is_multi_step]