diff --git a/code/expt/lmdk_sel_cmp.py b/code/expt/lmdk_sel_cmp.py index cf9c878..b50a600 100644 --- a/code/expt/lmdk_sel_cmp.py +++ b/code/expt/lmdk_sel_cmp.py @@ -32,7 +32,8 @@ def main(args): 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.yscale('log') + plt.ylabel('Euclidean distance') # Set y axis label. # Bar offset x_offset = -(bar_width/2)*(len(dist_type) - 1) for d_i, d in enumerate(dist_type): @@ -50,8 +51,9 @@ def main(args): 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, epsilon) - mae[n_i] += lmdk_lib.get_norm(hist, res)/args.reps + res, _ = exp_mech.exponential(hist, opts, exp_mech.score, delta, epsilon) + mae[n_i] += lmdk_lib.get_norm(hist, res)/args.reps # Euclidean + # mae[n_i] += lmdk_lib.get_emd(hist, res)/args.reps # Wasserstein print('[OK]', flush=True) # Plot bar for current distribution plt.bar( @@ -63,7 +65,7 @@ def main(args): ) # Change offset for next bar x_offset += bar_width - path = str('../../rslt/lmdk_sel_cmp-pareto/' + 'lmdk_sel_cmp') + path = str('../../rslt/lmdk_sel_cmp/' + 'lmdk_sel_cmp-norm') # Plot legend lmdk_lib.plot_legend() # Show plot diff --git a/code/lib/lmdk_sel.py b/code/lib/lmdk_sel.py index 91638f4..b45a79d 100644 --- a/code/lib/lmdk_sel.py +++ b/code/lib/lmdk_sel.py @@ -6,6 +6,7 @@ import exp_mech import numpy as np import random import time +from scipy.spatial.distance import cdist ''' @@ -174,7 +175,8 @@ def get_opts_from_top_h(seq, lmdks): hist_tmp = np.copy(hist_cur) hist_tmp[i] += 1 # Find difference from original - diff_cur = get_norm(hist, hist_tmp) + diff_cur = get_norm(hist, hist_tmp) # Euclidean + # diff_cur = get_emd(hist, hist_tmp) # Wasserstein # Remember if it is the best that you've seen if diff_cur < diff_min: diff_min = diff_cur @@ -331,6 +333,12 @@ def find_lmdks(seq, lmdks, epsilon): return lmdks_new, epsilon - eps_sel def test(): + + A = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) + B = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + print(get_norm(A, B)) + exit() + # Start and end points of the sequence # # Nonrandom # start = 1 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..27efa2b 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.pdf b/rslt/lmdk_sel_cmp/lmdk_sel_cmp-norm.pdf similarity index 77% rename from rslt/lmdk_sel_cmp/lmdk_sel_cmp.pdf rename to rslt/lmdk_sel_cmp/lmdk_sel_cmp-norm.pdf index 658c69f..c32cb9e 100644 Binary files a/rslt/lmdk_sel_cmp/lmdk_sel_cmp.pdf and b/rslt/lmdk_sel_cmp/lmdk_sel_cmp-norm.pdf differ