2022.08.11 (SS)

3단계에 대해서 for문 오류 없이 돌아가도록
1차 완성하였습니다.

각 i단계에 맞추어 데이터 생성까지는 잘 되는것을
확인하였으나 생성한 동적변수를 i형태로 호출하는 방법을
찾지 못하여 일단 0, 1, 2(1단계, 2단계, 3단계)로
일일히 기입하여 코드 작성하였습니다.

동적변수 호출하는 방안을 시도하는 과정에서
시간이 오래걸려 코드 작성이 늦어졌습니다.
늦은 업로드 죄송합니다.
확인 부탁드립니다.
master
Sehee Shin 2022-08-11 17:07:36 +09:00
parent 8598351c20
commit 3513120631
2 changed files with 77 additions and 96 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 KiB

After

Width:  |  Height:  |  Size: 279 KiB

173
main.py
View File

@ -18,9 +18,26 @@ def generate_data_hyper(px, pt):
return pt / (px[0] * pt + px[1]) return pt / (px[0] * pt + px[1])
# error between regression and measurement # error between regression and measurement
def fun_hyper_linear(px, pt, py): def fun_hyper_nonlinear(px, pt, py):
return pt / (px[0] * pt + px[1]) - py return pt / (px[0] * pt + px[1]) - py
# i단계 보정 침하량 산정
def fun_step_measured_correction(m, p):
return m - p
# i단계 t-ti 산정
def fun_step_time_correction(t, ti):
return t - ti
# i단계 침하곡선 작성
def settlement_prediction_curve(m1, p1):
return m1 + p1
# i단계 보정 예측 침하량 산정
def fun_step_prediction_correction(m2, p2):
return p2 + (m2[0] - p2[0])
# 파일 읽기, 리스트 설정 # 파일 읽기, 리스트 설정
@ -37,127 +54,91 @@ surcharge = data['Surcharge'].to_numpy()
# 예: 1단계: (0, 9), 2단계: (10, 37), 3단계: (38, 80) # 예: 1단계: (0, 9), 2단계: (10, 37), 3단계: (38, 80)
# 예: 전체 성토 단계: 3 # 예: 전체 성토 단계: 3
'''
1단계 성토고 침하 예측
'''
step_start_index = [0, 10, 38]
step_end_index = [9, 37, 80]
# #
# 각 단계별 예측을 반복문으로 처리 # 각 단계별 예측을 반복문으로 처리
# #
'''
# 반복문 예시
for i in range(0,3):
tm = time[step_start_index[i]:step_end_index[i]]
# 내용을 채우시오.
if i > 0: step_start_index = [0, 10, 38]
# 두번째 단계부터는 침하량 보정 step_end_index = [9, 37, 80]
# 내용을 채우시오.
'''
#1단계에 해당하는 실측 데이터 범위 지정
tm_1 = time[0:10]
ym_1 = settle[0:10]
# Set a list for the coefficient; here a and b
x0 = np.ones(2) x0 = np.ones(2)
# declare a least square object for i in range(0,3):
res_lsq_hyper_linear_1 = least_squares(fun_hyper_linear, x0, args=(tm_1, ym_1))
# Print the calculated coefficient if i == 0 : # 1단계
print(res_lsq_hyper_linear_1.x)
# Generate predicted settlement data # 1단계 실측 기간 및 침하량
settle_hyper_linear_1 = generate_data_hyper(res_lsq_hyper_linear_1.x, time) globals()['tm_{}'.format(i)] = time[step_start_index[i]:step_end_index[i]]
globals()['ym_{}'.format(i)] = settle[step_start_index[i]:step_end_index[i]]
''' res_lsq_hyper_nonlinear_0 = least_squares(fun_hyper_nonlinear, x0, args=(tm_0, ym_0))
2단계 성토고 침하 예측 print(res_lsq_hyper_nonlinear_0.x)
'''
# 2단계 실측 침하량 (2단계~최종) globals()['settle_predicted_{}'.format(i)] = generate_data_hyper(res_lsq_hyper_nonlinear_0.x, time)
tm_2 = time[10:80]
ym_2 = settle[10:80]
# 2단계 실측 침하량 (2단계 구간만)
tm_22 = time[10:37]
ym_22 = settle[10:37]
# 1단계 예측 침하량 (2단계 구간만)
yp_2 = settle_hyper_linear_1[10:37]
# 1단계 예측 침하량 (2단계 ~ 최종)
yp_22 = settle_hyper_linear_1[10:80]
# 2단계 보정 침하량 산정 elif 0 < i < 2 : # 최종단계 3단계 이므로 2를 넘지 않도록 설정
def fun_step_measured_correction(m, p):
return m - p
step2_measured_correction = fun_step_measured_correction(ym_22, yp_2) # i단계 실측 기간 및 침하량
globals()['tm_{}'.format(i)] = time[step_start_index[i]:step_end_index[i]]
globals()['ym_{}'.format(i)] = settle[step_start_index[i]:step_end_index[i]]
# 2단계 t-ti 산정 # i단계~최종 실측 기간 및 침하량
def fun_step_time_correction(t, ti): globals()['tmm_{}'.format(i)] = time[step_start_index[i]:step_end_index[i+1]]
return t - ti globals()['ymm_{}'.format(i)] = settle[step_start_index[i]:step_end_index[i+1]]
step2_time_correction = fun_step_time_correction(tm_2[0:69],tm_2[0]) # i-1 단계 예측 침하량 (i단계에 해당하는)
globals()['yp_{}'.format(i)] = settle_predicted_0[step_start_index[i]:step_end_index[i]]
# i-1 단계 예측 침하량 (i단계~최종)
globals()['ypp_{}'.format(i)] = settle_predicted_0[step_start_index[i]:step_end_index[i + 1]]
# 2단계 보정 침하량에 대한 예측 침하량 산정 # i단계 실측 보정 침하량 산정
globals()['step_{}_measured_correction'.format(i)] = fun_step_measured_correction(ym_1, yp_1)
# declare a least square object # i단계 t-ti 산정
# step2_time_correction[0:27]는 회귀분석 적용할 2단계 범위만 추출한 것 globals()['step_{}_time_correction'.format(i)] = fun_step_time_correction(tmm_1, tm_1[0])
res_lsq_hyper_linear_2 = least_squares(fun_hyper_linear, x0, args=(step2_time_correction[0:27], step2_measured_correction))
# Print the calculated coefficient # i 단계 보정 침하량에 대한 예측 침하량 산정
print(res_lsq_hyper_linear_2.x) globals()['res_lsq_hyper_nonlinear_{}'.format(i)] = least_squares(fun_hyper_nonlinear, x0,
args=(step_1_time_correction[0:(step_end_index[i]-step_start_index[i])], step_1_measured_correction))
print(res_lsq_hyper_nonlinear_1.x)
# Generate predicted settlement data globals()['settle_hyper_nonlinear_{}'.format(i)] = generate_data_hyper(res_lsq_hyper_nonlinear_1.x, step_1_time_correction)
settle_hyper_linear_2 = generate_data_hyper(res_lsq_hyper_linear_2.x, step2_time_correction)
# 2단계 침하곡선 작성 # i단계 침하곡선 작성
def settlement_prediction_curve(m1, p1): globals()['step_{}_prediction_curve'.format(i)] = settlement_prediction_curve(settle_hyper_nonlinear_1, ypp_1)
return m1 + p1
step2_prediction_curve = settlement_prediction_curve(settle_hyper_linear_2, yp_22) # i단계 보정 예측 침하량 산정
globals()['settle_predicted_{}'.format(i)] = fun_step_prediction_correction(ymm_1, step_1_prediction_curve)
# 2단계 보정 예측 침하량 산정 else: # 최종 성토 단계
def fun_step_prediction_correction(m2, p2):
return p2 + (m2[0] - p2[0])
step2_prediction_correction = fun_step_prediction_correction(ym_2, step2_prediction_curve) # 최종 단계 실측 기간 및 침하량
globals()['tm_{}'.format(i)] = time[step_start_index[i]:step_end_index[i]]
globals()['ym_{}'.format(i)] = settle[step_start_index[i]:step_end_index[i]]
''' # i-1 단계 예측 침하량 (최종 단계에 해당하는)
3단계 성토고 침하 예측 globals()['yp_{}'.format(i)] = settle_predicted_1[(step_start_index[i]-step_start_index[i-1]):step_end_index[i]]
'''
# 3단계 실측 침하량 (3단계~최종) # 최종 단계 실측 보정 침하량 산정
tm_3 = time[37:80] globals()['step_{}_measured_correction'.format(i)] = fun_step_measured_correction(ym_2, yp_2)
ym_3 = settle[37:80]
# 2단계 예측 침하량 (3단계 구간만) # 최종 단계 t-ti 산정
yp_3 = step2_prediction_correction[27:80] globals()['step_{}_time_correction'.format(i)] = fun_step_time_correction(tm_2, tm_2[0])
# 3단계 보정 침하량 산정 # 최종 단계 보정 침하량에 대한 예측 침하량 산정
step3_measured_correction = fun_step_measured_correction(ym_3, yp_3) globals()['res_lsq_hyper_nonlinear_{}'.format(i)] = least_squares(fun_hyper_nonlinear, x0,
args=(step_2_time_correction, step_2_measured_correction))
print(res_lsq_hyper_nonlinear_2.x)
# 3단계 t-ti 산정 globals()['settle_hyper_nonlinear_{}'.format(i)] = generate_data_hyper(res_lsq_hyper_nonlinear_2.x,
step_2_time_correction)
step3_time_correction = fun_step_time_correction(tm_3,tm_3[0]) # 최종 단계 침하곡선 작성
globals()['step_{}_prediction_curve'.format(i)] = settlement_prediction_curve(settle_hyper_nonlinear_2, yp_2)
# 3단계 보정 침하량에 대한 예측 침하량 산정 # i단계 보정 예측 침하량 산정
globals()['settle_predicted_{}'.format(i)] = fun_step_prediction_correction(ym_2, step_2_prediction_curve)
res_lsq_hyper_linear_3 = least_squares(fun_hyper_linear, x0, args=(step3_time_correction, step3_measured_correction)) break
print(res_lsq_hyper_linear_3.x)
settle_hyper_linear_3 = generate_data_hyper(res_lsq_hyper_linear_3.x, step3_time_correction)
# 3단계 침하곡선 작성
step3_prediction_curve = settlement_prediction_curve(settle_hyper_linear_3, yp_3)
# 3단계 보정 예측 침하량 산정
step3_prediction_correction = fun_step_prediction_correction(ym_3, step3_prediction_curve)
''' '''
나중에: 그래프 작성 나중에: 그래프 작성
@ -180,9 +161,9 @@ axes[0].set_xlim(left = 0)
axes[1].scatter(time, -settle, s = 50, facecolors='white', edgecolors='black', label = 'measured data') axes[1].scatter(time, -settle, s = 50, facecolors='white', edgecolors='black', label = 'measured data')
# draw predicted data # draw predicted data
axes[1].plot(time, -settle_hyper_linear_1, linestyle='--', color='red', label='original Hyperbolic_1') axes[1].plot(time, -settle_predicted_0, linestyle='--', color='red', label='Predicted Curve_Step 1')
axes[1].plot(tm_2, -step2_prediction_correction, linestyle='--', color='blue', label='original Hyperbolic_2') axes[1].plot(tmm_1, -settle_predicted_1, linestyle='--', color='blue', label='Predicted Curve_Step 2')
axes[1].plot(tm_3, -step3_prediction_correction, linestyle='--', color='green', label='original Hyperbolic_3') axes[1].plot(tm_2, -settle_predicted_2, linestyle='--', color='green', label='Predicted Curve_Step 3')
# Set axes title # Set axes title
axes[1].set_xlabel("Time (day)", fontsize = 17) axes[1].set_xlabel("Time (day)", fontsize = 17)
@ -198,5 +179,5 @@ axes[1].legend(bbox_to_anchor = (0, 0, 1, 0), loc =4, ncol = 3, mode="expand",
borderaxespad = 0, frameon = False, fontsize = 12) borderaxespad = 0, frameon = False, fontsize = 12)
plt.savefig('1_SP_11_Rev.2.png', dpi=300) plt.savefig('main_Rev.1.png', dpi=300)
plt.show() plt.show()