"""
This python file corresponds to the error rate of EI-TLR's preference and position effect estimations under Example 3
"""

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

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 = 500

# more parameters for EI-TLR-Explore:
# v_max: \nu_{0}, an upper bound for all items' preferences
# thr: threshold in applying Alternate Minimization Algorithm
# end_cri: binary ending criteria for the exploration phase
# rsd: np.random.seed and random.seed
v_max = 1
thr = 0.0001
end_cri = 1
rsd = 0

# construct the list of numbers of minimum exploration epochs
range_epoch_n = 20
range_epoch = np.zeros(range_epoch_n, dtype=int)
ini_epoch = 1000
end_epoch = 20000
mul = (end_epoch/ini_epoch)**(1/(range_epoch_n-1))
for i in range(range_epoch_n):
    range_epoch[i] = round(ini_epoch*mul**i)

# initialize data to save
pre_est_err = np.zeros(range_epoch_n)
pos_est_err = np.zeros(range_epoch_n)


# apply EI-TLR-Explore to multiple numbers of exploration epochs
for i in range(range_epoch_n):
    print(i)
    exp_epoch = range_epoch[i]
    pre_est_err_mean, pos_est_err_mean = ETE.EI_TLR_Explore(pos,v,exp_epoch,simu_times,thr,end_cri,rsd)
    pre_est_err[i] = pre_est_err_mean
    pos_est_err[i] = pos_est_err_mean


os.chdir('/Your Path/Data_Code/Simulation/Results/ErrorRate')
np.save("Ex3_range_epoch_1",range_epoch)
np.save("Ex3_pre_est_err_mean_1.npy", pre_est_err)
np.save("Ex3_pos_est_err_mean_1.npy", pos_est_err)