<jupyter_start><jupyter_text>Minimax 1: T dependence<jupyter_code>all_xs_T = []
K = 2
N_runs = 10
Ts = [100, 500, 5000]
result_minimax1 = []
for T in Ts:
    xs = np.linspace(0.1, min(6, 0.7 * np.sqrt(T / K)), 5)
    all_xs_T.append(xs)
    band_list = [ bands.BernoulliBand(2, np.array([0.8, 0.8 - x * np.sqrt(K / T)])) for x in xs]
    alg_list = [algs.KLUCBswitch(K, label="KLUCBswitch"),
            algs.UCB_a(K, label="UCB"),
            algs.KLUCB(K, label="KLUCB"),
            algs.KLUCBPlusPlus(K, label="KLUCB++"),
            algs.MOSS_a(K, sig=1/2, label="MOSS"),
            algs.Exp3(K, M=1, label="Exp3"),
            algs.FastFTRLTsallis(K, M=1, label="Tsallis-INF"),
           ]
    N_tests = [N_runs for _ in band_list]
    data_dict={
         'name':'<NAME>',
         'short_name':'minimax_experiment1'+str(T),
         'T':T,
         'N_tests':N_tests,
         'band_list':band_list,
         'alg_list':alg_list,
         'results':None,
     }
    launch(data_dict, n_jobs=1, checkpoints=False)
    result_minimax1.append(data_dict)
    print("T = {} is done".format(T))
print('Done')
colors = plt.get_cmap("tab10").colors
fig, axs = plt.subplots(1, 3, figsize=(18, 6), sharey=True)
for k, T in enumerate(Ts):
    data_dict = result_minimax1[k]
    for j, alg in enumerate(alg_list):
        reg_to_plot = []
        var_to_plot = []
        for i, band in enumerate(band_list):
            mean_reg, var_reg = data_dict["results"][i][j]
            reg_to_plot.append(mean_reg[-1])
            sig = np.sqrt(var_reg / data_dict["N_tests"][i])
            var_to_plot.append(sig[-1])
        scaling = np.sqrt(K * T) 
        xs = all_xs_T[k]
        reg_to_plot = np.array(reg_to_plot)
        var_to_plot = np.array(var_to_plot)
        axs[k].set_title("T = {}".format(T))
        axs[k].plot(xs, reg_to_plot / scaling, color=colors[j], label=alg.label)
        axs[k].fill_between(xs, (reg_to_plot - var_to_plot) /  scaling, (reg_to_plot + var_to_plot) / scaling, color=colors[j], alpha=0.3)
axs[0].legend(loc='upper left')
plt.show()<jupyter_output><empty_output><jupyter_text>Minimax 2: K dependence<jupyter_code>all_xs_K = []
Ks = np.linspace(0.1, 6, 5)
Ks = [2, 10, 50]
N_runs = 10
T = 2000
result_minimax2 = []
for K in Ks:
    xs = np.linspace(0.1, min(6, 0.7 * np.sqrt(T / K)), 5)
    all_xs_K.append(xs)
    band_list = [ bands.BernoulliBand(2, np.array([0.8] + [0.8 - x * np.sqrt(K / T)]*(K-1))) for x in xs]
    alg_list = [
            algs.KLUCBswitch(K, label="KLUCBswitch"),
            algs.UCB_a(K, label="UCB"),
            algs.KLUCB(K, label="KLUCB"),
            algs.KLUCBPlusPlus(K, label="KLUCB++"),
            algs.MOSS_a(K, sig=1/2, label="MOSS"),
            algs.Exp3(K, M=1, label="Exp3"),
            algs.FastFTRLTsallis(K, M=1, label="Tsallis-INF"),
           ]
    N_tests = [N_runs for _ in band_list]
    data_dict={
         'name':'<NAME>',
         'short_name':'minimax_experiment2'+str(K),
         'T':T,
         'N_tests':N_tests,
         'band_list':band_list,
         'alg_list':alg_list,
         'results':None,
     }
    launch(data_dict, n_jobs=1, checkpoints=False)
    result_minimax2.append(data_dict)
    print("K = "+str(K)+" is done")
