-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliff_walking.py
More file actions
24 lines (14 loc) · 930 Bytes
/
Copy pathcliff_walking.py
File metadata and controls
24 lines (14 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gymnasium as gym
from agent_helpers import train_off_policy_n_step_sarsa, train_q_learning, train_sarsa_zero
from visualizer import compare_rewards_all, compare_rewards
from td_learning import N_Step_Tree_Backup
env = gym.make("CliffWalking-v1")
eval_env = gym.make("CliffWalking-v1", render_mode="human")
if __name__ == "__main__":
reward_history_s, path_s, total_reward_s = train_sarsa_zero(env, eval_env)
reward_history_n, path_n, total_reward_n = train_off_policy_n_step_sarsa(env, eval_env)
reward_history_lambda, path_lambda, total_reward_lambda = train_q_learning(env, eval_env)
print(f"SARSA(0) Total Reward: {total_reward_s}")
print(f"Off-Policy N-Step SARSA Total Reward: {total_reward_n}")
print(f"Q-Learning Total Reward: {total_reward_lambda}")
compare_rewards_all(reward_history_s, reward_history_n, reward_history_lambda)