"""
This python file corresponds to the Example 4 with varying sub-optimality gaps
"""

import sys
import os
import numpy as np
sys.path.append('/Your Path/Data_Code/Methods')
import TLR_UCB as TU
from Pre_Functions import contract_v


# Example 4 setting:
# pos: the position effect vector
# v: the preference vector
# r: the revenue vector
# T: horizon length
# simu_times: number of replications
pos = [1,1/2,1/3,1/4]
v = [1/2,1/2,1/2,1/2,1/4,1/4,1/4,1/4,1/4,1/4]
r = [1,1,1,1,1,1,1,1,1,1]
T = 200000
simu_times = 500

# more parameters for TLR-UCB, LR-UCB, and A-UCB-V:
# v_max: \nu_{0}, an upper bound for all items' preferences
# lam: lambda
# c_UCB: UCB constant ahead of the bonus
# rsd: np.random.seed
v_max = max(v)
lam = 1
c_UCB = 0.01
rsd = 0


# construct contraction parameters
n = 5
cc = [(n-i)/n for i in range(n)]
print("Contraction parameters:", cc)

for i in range(n):
    # shrink the preference vector to vary the suboptimality gap
    v_new = contract_v(v, cc[i])
    print("New preferences:", v_new)

    # apply TLR-UCB policy
    reg_mean_TLR_UCB_Ex4 = TU.TLR_UCB(pos, v_new, r, v_max, T, simu_times, lam, c_UCB, rsd)
    print(np.sum(reg_mean_TLR_UCB_Ex4))

    # save the results
    os.chdir('/Your Path/Data_Code/Simulation/Results')
    s = "TLR-UCB_Ex4_reg_mean_" + str(i + 1) + ".npy"
    np.save(s, reg_mean_TLR_UCB_Ex4)



