This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Q-Learning example using OpenAI gym MountainCar enviornment | |
Author: Moustafa Alzantot ([email protected]) | |
""" | |
import numpy as np | |
import gym | |
from gym import wrappers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Solving FrozenLake8x8 environment using Policy iteration. | |
Author : Moustafa Alzantot ([email protected]) | |
""" | |
import numpy as np | |
import gym | |
from gym import wrappers | |
def run_episode(env, policy, gamma = 1.0, render = False): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Solving FrozenLake8x8 environment using Value-Itertion. | |
Author : Moustafa Alzantot ([email protected]) | |
""" | |
import numpy as np | |
import gym | |
from gym import wrappers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Q-Learning example using OpenAI gym MountainCar enviornment | |
Author: Moustafa Alzantot ([email protected]) | |
""" | |
import numpy as np | |
import gym | |
from gym import wrappers | |
n_states = 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import random | |
import time | |
import gym | |
from gym import wrappers | |
def run_episode(env, policy, episode_len=100): | |
total_reward = 0 | |
obs = env.reset() | |
for t in range(episode_len): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
import gym | |
def run_episode(env, policy, episode_len=100, render=False): | |
total_reward = 0 | |
obs = env.reset() | |
for t in range(episode_len): | |
if render: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
import numpy as np | |
def gen_random_policy(): | |
return (np.random.uniform(-1,1, size=4), np.random.uniform(-1,1)) | |
def policy_to_action(env, policy, obs): | |
if np.dot(policy[0], obs) + policy[1] > 0: | |
return 1 | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
env = gym.make('CartPole-v0') | |
# Restart the environment to start a new episode | |
obs = env.reset() | |
for step_idx in range(500): | |
env.render() | |
obs, reward, done, _ = env.step(env.action_space.sample()) |