"""
This python file corresponds to the regret rate of EI-TLR under Example 3
"""

import sys
import os
import numpy as np
sys.path.append('/Your Path/Data_Code/Methods')
import EI_TLR as ET

from math import ceil


# Example 3 setting:
# pos: the position effect vector
# v: the preference vector
# r: the revenue vector
# simu_times: number of replications
pos = [1,1/2,1/3,1/4,1/5]
v = [(10-i)/10 for i in range(10)]
r = [0.3, 0.2, 0.7, 0.4, 0.5, 0.6, 0.1, 0.9, 1.0, 0.8]
simu_times = 2

# more parameters for EI-TLR:
# v_max: \nu_{0}, an upper bound for all items' preferences
# lam: lambda
# c_UCB: UCB constant ahead of the bonus
# thr: threshold in applying Alternate Minimization Algorithm
# exp_c: constant affecting number of exploration epochs
# end_cri: binary ending criteria for the exploration phase
# rsd: np.random.seed and random.seed
v_max = 1
lam = 1
c_UCB = 0.01
thr = 0.0001
exp_c = 0.1
end_cri = 1
rsd = 0

# construct the list of horizon lengths
l = 20
ini_T = 200000
rg = 10
T_l = [0]*l
for i in range(l):
    T_l[i] = ceil(ini_T*rg**(i/(l-1)))
print(T_l)


# two options:
# option 1: apply EI-TLR to multiple horizon lengths, quite time-consuming
# for i in range(l):
#     T = T_l[i]
#     _ , reg_exp2_mean = ET.EI_TLR(pos,v,r,v_max,T,simu_times,lam,c_UCB,thr,exp_c,end_cri,rsd)
#     os.chdir('/Your Path/Data_Code/Simulation/Results/Ex3_RegretRate')
#     s = "EI-TLR_Ex3_reg_exp2_mean_" + str(i + 1) + ",npy"
#     np.save(s, reg_exp2_mean)

# option 2 (recommended): apply EI-TLR to a single horizon length each time
# need to manually vary i from 0 -- 19 (=l-1) to obtain all data needed
i = 0
T = T_l[i]
_ , reg_exp2_mean = ET.EI_TLR(pos,v,r,v_max,T,simu_times,lam,c_UCB,thr,exp_c,end_cri,rsd)
os.chdir('/Your Path/Data_Code/Simulation/Results/Ex3_RegretRate')
s = "EI-TLR_Ex3_reg_exp2_mean_" + str(i + 1) + ",npy"
np.save(s, reg_exp2_mean)