~vonfry/cpipc-2020

e49680815453c13359a1845891408661d3f9d81a — Vonfry 2 years ago 88fb46f
finish
1 files changed, 24 insertions(+), 14 deletions(-)

M 3optimization.py
M 3optimization.py => 3optimization.py +24 -14
@@ 58,7 58,7 @@ 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] * df_std_ron_loss + df_mean_ron_loss
        ron_loss = df_ron_loss.iloc[rowindex]
        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


@@ 96,25 96,35 @@ def calculate_minimum(rowindex):
    calcount += 1
    return fix_args.tolist() + original_best_x

optimzation = list(map(calculate_minimum, range(0, len(df))))
optimization = list(map(calculate_minimum, range(0, len(df))))

df_original_best_x = pd.DataFrame(optimzation, columns = unmodified_feature + modified_feature)
df_original_best_x = pd.DataFrame(optimization, columns = unmodified_feature + modified_feature)

df_original_best_x.index = df.index

df_original_best_x.to_csv('./data/optimization.csv')

# df_original_best_x = pd.read_csv('./data/optimization.csv', index_col = 0)
df_original_best_x_norm = (df_original_best_x[feature] - df[feature].mean()) / df[feature].std()
optimization_ron_loss_and_s  = model.predict(df_original_best_x_norm[feature])
df_optimization_ron_loss_and_s = pd.DataFrame(optimization_ron_loss_and_s, columns = ['ron_loss', 's'])
original_optimization_ron_loss = df_optimization_ron_loss_and_s['ron_loss'] * df_std_ron_loss + df_mean_ron_loss
original_optimization_s = df_optimization_ron_loss_and_s['s'] * df_std_s + df_mean_s
optimization_analysis_ron_loss_rate_mean = ((df_ron_loss - original_optimization_ron_loss) / df_ron_loss).mean()
optimization_analysis = pd.DataFrame({
    'ron_loss_rate_mean': [optimization_analysis_ron_loss_rate_mean],
    's_mean': [original_optimization_s.mean()]
})
optimization_analysis.to_csv('./data/optimization_analysis.csv')

diff = df[feature] - df_original_best_x
diff.to_csv('./data/optimization-diff.csv')

diff_mean = diff.mean()
diff.to_csv('./data/optimization-diff-mean.csv')
diff_mean.to_csv('./data/optimization-diff-mean.csv')

diff_norm = (diff - diff_mean) / diff.std()

# df_original_best_x = pd.read_csv('./data/optimization.csv', index_col = 0)
df_original_best_x_norm = (df_original_best_x - df_original_best_x.mean()) / df_original_best_x.std()

df_norm = (df - df.mean()) / df.std()

sample_index = 132


@@ 132,7 142,7 @@ optimization_sample_analysis = pd.DataFrame({
optimization_sample_analysis.to_csv('./data/optimization_sample_analysis.csv')

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


@@ 153,9 163,9 @@ width_sample = 0.35
x = np.arange(1, len(feature) + 1)
rects1 = axe_sample.bar(x - width_sample/2, df_norm[feature].iloc[sample_index].values, width_sample, label='Original')
rects2 = axe_sample.bar(x + width_sample/2, df_original_best_x_norm[feature].iloc[sample_index].values, width_sample, label='Optimized')
axe_133.set_xticks(x)
axe_133.set_xticklabels([ 'D' + str(i + 1) for i in range(0, len(feature))])
axe_133.set_ylabel('norm values')
axe_133.legend()
fig_133.tight_layout()
fig_133.savefig('./output/optimization-sample.jpg')
axe_sample.set_xticks(x)
axe_sample.set_xticklabels([ 'D' + str(i + 1) for i in range(0, len(feature))])
axe_sample.set_ylabel('norm values')
axe_sample.legend()
fig_sample.tight_layout()
fig_sample.savefig('./output/optimization-sample.jpg')