"""
This python file corresponds to LR-UCB policy implemented on real car data under known position effects
"""

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


# Real car data setting:
# pos: the position effect vector
# v: the preference vector
# r: the revenue vector
# T: horizon length
# simu_times: number of replications
K = 100
c_pos = 2
pos = []
for i in range(K):
    pos.append(2**(-c_pos*i/(K-1)))
os.chdir('/Your Path/Data_Code/Real_Application/Pre_Process')
v_ori = np.load("Car_Pre.npy")
v = list(v_ori)
print("Car preferences", v)

r = [1 for i in range(len(v))]

T = 4000000
simu_times = 50

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



# two options:
# option 1: apply LR-UCB with "simu_times" replications, quite time-consuming
# for i in range(simu_times):
#     # rsd: np.random.seed
#     rsd = i + 1

#     reg_mean_LR_UCB_Car = LU.LR_UCB(pos,v,r,v_max,T,1,lam,c_UCB,rsd)
#     print(np.sum(reg_mean_LR_UCB_Car))

#     # save the results
#     os.chdir('/Your Path/Data_Code/Real_Application/Results/LR_UCB')
#     s = "LR-UCB_reg_mean_" + str(i+1) + ".npy"
#     np.save(s,reg_mean_LR_UCB_Car)

# option 2 (recommended): apply LR-UCB separately for each replication
# need to manually vary i from 0 -- 49 (=simu_times-1) to obtain all data needed
i = 0
rsd = i + 1

reg_mean_LR_UCB_Car = LU.LR_UCB(pos,v,r,v_max,T,1,lam,c_UCB,rsd)
print(np.sum(reg_mean_LR_UCB_Car))

# save the results
os.chdir('/Your Path/Data_Code/Real_Application/Results/LR_UCB')
s = "LR-UCB_reg_mean_" + str(i+1) + ".npy"
np.save(s,reg_mean_LR_UCB_Car)