expt: Testing bottom to top approach

This commit is contained in:
Manos Katsomallos 2021-10-07 18:34:48 +02:00
parent 3d745c5fff
commit 8dfb70cc4a
3 changed files with 35 additions and 0 deletions

View File

@ -269,6 +269,41 @@ def get_opts_from_bottom(seq, lmdks):
return opts return opts
def get_opts_from_bottom_h(seq, lmdks):
# Create histogram
hist, h = get_hist(seq, lmdks)
# Keep track of points
hist_cur = np.array([h]*len(hist))
while np.sum(hist_cur) > len(seq):
hist_cur[-1] -= 1
# The options to be returned
hist_opts = []
# Keep removing points until the minimum is reached
while np.sum(hist_cur) > np.sum(hist):
# Track the minimum (best) evaluation
diff_min = float('inf')
# The candidate option
hist_cand = np.copy(hist_cur)
# Check every possibility
for i, h_i in enumerate(hist_cur):
# Can we remove one more point?
if h_i - 1 >= hist[i]:
hist_tmp = np.copy(hist_cur)
hist_tmp[i] -= 1
# Find difference from original
# 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
hist_cand = np.copy(hist_tmp)
# Update current histogram
hist_cur = np.copy(hist_cand)
# Add current best to options
hist_opts.append(hist_cand)
# Return options
return hist_opts
def get_non_opts_from_bottom(seq, lmdks): def get_non_opts_from_bottom(seq, lmdks):
# Evaluate the original # Evaluate the original
eval_orig = eval_seq(get_rel_dists(seq, [], lmdks)) eval_orig = eval_seq(get_rel_dists(seq, [], lmdks))

Binary file not shown.

Binary file not shown.