|
|
@@ -160,7 +160,11 @@ class SDHU_AB(BaseDevice):
|
|
|
self.record_model(
|
|
|
model_name = 'ATD',
|
|
|
model = reorder_posterior(param_prior,self.param_posterior),
|
|
|
- train_data = {'x':np.array([1])},
|
|
|
+ train_data = {
|
|
|
+ 'wheel_1_TinR': observed_data.loc[:,'wheel_1_TinR'].values,
|
|
|
+ 'fan_2_Hz' : observed_data.loc[:,'wheel_2_TinR'].values,
|
|
|
+ 'coil_2_DoutA': observed_data.loc[:,'coil_2_DoutA'].values,
|
|
|
+ },
|
|
|
train_metric = {'R2':1,'MAE':1,'MAPE':1}
|
|
|
)
|
|
|
self.TVP_data = self.get_TVP(self.param_posterior,observed_data)
|
|
|
@@ -204,99 +208,111 @@ class SDHU_AB(BaseDevice):
|
|
|
return clean_data
|
|
|
|
|
|
|
|
|
- # def optimize(
|
|
|
- # self,
|
|
|
- # cur_input_data: pd.DataFrame,
|
|
|
- # wheel_1_TinR : tuple = (70,120),
|
|
|
- # wheel_2_TinR : tuple = (70,120),
|
|
|
- # fan_2_Hz : tuple = (30,50),
|
|
|
- # constrains : list = None,
|
|
|
- # logging : bool = True,
|
|
|
- # target : str = 'summary_Fs',
|
|
|
- # target_min : bool = True
|
|
|
- # ) -> list:
|
|
|
- # constrains = [] if constrains is None else constrains
|
|
|
- # cur_input_data = cur_input_data.iloc[[0],:]
|
|
|
+ def optimize(
|
|
|
+ self,
|
|
|
+ cur_input_data: pd.DataFrame,
|
|
|
+ wheel_1_TinR : tuple = (70,120),
|
|
|
+ fan_2_Hz : tuple = (30,50),
|
|
|
+ constrains : list = None,
|
|
|
+ logging : bool = True,
|
|
|
+ target : str = 'summary_Fs',
|
|
|
+ target_min : bool = True
|
|
|
+ ) -> list:
|
|
|
+ constrains = [] if constrains is None else constrains
|
|
|
+ cur_input_data = cur_input_data.iloc[[0],:]
|
|
|
|
|
|
- # opt_var_boundary = {}
|
|
|
- # if wheel_1_TinR is not None:
|
|
|
- # opt_var_boundary['wheel_1_TinR'] = {'lb':min(wheel_1_TinR),'ub':max(wheel_1_TinR)}
|
|
|
- # if wheel_2_TinR is not None:
|
|
|
- # opt_var_boundary['wheel_2_TinR'] = {'lb':min(wheel_2_TinR),'ub':max(wheel_2_TinR)}
|
|
|
- # if fan_2_Hz is not None:
|
|
|
- # opt_var_boundary['fan_2_Hz'] = {'lb':min(fan_2_Hz),'ub':max(fan_2_Hz)}
|
|
|
+ opt_var_boundary = {}
|
|
|
+ if wheel_1_TinR is not None:
|
|
|
+ opt_var_boundary['wheel_1_TinR'] = {'lb':min(wheel_1_TinR),'ub':max(wheel_1_TinR)}
|
|
|
+ if fan_2_Hz is not None:
|
|
|
+ opt_var_boundary['fan_2_Hz'] = {'lb':min(fan_2_Hz),'ub':max(fan_2_Hz)}
|
|
|
|
|
|
- # opt_var_value = cur_input_data.loc[:,list(opt_var_boundary.keys())]
|
|
|
- # oth_var_value = (
|
|
|
- # cur_input_data
|
|
|
- # .loc[:,list(self.model_input_data_columns.values())]
|
|
|
- # .drop(opt_var_value.columns,axis=1)
|
|
|
- # )
|
|
|
- # opt_res = optimizer(
|
|
|
- # model = self,
|
|
|
- # opt_var_boundary = opt_var_boundary,
|
|
|
- # opt_var_value = opt_var_value,
|
|
|
- # oth_var_value = oth_var_value,
|
|
|
- # target = target,
|
|
|
- # target_min = target_min,
|
|
|
- # constrains = constrains,
|
|
|
- # logging = logging,
|
|
|
- # other_kwargs = {'NIND':2000,'MAXGEN':50}
|
|
|
- # )
|
|
|
- # return opt_res
|
|
|
+ opt_var_value = cur_input_data.loc[:,list(opt_var_boundary.keys())]
|
|
|
+ oth_var_value = (
|
|
|
+ cur_input_data
|
|
|
+ .loc[:,list(set(self.model_input_data_columns.values()))]
|
|
|
+ .drop(opt_var_value.columns,axis=1)
|
|
|
+ )
|
|
|
+ opt_res = optimizer(
|
|
|
+ model = self,
|
|
|
+ opt_var_boundary = opt_var_boundary,
|
|
|
+ opt_var_value = opt_var_value,
|
|
|
+ oth_var_value = oth_var_value,
|
|
|
+ target = target,
|
|
|
+ target_min = target_min,
|
|
|
+ constrains = constrains,
|
|
|
+ logging = logging,
|
|
|
+ other_kwargs = {'NIND':2000,'MAXGEN':50}
|
|
|
+ )
|
|
|
+ return opt_res
|
|
|
|
|
|
|
|
|
- # def plot_opt(
|
|
|
- # self,
|
|
|
- # cur_input_data: pd.DataFrame,
|
|
|
- # target_min : str = 'summary_waste',
|
|
|
- # ):
|
|
|
- # data_input = (
|
|
|
- # pd.MultiIndex.from_product(
|
|
|
- # [
|
|
|
- # np.linspace(70,120,1000),
|
|
|
- # np.linspace(70,120,1000),
|
|
|
- # ],
|
|
|
- # names=['wheel_1_TinR','wheel_2_TinR']
|
|
|
- # )
|
|
|
- # .to_frame(index=False)
|
|
|
- # )
|
|
|
- # for col in cur_input_data.columns:
|
|
|
- # if col in data_input.columns:
|
|
|
- # continue
|
|
|
- # data_input[col] = cur_input_data.loc[:,col].iat[0]
|
|
|
- # data_output = self.predict_system(data_input)
|
|
|
- # data = (
|
|
|
- # data_output
|
|
|
- # .assign(
|
|
|
- # wheel_1_TinR = data_input.loc[:,'wheel_1_TinR'],
|
|
|
- # wheel_2_TinR = data_input.loc[:,'wheel_2_TinR'],
|
|
|
- # )
|
|
|
- # .assign(coil_3_DoutA=lambda dt:dt.coil_3_DoutA.round(1))
|
|
|
- # .loc[lambda dt:dt.groupby('coil_3_DoutA')[target_min].idxmin()]
|
|
|
- # .loc[lambda dt:dt.coil_3_DoutA.mod(1)==0]
|
|
|
- # )
|
|
|
- # import plotnine as gg
|
|
|
- # plot = (
|
|
|
- # data
|
|
|
- # .pipe(gg.ggplot)
|
|
|
- # + gg.aes(x='wheel_1_TinR',y='wheel_2_TinR')
|
|
|
- # + gg.geom_path(size=1)
|
|
|
- # + gg.geom_point()
|
|
|
- # + gg.geom_label(gg.aes(label='coil_3_DoutA'))
|
|
|
- # + gg.geom_abline(slope=1,intercept=0,color='red',linetype='--')
|
|
|
- # )
|
|
|
- # return plot
|
|
|
+ def plot_opt(
|
|
|
+ self,
|
|
|
+ cur_input_data: pd.DataFrame,
|
|
|
+ target_min : str = 'summary_waste',
|
|
|
+ coil_2_DoutA : tuple = None
|
|
|
+ ):
|
|
|
+ if coil_2_DoutA is None:
|
|
|
+ coil_2_DoutA = (
|
|
|
+ self.model_info['model_train_info_ATD']['coil_2_DoutA_min'],
|
|
|
+ self.model_info['model_train_info_ATD']['coil_2_DoutA_max']
|
|
|
+ )
|
|
|
+ data_input = (
|
|
|
+ pd.MultiIndex.from_product(
|
|
|
+ [
|
|
|
+ np.linspace(
|
|
|
+ self.model_info['model_train_info_ATD']['wheel_1_TinR_min']-5,
|
|
|
+ self.model_info['model_train_info_ATD']['wheel_1_TinR_max']+5,
|
|
|
+ 1000
|
|
|
+ ),
|
|
|
+ np.linspace(
|
|
|
+ self.model_info['model_train_info_ATD']['fan_2_Hz_min']-5,
|
|
|
+ self.model_info['model_train_info_ATD']['fan_2_Hz_max']+5,
|
|
|
+ 1000
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ names=['wheel_1_TinR','fan_2_Hz']
|
|
|
+ )
|
|
|
+ .to_frame(index=False)
|
|
|
+ )
|
|
|
+ for col in cur_input_data.columns:
|
|
|
+ if col in data_input.columns:
|
|
|
+ continue
|
|
|
+ data_input[col] = cur_input_data.loc[:,col].iat[0]
|
|
|
+ data_output = self.predict_system(data_input)
|
|
|
+ data = (
|
|
|
+ data_output
|
|
|
+ .assign(
|
|
|
+ wheel_1_TinR = data_input.loc[:,'wheel_1_TinR'],
|
|
|
+ fan_2_Hz = data_input.loc[:,'fan_2_Hz'],
|
|
|
+ )
|
|
|
+ .assign(coil_2_DoutA=lambda dt:dt.coil_2_DoutA.round(1))
|
|
|
+ .loc[lambda dt:dt.coil_2_DoutA.between(*(min(coil_2_DoutA),max(coil_2_DoutA)))]
|
|
|
+ .loc[lambda dt:dt.groupby('coil_2_DoutA')[target_min].idxmin()]
|
|
|
+ .loc[lambda dt:dt.coil_2_DoutA.mod(0.5)==0]
|
|
|
+ )
|
|
|
+ import plotnine as gg
|
|
|
+ plot = (
|
|
|
+ data
|
|
|
+ .pipe(gg.ggplot)
|
|
|
+ + gg.aes(x='wheel_1_TinR',y='fan_2_Hz')
|
|
|
+ + gg.geom_path(size=1)
|
|
|
+ + gg.geom_point()
|
|
|
+ + gg.geom_label(gg.aes(label='coil_2_DoutA'))
|
|
|
+ + gg.geom_abline(slope=1,intercept=0,color='red',linetype='--')
|
|
|
+ )
|
|
|
+ return plot
|
|
|
|
|
|
- # def plot_check(self,cur_input_data:pd.DataFrame) -> dict:
|
|
|
- # pa1=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_DoutP')
|
|
|
- # pa2=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_ToutP')
|
|
|
- # pa3=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_EFF')
|
|
|
- # pb1=self.curve(input_data=cur_input_data,x='wheel_2_TinR',y='wheel_2_DoutP')
|
|
|
- # pb2=self.curve(input_data=cur_input_data,x='wheel_2_TinR',y='wheel_2_ToutP')
|
|
|
- # pb3=self.curve(input_data=cur_input_data,x='wheel_2_TinR',y='wheel_2_EFF')
|
|
|
- # plot1 = (pa1|pa2|pa3)/(pb1|pb2|pb3)
|
|
|
- # return {'plot1':plot1}
|
|
|
+ def plot_check(self,cur_input_data:pd.DataFrame) -> dict:
|
|
|
+ pa1=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_DoutP')
|
|
|
+ pa2=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_ToutP')
|
|
|
+ pa3=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_EFF')
|
|
|
+ pb1=self.curve(input_data=cur_input_data,x='fan_2_Hz',y='wheel_1_DoutP')
|
|
|
+ pb2=self.curve(input_data=cur_input_data,x='fan_2_Hz',y='wheel_1_ToutP')
|
|
|
+ pb3=self.curve(input_data=cur_input_data,x='fan_2_Hz',y='wheel_1_EFF')
|
|
|
+ plot1 = (pa1|pa2|pa3)/(pb1|pb2|pb3)
|
|
|
+ return {'plot1':plot1}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -384,15 +400,12 @@ def model_A(
|
|
|
engine = engine
|
|
|
)
|
|
|
|
|
|
-
|
|
|
- # waste = cal_Q_waste(
|
|
|
- # wheel_1_res = wheel_1_res_adj,
|
|
|
- # wheel_2_res = wheel_2_res_adj,
|
|
|
- # heatingcoil_1_res = heatingcoil_1_res,
|
|
|
- # heatingcoil_2_res = heatingcoil_2_res,
|
|
|
- # wheel_1_TinR = wheel_1_TinR,
|
|
|
- # wheel_2_TinR = wheel_2_TinR
|
|
|
- # )
|
|
|
+ waste = cal_Q_waste(
|
|
|
+ wheel_1_res = wheel_1_res_adj,
|
|
|
+ heatingcoil_1_res = heatingcoil_1_res,
|
|
|
+ wheel_1_TinR = wheel_1_TinR,
|
|
|
+ fan_2_Hz = fan_2_Hz
|
|
|
+ )
|
|
|
return {
|
|
|
'coil_2' : coil_2_res,
|
|
|
'wheel_1' : wheel_1_res_adj,
|
|
|
@@ -401,7 +414,7 @@ def model_A(
|
|
|
'Fa' : air_flow,
|
|
|
'summary' : {
|
|
|
'Fs' : heatingcoil_1_res['Fs'],
|
|
|
- # **waste,
|
|
|
+ **waste,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -442,31 +455,35 @@ class AirFlow_SDHU_A:
|
|
|
return param
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
def cal_Q_waste(
|
|
|
wheel_1_res,
|
|
|
- wheel_2_res,
|
|
|
heatingcoil_1_res,
|
|
|
- heatingcoil_2_res,
|
|
|
wheel_1_TinR,
|
|
|
- wheel_2_TinR
|
|
|
-):
|
|
|
+ fan_2_Hz
|
|
|
+) -> dict:
|
|
|
+ def waste_cond_func1(TinR):
|
|
|
+ waste = 0.15 + 0.0001 * (TinR-70)**3
|
|
|
+ return np.where(waste>0,waste,0)
|
|
|
+ def waste_cond_func2(TinR):
|
|
|
+ waste = 0.25 * (1 - np.exp(-0.04 * (TinR - 70)))
|
|
|
+ return np.where(waste>0,waste,0)
|
|
|
+
|
|
|
+ heatingcoil_1_Q = heatingcoil_1_res['Q']
|
|
|
+ heatingcoil_1_Q = np.where(heatingcoil_1_Q>0,heatingcoil_1_Q,0)
|
|
|
+
|
|
|
waste_Qsen1 = wheel_1_res['Qsen']
|
|
|
- waste_Qsen2 = wheel_2_res['Qsen']
|
|
|
- waste_cond1 = heatingcoil_1_res['Q'] * (0.15 + 0.0001 * (wheel_1_TinR-70)**2)
|
|
|
- waste_cond2 = heatingcoil_2_res['Q'] * (0.15 + 0.0001 * (wheel_2_TinR-70)**2)
|
|
|
- waste_out = (
|
|
|
- heatingcoil_1_res['Q'] + heatingcoil_2_res['Q']
|
|
|
- - wheel_1_res['Qsen'] - wheel_1_res['Qlat']
|
|
|
- - wheel_2_res['Qsen'] - wheel_2_res['Qlat']
|
|
|
- )
|
|
|
- return {
|
|
|
+ waste_cond1 = heatingcoil_1_Q * waste_cond_func1(wheel_1_TinR)
|
|
|
+
|
|
|
+ res = {
|
|
|
'waste_Qsen1': waste_Qsen1,
|
|
|
- 'waste_Qsen2': waste_Qsen2,
|
|
|
- 'waste_Qout' : waste_out,
|
|
|
'waste_cond1': waste_cond1,
|
|
|
- 'waste_cond2': waste_cond2,
|
|
|
- 'waste_out' : waste_out,
|
|
|
- 'waste' : waste_Qsen1+waste_cond2+waste_cond1+waste_cond2+waste_out,
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ waste_out = heatingcoil_1_Q - wheel_1_res['Qsen'] - wheel_1_res['Qlat']
|
|
|
+ waste_out = np.where(waste_out>0,waste_out,0)
|
|
|
+ waste = waste_Qsen1 + waste_cond1 + waste_out + fan_2_Hz/100
|
|
|
+ res['waste_out'] = waste_out
|
|
|
+ res['waste'] = waste
|
|
|
+
|
|
|
+ return res
|