~vonfry/cpipc-2020

bd2d54d8d1f00740ede0d44abb53430218c1cbb5 — Vonfry 2 years ago 7954698
fix some calculate error
1 files changed, 15 insertions(+), 11 deletions(-)

M 3optimization.py
M 3optimization.py => 3optimization.py +15 -11
@@ 36,6 36,10 @@ norm_ron_loss_zero = (0 - df_ron_loss.mean()) / df_ron_loss.std()
df_s = df['_硫含量']
norm_s = (5 - df_s.mean()) / df_s.std()
norm_s_zero = (0 - df_s.mean()) / df_s.std()
df_std_s = df.std()['_硫含量']
df_mean_s = df.mean()['_硫含量']
df_std_ron_loss = df.std()['RON损失']
df_mean_ron_loss = df.mean()['RON损失']

def merge_feature_args(unmodified, modified):
    for i in range(0, len(unmodified_feature_index)):


@@ 54,8 58,8 @@ def fitness(fix_args, rowindex):
        if not (pred_s > norm_s_zero and pred_s <= norm_s):
            return 1
        # step3: compute RON LOSS RATE
        ron_loss = df_ron_loss_norm.iloc[rowindex]
        loss_reduce_rate = (ron_loss - pred_ron_loss ) / ron_loss
        ron_loss = df_ron_loss_norm.iloc[rowindex] * df_std_ron_loss + df_mean_ron_loss
        loss_reduce_rate = (ron_loss - (pred_ron_loss * df_std_ron_loss + df_mean_ron_loss) ) / ron_loss
        if loss_reduce_rate > 0.8 :
            return 0
        if loss_reduce_rate < 0.3:


@@ 114,21 118,21 @@ df_original_best_x_norm = (df_original_best_x - df_original_best_x.mean()) / df_
df_norm = (df - df.mean()) / df.std()

sample_index = 132
df_sample_ron_loss = df.iloc[sample_index]['RON损失']
df_sample_ron_loss_norm = df_norm.iloc[sample_index]['RON损失']
df_std_s = df.std()['_硫含量']
df_mean_s = df.mean()['_硫含量']
df_std_ron_loss = df.std()['RON损失']
df_mean_ron_loss = df.mean()['RON损失']
pred_opted_sample = model.pred(np.array([df_original_best_x_norm[feature].iloc[sample_index]]))[0]
pred_opted_sample = model.predict(np.array([df_original_best_x_norm[feature].iloc[sample_index]]))[0]
optimization_sample_original_s = pred_opted_sample[1] * df_std_s + df_mean_s
optimization_sample_original_ron_loss = pred_opted_sample[0] * df_std_ron_loss + df_mean_ron_loss
optimization_sample_ron_loss_rate = (df_sample_ron_loss - optimization_sample_original_ron_loss) / df_sample_ron_loss
optimization_sample_analysis = pd.DataFrame({
    'optimized_s': [pred_opted_sample[1] * df_std_s + df_mean_s],
    'optimized_ron_loss': [pred_opted_sample[0] * df_std_ron_loss + df_mean_ron_loss],
    'ron_loss_rate': [(pred_opted_sample[0]- df_sample_ron_loss_norm) / df_sample_ron_loss_norm]
    'optimized_s': [optimization_sample_original_s],
    'optimized_ron_loss': [optimization_sample_original_ron_loss],
    'ron_loss_rate': [optimization_sample_ron_loss_rate]
})
optimization_sample_analysis.to_csv('./data/optimization_sample_analysis.csv')

optimization_and_original_sample = pd.DataFrame(
    np.array([opt, df[unmodified_feature + modified_feature].iloc[sample_index]]),
    np.array([df_original_best_x, df[unmodified_feature + modified_feature].iloc[sample_index]]),
    columns = unmodified_feature + modified_feature,
    index = ['optimized', 'original']
)