-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_hw.py
74 lines (60 loc) · 2.08 KB
/
exp_hw.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
import config
from run import run_q_learning, run_sarsa
import sys
import os
def q_learning_lr_experiment(lrs=None):
lrs = [0.1, 0.3, 0.5, 0.7, 0.9] if not lrs else lrs
srs = []
sys.stdout = open(os.devnull, 'w')
for _lr in lrs:
config.train_config['learning_rate'] = _lr
success_rate = 0
for i in range(10):
success_rate += run_q_learning()
srs.append(success_rate / 10)
sys.stdout = sys.__stdout__
print('q learning with different lrs: ', lrs)
print('average success rate: ', srs)
def q_learning_gamma_experiment(gammas=None):
gammas = [0., 0.5, 0.9, 0.99, 0.999] if not gammas else gammas
srs = []
sys.stdout = open(os.devnull, 'w')
for _gamma in gammas:
config.train_config['gamma'] = _gamma
success_rate = 0
for i in range(10):
success_rate += run_q_learning()
srs.append(success_rate / 10)
sys.stdout = sys.__stdout__
print('q learning with different gammas: ', gammas)
print('average success rate: ', srs)
def sarsa_lr_experiment(lrs=None):
lrs = [0.1, 0.3, 0.5, 0.7, 0.9] if not lrs else lrs
srs = []
sys.stdout = open(os.devnull, 'w')
for _lr in lrs:
config.train_config['learning_rate'] = _lr
success_rate = 0
for i in range(10):
success_rate += run_sarsa()
srs.append(success_rate / 10)
sys.stdout = sys.__stdout__
print('sarsa with different lrs: ', lrs)
print('average success rate: ', srs)
def sarsa_gamma_experiment(gammas=None):
gammas = [0., 0.5, 0.9, 0.99, 0.999] if not gammas else gammas
srs = []
sys.stdout = open(os.devnull, 'w')
for _gamma in gammas:
config.train_config['gamma'] = _gamma
success_rate = 0
for i in range(10):
success_rate += run_sarsa()
srs.append(success_rate / 10)
sys.stdout = sys.__stdout__
print('sarsa with different gammas: ', gammas)
print('average success rate: ', srs)
q_learning_lr_experiment()
q_learning_gamma_experiment()
sarsa_lr_experiment()
sarsa_gamma_experiment()