colors = plt.get_cmap("tab10").colors
fig, axs = plt.subplots(1, 3, figsize=(18, 6), sharey=True)
for k, K in enumerate(Ks):
    data_dict = result_minimax2[k]
    T = data_dict['T']
    for j, alg in enumerate(alg_list):
        reg_to_plot = []
        var_to_plot = []
        for i, band in enumerate(band_list):
            mean_reg, var_reg = data_dict["results"][i][j]
            reg_to_plot.append(mean_reg[-1])
            sig = np.sqrt(var_reg[-1] / data_dict["N_tests"][i])
            var_to_plot.append(sig)
        scaling = np.sqrt(K * T) 
        reg_to_plot = np.array(reg_to_plot)
        var_to_plot = np.array(var_to_plot)
        xs = all_xs_K[k]
        axs[k].set_title("K = {}".format(K))
        axs[k].plot(xs, reg_to_plot / scaling, color=colors[j], label=alg.label)
        axs[k].fill_between(xs, (reg_to_plot - var_to_plot) /  scaling, (reg_to_plot + var_to_plot) / scaling, color=colors[j], alpha=0.3)
axs[0].legend(loc='upper left')
plt.show()<jupyter_output><empty_output><jupyter_text>Switching Profile Case I: large gapArm 1 is the best arm.<jupyter_code>T = 5000
N = 100
K = 3
mus_ber = np.array([0.9]+ [0.3]*(K-1))
bandit = bands.BernoulliBand(2, mus_ber)

results_large_gap = np.zeros((N, T-K, K))
for i in range(N):
    alg = algs.KLUCBswitchProfile(K, label="KLUCBswitch")
    alg.play_T_times(bandit, T)
    for a in range(K):
        results_large_gap[i, :, a] = alg.profile[a]

print('Done')
fig, axs = plt.subplots(K, 1, figsize=(15, 3*K), sharey=True)
for a in range(K):
    axs[a].plot(np.mean(results_large_gap[:, :, a], axis=0))
fig.suptitle('Average switching profile over 100 runs: 0 is KL / 1 is MOSS')
plt.show()<jupyter_output><empty_output><jupyter_text>Case II: small gapArm 1 is the best arm. Both arms are always in MOSS mode.<jupyter_code>T = 5000
N = 100
K = 3
mus_ber = np.array([0.9]+ [0.8]*(K-1))
bandit = bands.BernoulliBand(2, mus_ber)

results_small_gap = np.zeros((N, T-K, K))
for i in range(N):
    alg = algs.KLUCBswitchProfile(K, label="KLUCBswitch")
    alg.play_T_times(bandit, T)
    for a in range(K):
        results_small_gap[i, :, a] = alg.profile[a]

print('Done')
fig, axs = plt.subplots(K, 1, figsize=(15, 3*K), sharey=True)
for a in range(K):
    axs[a].plot(np.mean(results_small_gap[:, :, a], axis=0))
fig.suptitle('Average switching profile over 100 runs: 0 is KL / 1 is MOSS')
plt.show()<jupyter_output><empty_output><jupyter_text>Testing Tsallis-INF<jupyter_code>#K = 2
#tsallis = algs.FastFTRLTsallis(K, M=1, label="Tsallis-INF")
#tsallis.verb = True
#
#bandit = bands.TruncatedGaussian(K_gauss, mus_gauss, sig_gauss)
#
#T = 1000
#
#for t in range(T):
#    tsallis.play_once(bandit)
#    print(t)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16753662232699107, 'fraction_numerical': 0.02609866980973228, 'mean_word_length': 3.14804469273743, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '109371', 'license': 'MIT', 'n_tokens_mistral': 2591, 'n_tokens_neox': 2455, 'n_words': 446, 'path': 'notebooks/KLUCB.ipynb', 'repo_name': 'H2DI/bandits_lab', 'size': '5945'}