diff --git a/irlc/lectures/lec09/__init__.py b/irlc/lectures/lec09/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..a56057c84d0ceac54aab1d40ba0f370c77fe10be --- /dev/null +++ b/irlc/lectures/lec09/__init__.py @@ -0,0 +1 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. diff --git a/irlc/lectures/lec09/unf_frozenlake.py b/irlc/lectures/lec09/unf_frozenlake.py new file mode 100644 index 0000000000000000000000000000000000000000..3e0a92077a1619cae07aca4b39edcd8d27df501c --- /dev/null +++ b/irlc/lectures/lec09/unf_frozenlake.py @@ -0,0 +1,11 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.ex01.agent import Agent +from irlc.gridworld.gridworld_environments import FrozenLake +from irlc import interactive, train + +if __name__ == "__main__": + env = FrozenLake(render_mode='human', print_states=True) + env, agent = interactive(env, Agent(env)) + agent.label = "Random agent" + train(env, agent, num_episodes=100, verbose=False) + env.close() diff --git a/irlc/lectures/lec09/unf_gridworld.py b/irlc/lectures/lec09/unf_gridworld.py new file mode 100644 index 0000000000000000000000000000000000000000..f66651112587a17484435dcb245ef5845cb60a31 --- /dev/null +++ b/irlc/lectures/lec09/unf_gridworld.py @@ -0,0 +1,12 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.ex01.agent import Agent +from irlc.gridworld.gridworld_environments import BookGridEnvironment +from irlc import interactive, train + + +if __name__ == "__main__": + env = BookGridEnvironment(render_mode='human', print_states=True, living_reward=-0.05) + env, agent = interactive(env, Agent(env)) + agent.label = "Random agent" + train(env, agent, num_episodes=100, verbose=False) + env.close() diff --git a/irlc/lectures/lec09/unf_policy_evaluation_frozen.py b/irlc/lectures/lec09/unf_policy_evaluation_frozen.py new file mode 100644 index 0000000000000000000000000000000000000000..9adda9fd454d02ed5809cb122d70365c9130c148 --- /dev/null +++ b/irlc/lectures/lec09/unf_policy_evaluation_frozen.py @@ -0,0 +1,20 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import FrozenLake +from irlc import interactive, train +from irlc.gridworld.demo_agents.hidden_agents import PolicyEvaluationAgent2 + +def policy_evaluation(env=None): + agent = PolicyEvaluationAgent2(env, gamma=1., steps_between_policy_improvement=None) + env, agent = interactive(env, agent) + train(env, agent, num_episodes=100) + env.close() + +def policy_improvement(env=None, q_mode=True): + agent = PolicyEvaluationAgent2(env, gamma=1.,steps_between_policy_improvement=20) + env, agent = interactive(env, agent) + train(env, agent, num_episodes=1000, verbose=False) + env.close() + +if __name__ == "__main__": + env = FrozenLake(render_mode='human', living_reward=-0.0) + policy_evaluation(env) diff --git a/irlc/lectures/lec09/unf_policy_evaluation_gridworld.py b/irlc/lectures/lec09/unf_policy_evaluation_gridworld.py new file mode 100644 index 0000000000000000000000000000000000000000..ccfd39c38bc267966f35f0ef79ddbea5afe35733 --- /dev/null +++ b/irlc/lectures/lec09/unf_policy_evaluation_gridworld.py @@ -0,0 +1,20 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import BookGridEnvironment +from irlc import interactive, train +from irlc.gridworld.demo_agents.hidden_agents import PolicyEvaluationAgent2 + +def policy_evaluation(env=None): + agent = PolicyEvaluationAgent2(env, gamma=1., steps_between_policy_improvement=None, only_update_current=False) + env, agent = interactive(env, agent) + train(env, agent, num_episodes=100) + env.close() + +def policy_improvement(env=None, q_mode=True): + agent = PolicyEvaluationAgent2(env, gamma=1.,steps_between_policy_improvement=20) + env, agent = interactive(env, agent) + train(env, agent, num_episodes=1000) + env.close() + +if __name__ == "__main__": + env = BookGridEnvironment(render_mode='human', living_reward=-0.05) + policy_evaluation(env) diff --git a/irlc/lectures/lec09/unf_policy_evaluation_stepwise_gridworld.py b/irlc/lectures/lec09/unf_policy_evaluation_stepwise_gridworld.py new file mode 100644 index 0000000000000000000000000000000000000000..a438af8f6d67f7d80b09c1efffdda5e69af84fb4 --- /dev/null +++ b/irlc/lectures/lec09/unf_policy_evaluation_stepwise_gridworld.py @@ -0,0 +1,20 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import BookGridEnvironment +from irlc import interactive, train +from irlc.gridworld.demo_agents.hidden_agents import PolicyEvaluationAgent2 + +def policy_evaluation_stepwise(env=None): + agent = PolicyEvaluationAgent2(env, gamma=1., steps_between_policy_improvement=None, only_update_current=True) + env, agent = interactive(env, agent) + train(env, agent, num_episodes=100) + env.close() + +def policy_improvement(env=None, q_mode=True): + agent = PolicyEvaluationAgent2(env, gamma=1.,steps_between_policy_improvement=20) + env, agent = interactive(env, agent) + train(env, agent, num_episodes=1000) + env.close() + +if __name__ == "__main__": + env = BookGridEnvironment(render_mode='human', living_reward=-0.05) + policy_evaluation_stepwise(env) diff --git a/irlc/lectures/lec09/unf_policy_improvement_frozenlake.py b/irlc/lectures/lec09/unf_policy_improvement_frozenlake.py new file mode 100644 index 0000000000000000000000000000000000000000..7242b00a8195c5c368bfb4d9abebc79498e35b1c --- /dev/null +++ b/irlc/lectures/lec09/unf_policy_improvement_frozenlake.py @@ -0,0 +1,7 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import BookGridEnvironment, FrozenLake +from irlc.lectures.unf.unf_policy_evaluation_gridworld import policy_improvement + +if __name__ == "__main__": + env = FrozenLake(render_mode='human', living_reward=-0) + policy_improvement(env) diff --git a/irlc/lectures/lec09/unf_policy_improvement_gridworld.py b/irlc/lectures/lec09/unf_policy_improvement_gridworld.py new file mode 100644 index 0000000000000000000000000000000000000000..eb6d7623bf8b566aed9e589d4586256d2b5b3fd5 --- /dev/null +++ b/irlc/lectures/lec09/unf_policy_improvement_gridworld.py @@ -0,0 +1,7 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import BookGridEnvironment +from irlc.lectures.unf.unf_policy_evaluation_gridworld import policy_improvement + +if __name__ == "__main__": + env = BookGridEnvironment(render_mode='human', living_reward=-0.05) + policy_improvement(env) diff --git a/irlc/lectures/lec09/unf_vi_frozenlake.py b/irlc/lectures/lec09/unf_vi_frozenlake.py new file mode 100644 index 0000000000000000000000000000000000000000..4ece4f2e944c076be048a9fdae6f453ce6ff01ad --- /dev/null +++ b/irlc/lectures/lec09/unf_vi_frozenlake.py @@ -0,0 +1,17 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import FrozenLake +from irlc.ex01.agent import train +from irlc.gridworld.demo_agents.hidden_agents import ValueIterationAgent3 +from irlc import interactive + +def q1_vi(env): + agent = ValueIterationAgent3(env, epsilon=0, gamma=1, only_update_current=False) + env, agent = interactive(env, agent) + env.reset() + train(env, agent, num_episodes=100) + env.close() + + +if __name__ == "__main__": + env = FrozenLake(render_mode='human', living_reward=-0) + q1_vi(env) diff --git a/irlc/lectures/lec09/unf_vi_gridworld.py b/irlc/lectures/lec09/unf_vi_gridworld.py new file mode 100644 index 0000000000000000000000000000000000000000..766303f449847ba19577cbe793127bd886f01dae --- /dev/null +++ b/irlc/lectures/lec09/unf_vi_gridworld.py @@ -0,0 +1,16 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import BookGridEnvironment +from irlc.ex01.agent import train +from irlc.gridworld.demo_agents.hidden_agents import ValueIterationAgent3 +from irlc import interactive + +def q1_vi(env): + agent = ValueIterationAgent3(env, epsilon=0, gamma=1, only_update_current=False) + env, agent = interactive(env, agent) + env.reset() + train(env, agent, num_episodes=100) + env.close() + +if __name__ == "__main__": + env = BookGridEnvironment(render_mode='human', living_reward=-0.05) + q1_vi(env) diff --git a/irlc/lectures/lec09/unf_vi_gridworld_stepwise.py b/irlc/lectures/lec09/unf_vi_gridworld_stepwise.py new file mode 100644 index 0000000000000000000000000000000000000000..152a91b25114104a470fc43d4611a36601e9d9c0 --- /dev/null +++ b/irlc/lectures/lec09/unf_vi_gridworld_stepwise.py @@ -0,0 +1,16 @@ +# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. +from irlc.gridworld.gridworld_environments import BookGridEnvironment +from irlc.ex01.agent import train +from irlc.gridworld.demo_agents.hidden_agents import ValueIterationAgent3 +from irlc import interactive + +def q1_vi(env): + agent = ValueIterationAgent3(env, epsilon=0, gamma=1, only_update_current=True) + env, agent = interactive(env, agent) + env.reset() + train(env, agent, num_episodes=100) + env.close() + +if __name__ == "__main__": + env = BookGridEnvironment(render_mode='human', living_reward=-0.05, print_states=False) + q1_vi(env)