A Deep Q-learning solution

In the following code, a Deep Q-learning solution for the FrozenLake problem is proposed:

import gymimport numpy as npfrom keras.models import Sequentialfrom keras.layers.core import Dense, Reshapefrom keras.layers.embeddings import Embeddingfrom keras.optimizers import Adamfrom rl.agents.dqn import DQNAgentfrom rl.policy import BoltzmannQPolicyfrom rl.memory import SequentialMemory ENV_NAME = 'FrozenLake-v0' env = gym.make(ENV_NAME)np.random.seed(1)env.seed(1)Actions = env.action_space.n model = Sequential()model.add(Embedding(16, 4, input_length=1))model.add(Reshape((4,)))print(model.summary()) memory = SequentialMemory(limit=10000, window_length=1)policy = BoltzmannQPolicy()Dqn = DQNAgent(model=model, nb_actions=Actions, ...

Get Keras Reinforcement Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.