From ca85703de808e9c5ed6f204ae2217761469ee42a Mon Sep 17 00:00:00 2001 From: Manos Date: Wed, 6 Oct 2021 13:14:28 +0200 Subject: [PATCH] code: WIP --- code/expt/copenhagen-sel.py | 23 ++++++----------------- code/expt/hue-sel.py | 23 ++++++----------------- code/expt/t-drive-sel.py | 23 ++++++----------------- code/lib/lmdk_sel.py | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 51 deletions(-) diff --git a/code/expt/copenhagen-sel.py b/code/expt/copenhagen-sel.py index 26597af..321b48f 100644 --- a/code/expt/copenhagen-sel.py +++ b/code/expt/copenhagen-sel.py @@ -8,6 +8,8 @@ from datetime import datetime from geopy.distance import distance import lmdk_bgt import lmdk_lib +import lmdk_sel +import exp_mech import math import numpy as np from matplotlib import pyplot as plt @@ -66,33 +68,20 @@ def main(args): for _ in range(args.iter): - eps_sel = 0 - if pct != 0 and pct != 100: - # Get landmarks timestamps in sequence - lmdks_seq = lmdk_lib.find_lmdks_seq(seq, lmdks) - # Turn landmarks to histogram - hist, h = lmdk_lib.get_hist(lmdk_lib.get_seq(1, len(seq)), lmdks_seq) - # Find all possible options - opts = lmdk_sel.get_opts_from_top_h(lmdk_lib.get_seq(1, len(seq)), lmdks_seq) - # Landmarks selection budget - eps_sel = epsilon/(len(lmdks_seq) + 1) - # Get private landmarks timestamps - lmdks_seq, _ = exp_mech.exponential_pareto(hist, opts, exp_mech.score, 1.0, eps_sel) - # Get actual landmarks values - lmdks = seq[lmdks_seq] + lmdks, eps_out = lmdk_sel.find_lmdks(seq, lmdks, epsilon) # Skip - rls_data_s, bgts_s = lmdk_bgt.skip_cont(seq, lmdks, epsilon - eps_sel) + 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 # Uniform - rls_data_u, bgts_u = lmdk_bgt.uniform_cont(seq, lmdks, epsilon - eps_sel) + 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 # Adaptive - rls_data_a, _, _ = lmdk_bgt.adaptive_cont(seq, lmdks, epsilon - eps_sel, .5, .5) + 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 # Calculate once diff --git a/code/expt/hue-sel.py b/code/expt/hue-sel.py index 240fe37..bb70f83 100644 --- a/code/expt/hue-sel.py +++ b/code/expt/hue-sel.py @@ -8,6 +8,8 @@ from datetime import datetime from geopy.distance import distance import lmdk_bgt import lmdk_lib +import lmdk_sel +import exp_mech import math import numpy as np from matplotlib import pyplot as plt @@ -62,32 +64,19 @@ def main(args): for _ in range(args.iter): - eps_sel = 0 - if pct != 0 and pct != 100: - # Get landmarks timestamps in sequence - lmdks_seq = lmdk_lib.find_lmdks_seq(seq, lmdks) - # Turn landmarks to histogram - hist, h = lmdk_lib.get_hist(lmdk_lib.get_seq(1, len(seq)), lmdks_seq) - # Find all possible options - opts = lmdk_sel.get_opts_from_top_h(lmdk_lib.get_seq(1, len(seq)), lmdks_seq) - # Landmarks selection budget - eps_sel = epsilon/(len(lmdks_seq) + 1) - # Get private landmarks timestamps - lmdks_seq, _ = exp_mech.exponential_pareto(hist, opts, exp_mech.score, 1.0, eps_sel) - # Get actual landmarks values - lmdks = seq[lmdks_seq] + lmdks, eps_out = lmdk_sel.find_lmdks(seq, lmdks, epsilon) # Skip - rls_data_s, bgts_s = lmdk_bgt.skip_cons(seq, lmdks, epsilon - eps_sel) + rls_data_s, bgts_s = lmdk_bgt.skip_cons(seq, lmdks, eps_out) # lmdk_bgt.validate_bgts(seq, lmdks, epsilon, bgts_s) mae_s[i] += lmdk_bgt.mae_cons(seq, rls_data_s)/args.iter # Uniform - rls_data_u, bgts_u = lmdk_bgt.uniform_cons(seq, lmdks, epsilon - eps_sel) + rls_data_u, bgts_u = lmdk_bgt.uniform_cons(seq, lmdks, eps_out) mae_u[i] += lmdk_bgt.mae_cons(seq, rls_data_u)/args.iter # Adaptive - rls_data_a, _, _ = lmdk_bgt.adaptive_cons(seq, lmdks, epsilon - eps_sel, .5, .5) + rls_data_a, _, _ = lmdk_bgt.adaptive_cons(seq, lmdks, eps_out, .5, .5) mae_a[i] += lmdk_bgt.mae_cons(seq, rls_data_a)/args.iter # Calculate once diff --git a/code/expt/t-drive-sel.py b/code/expt/t-drive-sel.py index 77a4a1d..1f1683c 100644 --- a/code/expt/t-drive-sel.py +++ b/code/expt/t-drive-sel.py @@ -7,6 +7,8 @@ from datetime import datetime from geopy.distance import distance import lmdk_bgt import lmdk_lib +import lmdk_sel +import exp_mech import numpy as np from matplotlib import pyplot as plt import time @@ -85,31 +87,18 @@ def main(args): for bgt in bgt_conf: for _ in range(args.iter): - eps_sel = 0 - if lmdk != 0 and lmdk != 100: - # Get landmarks timestamps in sequence - lmdks_seq = lmdk_lib.find_lmdks_seq(seq, lmdks) - # Turn landmarks to histogram - hist, h = lmdk_lib.get_hist(lmdk_lib.get_seq(1, len(seq)), lmdks_seq) - # Find all possible options - opts = lmdk_sel.get_opts_from_top_h(lmdk_lib.get_seq(1, len(seq)), lmdks_seq) - # Landmarks selection budget - eps_sel = bgt['epsilon']/(len(lmdks_seq) + 1) - # Get private landmarks timestamps - lmdks_seq, _ = exp_mech.exponential_pareto(hist, opts, exp_mech.score, 1.0, eps_sel) - # Get actual landmarks values - lmdks = seq[lmdks_seq] + lmdks, eps_out = lmdk_sel.find_lmdks(seq, lmdks, bgt['epsilon']) # Skip - rls_data_s, _ = lmdk_bgt.skip(seq, lmdks, bgt['epsilon'] - eps_sel) + rls_data_s, _ = lmdk_bgt.skip(seq, lmdks, eps_out) mae_s[i] += lmdk_bgt.mae(seq, rls_data_s)/args.iter # Uniform - rls_data_u, _ = lmdk_bgt.uniform_r(seq, lmdks, bgt['epsilon'] - eps_sel) + rls_data_u, _ = lmdk_bgt.uniform_r(seq, lmdks, eps_out) mae_u[i] += lmdk_bgt.mae(seq, rls_data_u)/args.iter # Adaptive - rls_data_a, _, _ = lmdk_bgt.adaptive(seq, lmdks, bgt['epsilon'] - eps_sel, .5, .5) + rls_data_a, _, _ = lmdk_bgt.adaptive(seq, lmdks, eps_out, .5, .5) mae_a[i] += lmdk_bgt.mae(seq, rls_data_a)/args.iter # Event diff --git a/code/lib/lmdk_sel.py b/code/lib/lmdk_sel.py index 2685844..421ab7e 100644 --- a/code/lib/lmdk_sel.py +++ b/code/lib/lmdk_sel.py @@ -2,6 +2,7 @@ import itertools from lmdk_lib import * +import exp_mech import numpy as np import random import time @@ -297,6 +298,23 @@ def get_non_opts_from_bottom(seq, lmdks): return non_opts +def find_lmdks(seq, lmdks, epsilon): + eps_sel = 0 + if len(lmdks) > 0 and len(seq) != len(lmdks): + # Get landmarks timestamps in sequence + lmdks_seq = find_lmdks_seq(seq, lmdks) + # Turn landmarks to histogram + hist, h = get_hist(get_seq(1, len(seq)), lmdks_seq) + # Find all possible options + opts = get_opts_from_top_h(get_seq(1, len(seq)), lmdks_seq) + # Landmarks selection budget + eps_sel = epsilon/(len(lmdks_seq) + 1) + # Get private landmarks timestamps + lmdks_seq, _ = exp_mech.exponential_pareto(hist, opts, exp_mech.score, 1.0, eps_sel) + # Get actual landmarks values + lmdks = seq[lmdks_seq] + return lmdks, epsilon - eps_sel + def test(): # Start and end points of the sequence # # Nonrandom