Skip to content
Snippets Groups Projects
Commit 9ab4a43b authored by tuhe's avatar tuhe
Browse files

Lecture 9 examples

parent d9906643
Branches
No related tags found
No related merge requests found
# 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.
# 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()
# 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()
# 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)
# 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)
# 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)
# 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)
# 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)
# 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)
# 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)
# 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment