This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_simulation.py
93 lines (83 loc) · 4.36 KB
/
run_simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import argparse
from learners.advertisement.gpts import GPTS
from learners.advertisement.gpts_scaled import GPTS as GPTS2
from learners.advertisement.gts import GTS
from learners.joint.joint_contextual_learner import JointContextualLearner
from learners.joint.joint_learner import JointLearner
from learners.pricing.thompson_sampling import ThompsonSampling
from learners.pricing.ucb import UCB
from utils.tasks.complete_task import CompleteTask
def task_builder(simulation_name, source, fixed_adv, fixed_price, selected_bid, selected_price, pricing_context,
time_horizon, n_experiments, cg_confidence, cg_start_from, cg_frequency):
new_task = CompleteTask(data_src=source,
name=simulation_name,
fixed_adv=fixed_adv,
fixed_price=fixed_price,
selected_bid=selected_bid,
selected_price=selected_price,
pricing_context=pricing_context
)
if fixed_price:
learners = [GTS, GPTS]
elif fixed_adv:
learners = [UCB, ThompsonSampling]
elif pricing_context:
learners = [JointContextualLearner]
else:
learners = [JointLearner]
new_task.config(time_horizon=time_horizon,
n_experiments=n_experiments,
learner_to_test=learners,
cg_start_from=cg_start_from,
cg_frequency=cg_frequency,
cg_confidence=cg_confidence)
return new_task
if __name__ == '__main__':
ap = argparse.ArgumentParser()
# Add the arguments to the parser
ap.add_argument("--simulation_name", required=True, help="Name of the simulation", type=str)
ap.add_argument("--src", required=True, help="Source data", type=str)
ap.add_argument("-T", "--time_horizon", required=True, help="Time Horizon", type=int)
ap.add_argument("-n", "--n_experiments", required=True, help="Number of experiments", type=int)
ap.add_argument("--fixed_adv", required=False, help="Fixed advertisement campaign",
type=bool, default=False, choices=[True, False])
ap.add_argument("--fixed_price", required=False, help="Fixed pricing campaign",
type=bool, default=False, choices=[True, False])
ap.add_argument("--selected_bid", required=False, help="Selected bid (in case of fixed_adv)",
type=int, default=4, choices=range(0, 10))
ap.add_argument("--selected_price", required=False, help="Selected price (in case of fixed_price)",
type=int, default=3, choices=range(0, 10))
ap.add_argument("--pricing_context", required=False,
help="Contextual pricing campaign (in case of not fixed_price)",
type=bool, default=False, choices=[True, False])
ap.add_argument("--cg_start_from", required=False, help="Context generator starting day",
type=int, default=31)
ap.add_argument("--cg_frequency", required=False, help="Context generator frequency",
type=int, default=10)
ap.add_argument("--cg_confidence", required=False,
help="Context generator confidence",
type=float, default=0.002)
ap.add_argument("--output_folder", required=False, help="Output folder where the result of the simulation is saved",
type=str, default='simulations_results')
args = vars(ap.parse_args())
print(args)
task = task_builder(source=args['src'],
simulation_name=args['simulation_name'],
fixed_adv=args['fixed_adv'],
fixed_price=args['fixed_price'],
selected_bid=args['selected_bid'],
selected_price=args['selected_price'],
pricing_context=args['pricing_context'],
time_horizon=args['time_horizon'],
n_experiments=args['n_experiments'],
cg_frequency=args['cg_frequency'],
cg_confidence=args['cg_confidence'],
cg_start_from=args['cg_start_from']
)
out_folder = args['output_folder']
task.run()
path = task.save(folder=out_folder)
task.load(path)
task.plot(0)
task.plot(1)
task.plot(2)