From 2481a751ae9dabe9e9abb8ace8288b43a3c73e61 Mon Sep 17 00:00:00 2001 From: Manos Katsomallos Date: Wed, 13 Oct 2021 15:04:57 +0200 Subject: [PATCH] code: Compare sel with original --- code/expt/copenhagen-sel.py | 55 ++++++++++++++++++++++++++------ code/expt/hue-sel.py | 62 +++++++++++++++++++++++++++++-------- code/expt/t-drive-sel.py | 57 ++++++++++++++++++++++++++++------ 3 files changed, 142 insertions(+), 32 deletions(-) diff --git a/code/expt/copenhagen-sel.py b/code/expt/copenhagen-sel.py index 6620097..52d6bcb 100644 --- a/code/expt/copenhagen-sel.py +++ b/code/expt/copenhagen-sel.py @@ -57,8 +57,11 @@ def main(args): x_offset = -(bar_width/2)*(n - 1) mae_u = np.zeros(len(lmdks_pct)) + mae_u_sel= np.zeros(len(lmdks_pct)) mae_s = np.zeros(len(lmdks_pct)) + mae_s_sel = np.zeros(len(lmdks_pct)) mae_a = np.zeros(len(lmdks_pct)) + mae_a_sel = np.zeros(len(lmdks_pct)) mae_evt = 0 mae_usr = 0 @@ -71,16 +74,22 @@ def main(args): lmdks_sel, eps_out = lmdk_sel.find_lmdks(seq, lmdks, epsilon) # Skip - rls_data_s, _ = lmdk_bgt.skip_cont(seq, lmdks_sel, eps_out) + rls_data_s, _ = lmdk_bgt.skip_cont(seq, lmdks, eps_out) mae_s[i] += (lmdk_bgt.mae_cont(rls_data_s)/args.iter)*100 + rls_data_s_sel, _ = lmdk_bgt.skip_cont(seq, lmdks_sel, eps_out) + mae_s_sel[i] += (lmdk_bgt.mae_cont(rls_data_s_sel)/args.iter)*100 # Uniform - rls_data_u, _ = lmdk_bgt.uniform_cont(seq, lmdks_sel, eps_out) + rls_data_u, _ = lmdk_bgt.uniform_cont(seq, lmdks, eps_out) mae_u[i] += (lmdk_bgt.mae_cont(rls_data_u)/args.iter)*100 + rls_data_u_sel, _ = lmdk_bgt.uniform_cont(seq, lmdks_sel, eps_out) + mae_u_sel[i] += (lmdk_bgt.mae_cont(rls_data_u_sel)/args.iter)*100 # Adaptive - rls_data_a, _, _ = lmdk_bgt.adaptive_cont(seq, lmdks_sel, eps_out, .5, .5) + rls_data_a, _, _ = lmdk_bgt.adaptive_cont(seq, lmdks, eps_out, .5, .5) mae_a[i] += (lmdk_bgt.mae_cont(rls_data_a)/args.iter)*100 + rls_data_a_sel, _, _ = lmdk_bgt.adaptive_cont(seq, lmdks_sel, eps_out, .5, .5) + mae_a_sel[i] += (lmdk_bgt.mae_cont(rls_data_a_sel)/args.iter)*100 # Calculate once if pct == lmdks_pct[0]: @@ -106,29 +115,57 @@ def main(args): ) plt.text(x_i[-1] + x_i[-1]*.14, mae_usr - mae_usr*.05, 'user') + # Plot bars plt.bar( x_i + x_offset, - mae_s, + mae_s_sel, bar_width, label='Skip', linewidth=lmdk_lib.line_width ) - x_offset += bar_width plt.bar( x_i + x_offset, - mae_u, + mae_s, bar_width, - label='Uniform', + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', linewidth=lmdk_lib.line_width ) x_offset += bar_width plt.bar( x_i + x_offset, - mae_a, + mae_u_sel, + bar_width, + label='Uniform', + linewidth=lmdk_lib.line_width + ) + plt.bar( + x_i + x_offset, + mae_u, + bar_width, + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', + linewidth=lmdk_lib.line_width + ) + x_offset += bar_width + plt.bar( + x_i + x_offset, + mae_a_sel, bar_width, label='Adaptive', linewidth=lmdk_lib.line_width ) + plt.bar( + x_i + x_offset, + mae_a, + bar_width, + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', + linewidth=lmdk_lib.line_width + ) x_offset += bar_width path = str('../../rslt/bgt_cmp/' + d) @@ -137,7 +174,7 @@ def main(args): # # Show plot # plt.show() # Save plot - lmdk_lib.save_plot(path + '-sel.pdf') + lmdk_lib.save_plot(path + '-sel-cmp.pdf') print('[OK]', flush=True) diff --git a/code/expt/hue-sel.py b/code/expt/hue-sel.py index 5a0ce9b..6fddc4b 100644 --- a/code/expt/hue-sel.py +++ b/code/expt/hue-sel.py @@ -17,7 +17,6 @@ import time def main(args): - res_file = '/home/manos/Cloud/Data/HUE/Results.zip' # User's consumption seq = lmdk_lib.load_data(args, 'cons') # The name of the dataset @@ -53,8 +52,11 @@ def main(args): x_offset = -(bar_width/2)*(n - 1) mae_u = np.zeros(len(lmdks_pct)) + mae_u_sel= np.zeros(len(lmdks_pct)) mae_s = np.zeros(len(lmdks_pct)) + mae_s_sel = np.zeros(len(lmdks_pct)) mae_a = np.zeros(len(lmdks_pct)) + mae_a_sel = np.zeros(len(lmdks_pct)) mae_evt = 0 mae_usr = 0 @@ -67,16 +69,22 @@ def main(args): lmdks_sel, eps_out = lmdk_sel.find_lmdks(seq, lmdks, epsilon) # Skip - rls_data_s, _ = lmdk_bgt.skip_cons(seq, lmdks_sel, eps_out) - mae_s[i] += lmdk_bgt.mae_cons(seq, rls_data_s)/args.iter + rls_data_s, _ = lmdk_bgt.skip_cons(seq, lmdks, eps_out) + mae_s[i] += (lmdk_bgt.mae_cons(seq, rls_data_s)/args.iter)*100 + rls_data_s_sel, _ = lmdk_bgt.skip_cons(seq, lmdks_sel, eps_out) + mae_s_sel[i] += (lmdk_bgt.mae_cons(seq, rls_data_s_sel)/args.iter)*100 # Uniform - rls_data_u, _ = lmdk_bgt.uniform_cons(seq, lmdks_sel, eps_out) - mae_u[i] += lmdk_bgt.mae_cons(seq, rls_data_u)/args.iter + rls_data_u, _ = lmdk_bgt.uniform_cons(seq, lmdks, eps_out) + mae_u[i] += (lmdk_bgt.mae_cons(seq, rls_data_u)/args.iter)*100 + rls_data_u_sel, _ = lmdk_bgt.uniform_cons(seq, lmdks_sel, eps_out) + mae_u_sel[i] += (lmdk_bgt.mae_cons(seq, rls_data_u_sel)/args.iter)*100 # Adaptive - rls_data_a, _, _ = lmdk_bgt.adaptive_cons(seq, lmdks_sel, eps_out, .5, .5) - mae_a[i] += lmdk_bgt.mae_cons(seq, rls_data_a)/args.iter + rls_data_a, _, _ = lmdk_bgt.adaptive_cons(seq, lmdks, eps_out, .5, .5) + mae_a[i] += (lmdk_bgt.mae_cons(seq, rls_data_a)/args.iter)*100 + rls_data_a_sel, _, _ = lmdk_bgt.adaptive_cons(seq, lmdks_sel, eps_out, .5, .5) + mae_a_sel[i] += (lmdk_bgt.mae_cons(seq, rls_data_a_sel)/args.iter)*100 # Calculate once if pct == lmdks_pct[0]: @@ -102,29 +110,57 @@ def main(args): ) plt.text(x_i[-1] + x_i[-1]*.14, mae_usr - mae_usr*.14, 'user') + # Plot bars plt.bar( x_i + x_offset, - mae_s, + mae_s_sel, bar_width, label='Skip', linewidth=lmdk_lib.line_width ) - x_offset += bar_width plt.bar( x_i + x_offset, - mae_u, + mae_s, bar_width, - label='Uniform', + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', linewidth=lmdk_lib.line_width ) x_offset += bar_width plt.bar( x_i + x_offset, - mae_a, + mae_u_sel, + bar_width, + label='Uniform', + linewidth=lmdk_lib.line_width + ) + plt.bar( + x_i + x_offset, + mae_u, + bar_width, + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', + linewidth=lmdk_lib.line_width + ) + x_offset += bar_width + plt.bar( + x_i + x_offset, + mae_a_sel, bar_width, label='Adaptive', linewidth=lmdk_lib.line_width ) + plt.bar( + x_i + x_offset, + mae_a, + bar_width, + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', + linewidth=lmdk_lib.line_width + ) x_offset += bar_width path = str('../../rslt/bgt_cmp/' + d) @@ -133,7 +169,7 @@ def main(args): # Show plot # plt.show() # Save plot - lmdk_lib.save_plot(path + '-sel.pdf') + lmdk_lib.save_plot(path + '-sel-cmp.pdf') print('[OK]', flush=True) diff --git a/code/expt/t-drive-sel.py b/code/expt/t-drive-sel.py index b91b411..af6704e 100644 --- a/code/expt/t-drive-sel.py +++ b/code/expt/t-drive-sel.py @@ -75,8 +75,11 @@ def main(args): x_offset = -(bar_width/2)*(n - 1) mae_u = np.zeros(len(data_info[d]['lmdks'])) + mae_u_sel= np.zeros(len(data_info[d]['lmdks'])) mae_s = np.zeros(len(data_info[d]['lmdks'])) + mae_s_sel = np.zeros(len(data_info[d]['lmdks'])) mae_a = np.zeros(len(data_info[d]['lmdks'])) + mae_a_sel = np.zeros(len(data_info[d]['lmdks'])) mae_evt = 0 mae_usr = 0 for i, lmdk in enumerate(data_info[d]['lmdks']): @@ -90,16 +93,22 @@ def main(args): lmdks_sel, eps_out = lmdk_sel.find_lmdks(seq, lmdks, bgt['epsilon']) # Skip - rls_data_s, _ = lmdk_bgt.skip(seq, lmdks_sel, eps_out) - mae_s[i] += lmdk_bgt.mae(seq, rls_data_s)/args.iter + rls_data_s, _ = lmdk_bgt.skip(seq, lmdks, eps_out) + mae_s[i] += (lmdk_bgt.mae(seq, rls_data_s)/args.iter)*100 + rls_data_s_sel, _ = lmdk_bgt.skip(seq, lmdks_sel, eps_out) + mae_s_sel[i] += (lmdk_bgt.mae(seq, rls_data_s_sel)/args.iter)*100 # Uniform - rls_data_u, _ = lmdk_bgt.uniform_r(seq, lmdks_sel, eps_out) - mae_u[i] += lmdk_bgt.mae(seq, rls_data_u)/args.iter + rls_data_u, _ = lmdk_bgt.uniform_r(seq, lmdks, eps_out) + mae_u[i] += (lmdk_bgt.mae(seq, rls_data_u)/args.iter)*100 + rls_data_u_sel, _ = lmdk_bgt.uniform_r(seq, lmdks_sel, eps_out) + mae_u_sel[i] += (lmdk_bgt.mae(seq, rls_data_u_sel)/args.iter)*100 # Adaptive - rls_data_a, _, _ = lmdk_bgt.adaptive(seq, lmdks_sel, eps_out, .5, .5) - mae_a[i] += lmdk_bgt.mae(seq, rls_data_a)/args.iter + rls_data_a, _, _ = lmdk_bgt.adaptive(seq, lmdks, eps_out, .5, .5) + mae_a[i] += (lmdk_bgt.mae(seq, rls_data_a)/args.iter)*100 + rls_data_a_sel, _, _ = lmdk_bgt.adaptive(seq, lmdks_sel, eps_out, .5, .5) + mae_a_sel[i] += (lmdk_bgt.mae(seq, rls_data_a_sel)/args.iter)*100 # Calculate once if lmdk == min(data_info[d]['lmdks']): @@ -128,27 +137,55 @@ def main(args): # Plot bars plt.bar( x_i + x_offset, - mae_s, + mae_s_sel, bar_width, label='Skip', linewidth=lmdk_lib.line_width ) + plt.bar( + x_i + x_offset, + mae_s, + bar_width, + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', + linewidth=lmdk_lib.line_width + ) x_offset += bar_width plt.bar( x_i + x_offset, - mae_u, + mae_u_sel, bar_width, label='Uniform', linewidth=lmdk_lib.line_width ) + plt.bar( + x_i + x_offset, + mae_u, + bar_width, + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', + linewidth=lmdk_lib.line_width + ) x_offset += bar_width plt.bar( x_i + x_offset, - mae_a, + mae_a_sel, bar_width, label='Adaptive', linewidth=lmdk_lib.line_width ) + plt.bar( + x_i + x_offset, + mae_a, + bar_width, + color='none', + linestyle='dashed', + edgecolor='#bdbdbd', + linewidth=lmdk_lib.line_width + ) + x_offset += bar_width path = str('../../rslt/bgt_cmp/' + d) # Plot legend @@ -156,7 +193,7 @@ def main(args): # Show plot # plt.show() # Save plot - lmdk_lib.save_plot(path + '-sel.pdf') + lmdk_lib.save_plot(path + '-sel-cmp.pdf') print('[OK]', flush=True)