code: Comparing Wasserstein and Euclidean distance
This commit is contained in:
parent
9ed4fc242b
commit
6a865d4925
@ -32,7 +32,8 @@ def main(args):
|
|||||||
plt.xlabel('Landmarks (%)') # Set x axis label.
|
plt.xlabel('Landmarks (%)') # Set x axis label.
|
||||||
plt.xlim(x_i.min() - x_margin, x_i.max() + x_margin)
|
plt.xlim(x_i.min() - x_margin, x_i.max() + x_margin)
|
||||||
# The y axis
|
# 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
|
# Bar offset
|
||||||
x_offset = -(bar_width/2)*(len(dist_type) - 1)
|
x_offset = -(bar_width/2)*(len(dist_type) - 1)
|
||||||
for d_i, d in enumerate(dist_type):
|
for d_i, d in enumerate(dist_type):
|
||||||
@ -50,8 +51,9 @@ def main(args):
|
|||||||
hist, h = lmdk_lib.get_hist(seq, lmdks)
|
hist, h = lmdk_lib.get_hist(seq, lmdks)
|
||||||
opts = lmdk_sel.get_opts_from_top_h(seq, lmdks)
|
opts = lmdk_sel.get_opts_from_top_h(seq, lmdks)
|
||||||
delta = 1.0
|
delta = 1.0
|
||||||
res, _ = exp_mech.exponential_pareto(hist, opts, exp_mech.score, delta, epsilon)
|
res, _ = exp_mech.exponential(hist, opts, exp_mech.score, delta, epsilon)
|
||||||
mae[n_i] += lmdk_lib.get_norm(hist, res)/args.reps
|
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)
|
print('[OK]', flush=True)
|
||||||
# Plot bar for current distribution
|
# Plot bar for current distribution
|
||||||
plt.bar(
|
plt.bar(
|
||||||
@ -63,7 +65,7 @@ def main(args):
|
|||||||
)
|
)
|
||||||
# Change offset for next bar
|
# Change offset for next bar
|
||||||
x_offset += bar_width
|
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
|
# Plot legend
|
||||||
lmdk_lib.plot_legend()
|
lmdk_lib.plot_legend()
|
||||||
# Show plot
|
# Show plot
|
||||||
|
@ -6,6 +6,7 @@ import exp_mech
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import random
|
import random
|
||||||
import time
|
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 = np.copy(hist_cur)
|
||||||
hist_tmp[i] += 1
|
hist_tmp[i] += 1
|
||||||
# Find difference from original
|
# 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
|
# Remember if it is the best that you've seen
|
||||||
if diff_cur < diff_min:
|
if diff_cur < diff_min:
|
||||||
diff_min = diff_cur
|
diff_min = diff_cur
|
||||||
@ -331,6 +333,12 @@ def find_lmdks(seq, lmdks, epsilon):
|
|||||||
return lmdks_new, epsilon - eps_sel
|
return lmdks_new, epsilon - eps_sel
|
||||||
|
|
||||||
def test():
|
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
|
# Start and end points of the sequence
|
||||||
# # Nonrandom
|
# # Nonrandom
|
||||||
# start = 1
|
# start = 1
|
||||||
|
BIN
rslt/lmdk_sel_cmp/lmdk_sel_cmp-emd.pdf
Normal file
BIN
rslt/lmdk_sel_cmp/lmdk_sel_cmp-emd.pdf
Normal file
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user