diff --git a/code/expt/copenhagen-sel.py b/code/expt/copenhagen-sel.py index cd69c7b..99141fd 100644 --- a/code/expt/copenhagen-sel.py +++ b/code/expt/copenhagen-sel.py @@ -73,31 +73,25 @@ def main(args): # Skip rls_data_s, bgts_s = lmdk_bgt.skip_cont(seq, lmdks, eps_out) # lmdk_bgt.validate_bgts(seq, lmdks, epsilon, bgts_s) - mae_s[i] += lmdk_bgt.mae_cont(rls_data_s)/args.iter + mae_s[i] += (lmdk_bgt.mae_cont(rls_data_s)/args.iter)*100 # Uniform rls_data_u, bgts_u = lmdk_bgt.uniform_cont(seq, lmdks, eps_out) # lmdk_bgt.validate_bgts(seq, lmdks, epsilon, bgts_u) - mae_u[i] += lmdk_bgt.mae_cont(rls_data_u)/args.iter + mae_u[i] += (lmdk_bgt.mae_cont(rls_data_u)/args.iter)*100 # Adaptive 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 + mae_a[i] += (lmdk_bgt.mae_cont(rls_data_a)/args.iter)*100 # Calculate once if i == 0: # Event rls_data_evt, _ = lmdk_bgt.uniform_cont(seq, lmdk_lib.find_lmdks_cont(lmdk_data, seq, uid, 0), epsilon) - mae_evt += lmdk_bgt.mae_cont(rls_data_evt)/args.iter + mae_evt += (lmdk_bgt.mae_cont(rls_data_evt)/args.iter)*100 # User rls_data_usr, _ = lmdk_bgt.uniform_cont(seq, lmdk_lib.find_lmdks_cont(lmdk_data, seq, uid, 100), epsilon) - mae_usr += lmdk_bgt.mae_cont(rls_data_usr)/args.iter - - mae_u *= 100 - mae_s *= 100 - mae_a *= 100 - mae_evt *= 100 - mae_usr *= 100 + mae_usr += (lmdk_bgt.mae_cont(rls_data_usr)/args.iter)*100 plt.axhline( y = mae_evt, @@ -144,7 +138,7 @@ def main(args): # # Show plot # plt.show() # Save plot - lmdk_lib.save_plot(path + '-sel-emd.pdf') + lmdk_lib.save_plot(path + '-sel.pdf') print('[OK]', flush=True) diff --git a/code/expt/copenhagen.py b/code/expt/copenhagen.py index 0da5a07..aa9b514 100644 --- a/code/expt/copenhagen.py +++ b/code/expt/copenhagen.py @@ -27,7 +27,7 @@ def main(args): # The landmarks percentages lmdks_pct = [0, 20, 40, 60, 80, 100] # The privacy budget - epsilon = .1 + epsilon = 1.0 # Number of methods n = 3 @@ -87,7 +87,7 @@ def main(args): # User rls_data_usr, _ = lmdk_bgt.uniform_cont(seq, lmdk_lib.find_lmdks_cont(lmdk_data, seq, uid, 100), epsilon) mae_usr += (lmdk_bgt.mae_cont(rls_data_usr)/args.iter)*100 - exit() + plt.axhline( y = mae_evt, color = '#212121', diff --git a/code/expt/expt_lmdk_sel-pareto.py b/code/expt/expt_lmdk_sel-pareto.py deleted file mode 100644 index 0bc4ff7..0000000 --- a/code/expt/expt_lmdk_sel-pareto.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python3 - -import sys -sys.path.insert(1, '../lib') -import argparse -import lmdk_lib -import lmdk_sel -import exp_mech -import numpy as np -import os -from matplotlib import pyplot as plt -import time - - -def main(args): - # Privacy goal - epsilon = [.001, .01, .1, 1.0, 10.0, 100.0] - # Number of timestamps - seq = lmdk_lib.get_seq(1, args.time) - # Distribution type - dist_type = np.array(range(-1, 4)) - # Number of landmarks - lmdk_n = np.array(range(int(.2*args.time), args.time, int(args.time/5))) - # Width of bars - bar_width = 1/(len(epsilon) + 1) - # The x axis - x_i = np.arange(len(lmdk_n)) - x_margin = bar_width*(len(epsilon)/2 + 1) - for d_i, d in enumerate(dist_type): - # Logging - title = lmdk_lib.dist_type_to_str(d) + ' landmark distribution' - print('(%d/%d) %s... ' %(d_i + 1, len(dist_type), title), end='', flush=True) - # Initialize plot - lmdk_lib.plot_init() - # The x axis - plt.xticks(x_i, ((lmdk_n/len(seq))*100).astype(int)) - plt.xlabel('Landmarks (%)') # Set x axis label. - plt.xlim(x_i.min() - x_margin, x_i.max() + x_margin) - # The y axis - plt.ylabel('Mean absolute error') # Set y axis label. - # plt.ylim(0, len(seq)*1.5) - # Bar offset - x_offset = -(bar_width/2)*(len(epsilon) - 1) - for e_i, e in enumerate(epsilon): - mae = np.zeros(len(lmdk_n)) - for n_i, n in enumerate(lmdk_n): - for r in range(args.reps): - lmdks = lmdk_lib.get_lmdks(seq, n, d) - hist, h = lmdk_lib.get_hist(seq, lmdks) - opts = lmdk_sel.get_opts_from_top_h(seq, lmdks) - delta = 1.0 - res, _ = exp_mech.exponential_pareto(hist, opts, exp_mech.score, delta, e) - mae[n_i] += lmdk_lib.get_norm(hist, res)/args.reps - # Plot bar for current epsilon - plt.bar( - x_i + x_offset, - mae, - bar_width, - label=u'\u03B5 = ' + str("{:.0e}".format(e)), - linewidth=lmdk_lib.line_width - ) - # Change offset for next bar - x_offset += bar_width - path = str('../../rslt/lmdk_sel-pareto/' + title) - # Plot legend - lmdk_lib.plot_legend() - # Show plot - # plt.show() - # Save plot - lmdk_lib.save_plot(path + '.pdf') - print('[OK]', flush=True) - - -''' - Parse arguments. - - Optional: - reps - The number of repetitions. - time - The time limit of the sequence. -''' -def parse_args(): - # Create argument parser. - parser = argparse.ArgumentParser() - - # Mandatory arguments. - - # Optional arguments. - parser.add_argument('-r', '--reps', help='The number of repetitions.', type=int, default=1) - parser.add_argument('-t', '--time', help='The time limit of the sequence.', type=int, default=100) - - # Parse arguments. - args = parser.parse_args() - - return args - - -if __name__ == '__main__': - try: - start_time = time.time() - main(parse_args()) - end_time = time.time() - print('##############################') - print('Time elapsed: %s' % (time.strftime('%H:%M:%S', time.gmtime(end_time - start_time)))) - print('##############################') - except KeyboardInterrupt: - print('Interrupted by user.') - exit() diff --git a/code/expt/hue-sel.py b/code/expt/hue-sel.py index 70d15e9..38bbb1c 100644 --- a/code/expt/hue-sel.py +++ b/code/expt/hue-sel.py @@ -48,7 +48,7 @@ def main(args): # The y axis plt.ylabel('Mean absolute error (kWh)') # Set y axis label. plt.yscale('log') - # plt.ylim(.01, 10000) + plt.ylim(.01, 1000) # Bar offset x_offset = -(bar_width/2)*(n - 1) @@ -134,7 +134,7 @@ def main(args): # Show plot # plt.show() # Save plot - lmdk_lib.save_plot(path + '-sel-emd.pdf') + lmdk_lib.save_plot(path + '-sel.pdf') print('[OK]', flush=True) diff --git a/code/expt/hue.py b/code/expt/hue.py index 56e3751..3c2e053 100644 --- a/code/expt/hue.py +++ b/code/expt/hue.py @@ -46,7 +46,7 @@ def main(args): # The y axis plt.ylabel('Mean absolute error (kWh)') # Set y axis label. plt.yscale('log') - # plt.ylim(.01, 10000) + plt.ylim(.01, 1000) # Bar offset x_offset = -(bar_width/2)*(n - 1) @@ -162,7 +162,7 @@ if __name__ == '__main__': main(parse_args()) end_time = time.time() print('##############################') - print('Time : %.4fs' % (end_time - start_time)) + print('Time elapsed: %s' % (time.strftime('%H:%M:%S', time.gmtime(end_time - start_time)))) print('##############################') except KeyboardInterrupt: print('Interrupted by user.') diff --git a/code/expt/lmdk_sel_cmp.py b/code/expt/lmdk_sel_cmp.py index b50a600..a7d9d71 100644 --- a/code/expt/lmdk_sel_cmp.py +++ b/code/expt/lmdk_sel_cmp.py @@ -34,6 +34,7 @@ def main(args): # The y axis # plt.yscale('log') plt.ylabel('Euclidean distance') # Set y axis label. + # plt.ylabel('Wasserstein distance') # Set y axis label. # Bar offset x_offset = -(bar_width/2)*(len(dist_type) - 1) for d_i, d in enumerate(dist_type): @@ -66,6 +67,7 @@ def main(args): # Change offset for next bar x_offset += bar_width path = str('../../rslt/lmdk_sel_cmp/' + 'lmdk_sel_cmp-norm') + # path = str('../../rslt/lmdk_sel_cmp/' + 'lmdk_sel_cmp-emd') # Plot legend lmdk_lib.plot_legend() # Show plot diff --git a/code/expt/t-drive-sel.py b/code/expt/t-drive-sel.py index ce41560..1f1683c 100644 --- a/code/expt/t-drive-sel.py +++ b/code/expt/t-drive-sel.py @@ -155,7 +155,7 @@ def main(args): # Show plot # plt.show() # Save plot - lmdk_lib.save_plot(path + '-sel-emd.pdf') + lmdk_lib.save_plot(path + '-sel.pdf') print('[OK]', flush=True) diff --git a/code/expt/t-drive.py b/code/expt/t-drive.py index 55a8fcb..4843cb4 100644 --- a/code/expt/t-drive.py +++ b/code/expt/t-drive.py @@ -188,7 +188,7 @@ if __name__ == '__main__': main(parse_args()) end_time = time.time() print('##############################') - print('Time : %.4fs' % (end_time - start_time)) + print('Time elapsed: %s' % (time.strftime('%H:%M:%S', time.gmtime(end_time - start_time)))) print('##############################') except KeyboardInterrupt: print('Interrupted by user.') diff --git a/rslt/bgt_cmp/Copenhagen-sel.pdf b/rslt/bgt_cmp/Copenhagen-sel.pdf new file mode 100644 index 0000000..dd6cb5d Binary files /dev/null and b/rslt/bgt_cmp/Copenhagen-sel.pdf differ diff --git a/rslt/bgt_cmp/Copenhagen.pdf b/rslt/bgt_cmp/Copenhagen.pdf index a4bdeb6..cb68cc3 100644 Binary files a/rslt/bgt_cmp/Copenhagen.pdf and b/rslt/bgt_cmp/Copenhagen.pdf differ diff --git a/rslt/bgt_cmp/HUE-sel.pdf b/rslt/bgt_cmp/HUE-sel.pdf new file mode 100644 index 0000000..3d5a448 Binary files /dev/null and b/rslt/bgt_cmp/HUE-sel.pdf differ diff --git a/rslt/bgt_cmp/HUE.pdf b/rslt/bgt_cmp/HUE.pdf index fef1ce6..6ca38a5 100644 Binary files a/rslt/bgt_cmp/HUE.pdf and b/rslt/bgt_cmp/HUE.pdf differ diff --git a/rslt/lmdk_sel_cmp/lmdk_sel_cmp-emd.pdf b/rslt/lmdk_sel_cmp/lmdk_sel_cmp-emd.pdf new file mode 100644 index 0000000..b49ce11 Binary files /dev/null and b/rslt/lmdk_sel_cmp/lmdk_sel_cmp-emd.pdf differ diff --git a/rslt/lmdk_sel_cmp/lmdk_sel_cmp-norm.pdf b/rslt/lmdk_sel_cmp/lmdk_sel_cmp-norm.pdf new file mode 100644 index 0000000..dddda0c Binary files /dev/null and b/rslt/lmdk_sel_cmp/lmdk_sel_cmp-norm.pdf differ