Esempio n. 1
0
N = 100000
DIR_EXP2 = "experiment_K/"
os.system("mkdir -p " + DIR_EXP2)

aggregates_time = dict()
for algo in algos:
    aggregates_time[algo] = list()
aggregates_all = dict()
for K in K_vals:
    scenario = "_K_" + str(K)
    input_file = DIR_EXP2 + "scenario" + scenario + ".txt"
    f = open(input_file, "w")
    f.write(str(K) + "\n1" + "\n0.9" + "\n0.8" * (K - 1))
    f.close()
    R_list = dict()
    for algo in algos:
        print("*" * 10 + " Scenario", scenario, "N=", N, "algo=", algo)
        output_file = DIR_EXP2 + "scenario" + scenario + "_N_" + str(
            N) + "_" + algo + ".txt"
        #os.system("python3 " + algo + ".py " + str(nb_runs) + " " + str(N) + " " + input_file + " " + output_file + " " + str(set_random))
        R_list[algo], aggregate_time, aggregates_all[algo] = parse_json_output(
            output_file)
        aggregates_time[algo].append(aggregate_time)
    # check that all algorithms output the same result if the random seed is fixed
    if set_random == 0:
        check_results(R_list, algos)

# generate plot
plot_lines_K("K_varies", algos, algos_names, "Number of arms K", False, K_vals,
             aggregates_time, DIR_EXP2)
Esempio n. 2
0
os.system("mkdir -p " + DIR_EXP)

for scenario in scenarios:
    input_file = DIR_EXP + "scenario_" + scenario + ".txt"
    f = open(input_file, "w")
    if scenario == "uniform":
        f.write(str(K) + "\n0" + "\n5" + "\n30" + "\n28" * (K - 1))
    elif scenario == "bernoulli":
        f.write(str(K) + "\n1" + "\n0.9" + "\n0.8" * (K - 1))
    f.close()
    aggregates_time = dict()
    for algo in algos:
        aggregates_time[algo] = list()
    aggregates_all = dict()
    for N in N_vals:
        R_list = dict()
        for algo in algos:
            print("*" * 10 + " Scenario=", scenario, "N=", N, "algo=", algo)
            output_file = DIR_EXP + "scenario_" + scenario + "_N_" + str(
                N) + "_" + algo + ".txt"
            #os.system("python3 " + algo + ".py " + str(nb_runs) + " " + str(N) + " " + input_file + " " + output_file + " " + str(set_random))
            R_list[algo], aggregate_time, aggregates_all[
                algo] = parse_json_output(output_file)
            aggregates_time[algo].append(aggregate_time)
        # check that all algorithms output the same result if the random seed is fixed
        if set_random == 0:
            check_results(R_list, algos)
    # generate plot
    plot_lines_and_pie(scenario, algos, algos_names, "Budget N", False, N_vals,
                       aggregates_time, aggregates_all, "N=" + str(N), DIR_EXP)
Esempio n. 3
0
K_vals = [50, 6]
d_vals = [5, 18]
N = 200

DIR_exp = "experiment_n_cores/"
os.system("mkdir -p " + DIR_exp)

keys = ["theta", "Bi", "dec"]

for i in range(len(K_vals)):
    DIR = DIR_exp + "linucb_" + str(K_vals[i]) + "_" + str(d_vals[i]) + "/"
    os.system("mkdir -p " + DIR)
    aggregates_all = dict()
    for key in keys:
        aggregates_all[key] = list()
    for n_cores in n_cores_vals:
        print("*" * 10 + "n =", n_cores, "K =", K_vals[i], "d =", d_vals[i])
        output_file = DIR + "n=" + str(n_cores) + "_d=" + str(
            d_vals[i]) + "_K=" + str(
                K_vals[i]) + "_N=" + str(N) + "_" + algo + ".txt"
        #os.system("python3 " + algo + ".py " + str(nb_runs) + " " + str(N) + " "
        #          + str(K_vals[i]) + " " +str(d_vals[i]) + " " + output_file + " "
        #          + str(key_size) + " " + str(n_cores) + " " + str(0) + " " + str(0))
        _, res = parse_json_output(output_file)
        for key in keys:
            aggregates_all[key].append(res["time of " + str(key)])

    # generate plot
    plot_stack_lines("stack_lines_" + str(K_vals[i]) + "_" + str(d_vals[i]),
                     "Number of cores", n_cores_vals, aggregates_all, DIR)
algos = [
    "linucb_ds", "spectralucb_ds", "linucb_ds_parall", "spectralucb_ds_parall"
]
algos_names = [
    "LinUCB-DS 1 core", "SpectralUCB-DS 1 core", "LinUCB-DS 6 cores",
    "SpectralUCB-DS 6 cores"
]
K_vals = [10, 20, 30]

DIR = "experiment_spectral/"
os.system("mkdir -p " + DIR)

aggregates_time = dict()
for algo in algos:
    aggregates_time[algo] = list()
for K in K_vals:
    d = K
    N = K
    for algo in algos:
        print("*" * 10 + "K=", K, "algo=", algo)
        output_file = DIR + "N_K_d=" + str(K) + "_" + algo + ".txt"
        #os.system("python3 " + algo + ".py " + str(nb_runs) + " " + str(N)
        #          + " " + str(K) + " " + str(d) + " " + output_file + " "
        #          + str(key_size) + " " + str(n_cores) + " " + str(0) + " " + str(0))
        aggregate_time, _ = parse_json_output(output_file)
        aggregates_time[algo].append(aggregate_time)

# generate plot
plot_lines(str(key_size), algos_names, "", "N = K = d", K_vals,
           aggregates_time, False, False, DIR)
Esempio n. 5
0
    aggregates_time["SR_SP_" + str(K)] = list()
    aggregates_time["SR_Secure_ISPEC_" + str(K)] = list()
    input_file = DIR + "scenario_K=" + str(K) + ".txt"
    f = open(input_file, "w")
    f.write(str(K) + "\n0" + "\n5" + "\n40" + "\n38" * (K - 1))
    f.close()
    aggregates_all = dict()
    for N in N_vals:
        R_list = dict()
        for algo in algos:
            print("*" * 10 + " K=", K, "N=", N, "algo=", algo)
            output_file = DIR + "K_" + str(K) + "_N_" + str(
                N) + "_" + algo + ".txt"
            #os.system("python3 " + algo + ".py " + str(nb_runs) + " " + str(N) + " " + input_file + " " + output_file + " " + str(set_random))
            R_list[algo], aggregate_time, aggregates_all[
                algo] = parse_json_output(output_file)
            aggregates_time[algo + "_" + str(K)].append(aggregate_time)

# generate plot
algos = []
algos_names = []
for K in K_vals:
    algos.append("SR_Secure_ISPEC_" + str(K))
    algos.append("SR_SP_" + str(K))
    algos_names.append("K=" + str(K) + ", SR-Paillier-Old")
    algos_names.append("K=" + str(K) + ", SR-Paillier")

# plot one line for each algorithm
plt.figure(figsize=(8, 4))
plt.rcParams.update({'font.size': 14})
ax = plt.subplot(121)