-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_taxi.py
65 lines (58 loc) · 2.09 KB
/
train_taxi.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
from policies import TabularPolicy, DQNPolicy, IntentionPolicy, IntentionAblatedPolicy
from tabular_class import QTabularRLModel, MCTabularRLModel
from deep_class import DQNModel, IntentionModel, IntentionAblatedModel
import argparse
import numpy as np
import gym
from wrappers import DiscretizedObservationWrapper, TaxiObservationWrapper
parser = argparse.ArgumentParser()
parser.add_argument("--policy", type=str, help="Policy to train. One of [MC/Q/DQN].")
parser.add_argument("--load", type=str, help="Path to model to load.")
parser.add_argument("--ckpt", type=str, help="Path to model checkpoint.")
parser.add_argument("--seed", type=int, help="Random seed.")
parser.add_argument("--train", action="store_true", help="Training mode.")
args = parser.parse_args()
env = gym.make('Taxi-v3')
if args.policy in ["MC", "Q"]:
if args.policy == 'Q':
model = QTabularRLModel(
policy=TabularPolicy,
env=env,
learning_rate=0.1,
gamma=1.,
exploration_type="linear",
exploration_frac=0.999,
exploration_initial_eps=1.,
exploration_final_eps=0.05,
seed=args.seed,
intent=True)
if args.policy == 'MC':
model = MCTabularRLModel(
policy=TabularPolicy,
env=env,
learning_rate=0.1,
gamma=1.,
exploration_type="linear",
exploration_frac=0.999,
exploration_initial_eps=1.,
exploration_final_eps=0.05,
seed=args.seed,
intent=True)
if args.policy == 'DQN':
env = TaxiObservationWrapper(env)
model = IntentionAblatedModel(
policy=IntentionAblatedPolicy,
env=env,
learning_rate=0.0001,
gamma=1.,
buffer_size=10000,
exploration_type="linear",
exploration_frac=0.999,
exploration_initial_eps=1.,
exploration_final_eps=0.05,
seed=args.seed)
model.set_random_seed(args.seed)
if args.load:
model.load(args.load)
if args.train:
model.learn(total_episodes=5000, ckpt_interval=100, ckpt_path=args.ckpt)