-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
46 lines (43 loc) · 1.56 KB
/
example.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
from Amgu.basic.env import CityFlow1D
from Amgu.basic.reward import *
from Amgu.basic.models import Random
from Amgu.basic.evaluate import evaluation_generator
from Amgu.visualization.graph import line_graph, offline_attack_analysis
from Amgu.runnner import stable_baseline_train
from stable_baselines3 import DQN
exp_name = "DQN_delta_waiting_time_1x1"
stable_baselines_config = {
"experiment_name": exp_name,
"env_config": {
"config_path": "example/1x1/config.json",
"steps_per_episode": 400,
"save_path": "example/1x1/res/",
},
"env_param": {"reward_func": queue_length, "district": True},
"policy_param": {
"policy": "MlpPolicy",
"tensorboard_log": f"{exp_name}/tesnorboard",
# 'policy_kwargs': dict(activation_fn=th.nn.ReLU, net_arch=[146,50,8]),
"gamma": 0.95,
"learning_rate": 0.005,
# "exploration_initial_eps": 1,
# 'exploration_fraction': 0.9,
# "exploration_final_eps": 0.15,
# 'target_update_interval': 1_000,
},
"evaluation_interval": 400,
"evaluation_duration": 1,
"stop": {"training_iteration": 2_000},
}
# stable_baseline_train(DQN, CityFlow1D, stable_baselines_config)
env = CityFlow1D(
stable_baselines_config["env_config"], **stable_baselines_config["env_param"]
)
models = [
Random(env.action_space),
# Random(env.action_space),
# Random(env.action_space),
# Random(env.action_space),
]
gen = evaluation_generator(CityFlow1D, stable_baselines_config, models)
offline_attack_analysis(gen, 400, len(models), "here.png")