code: Comparing Wasserstein and Euclidean distance
This commit is contained in:
		@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											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.
										
									
								
							
		Reference in New Issue
	
	Block a user