File size: 1,973 Bytes
ec5ee81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

The whole training pipeline (about 30-60 minutes on a laptop):



  python scripts/train.py              data, models, traffic-light tuning, reinforcement learning

  python scripts/train.py --skip-data  reuse data/training/*.csv

  python scripts/train.py --skip-tune  skip the max-pressure tuning

  python scripts/train.py --skip-rl    skip reinforcement learning

  python scripts/train.py --only-rl    reinforcement learning only (rounds: --rl-rounds 3)

"""
import argparse
import json

import _path  # noqa: F401
from traffix.training import datagen, rl, train_models, tune

if __name__ == "__main__":
    p = argparse.ArgumentParser()
    p.add_argument("--skip-data", action="store_true")
    p.add_argument("--skip-tune", action="store_true")
    p.add_argument("--trials", type=int, default=8)
    p.add_argument("--skip-rl", action="store_true")
    p.add_argument("--only-rl", action="store_true")
    p.add_argument("--only-predictive", action="store_true")
    p.add_argument("--rl-rounds", type=int, default=3)
    a = p.parse_args()
    if a.only_predictive:
        print("Tuning the predictive traffic light agent...")
        print(tune.tune_predictive(a.trials))
        raise SystemExit
    if a.only_rl:
        print("Reinforcement learning (Fitted Q-Iteration)...")
        print(rl.train(a.rl_rounds))
        raise SystemExit
    if not a.skip_data:
        print("1/4 Generating training data (2025 dates)...")
        print(datagen.generate())
    print("2/4 Training models...")
    print(json.dumps(train_models.train_all(), indent=1))
    if not a.skip_tune:
        print("3/4 Tuning traffic light, corridor and predictive-agent parameters...")
        print(tune.tune(a.trials))
        print(tune.tune_predictive(a.trials))
    if not a.skip_rl:
        print("4/4 Reinforcement learning for the traffic light agent...")
        print(rl.train(a.rl_rounds))
    print("Models saved in models/")