提交 5be4ca00 编写于 作者: B Bo Zhou 提交者: Hongsheng Zeng

Update README.md (#34)

a more detailed example for DQN model.
上级 b249dee3
...@@ -31,8 +31,24 @@ Here is an example of building an agent with DQN algorithm for atari games. ...@@ -31,8 +31,24 @@ Here is an example of building an agent with DQN algorithm for atari games.
import parl import parl
from parl.algorithms import DQN, DDQN from parl.algorithms import DQN, DDQN
class CriticModel(parl.Model): class AtariModel(parl.Model):
""" define specific forward model for environment ...""" """AtariModel
This class defines the forward part for an algorithm,
its input is state observed on environment.
"""
def __init__(self, img_shape, action_dim):
# define your layers
self.cnn1 = layers.conv_2d(num_filters=32, filter_size=5,
stride=[1, 1], padding=[2, 2], act='relu')
...
self.fc1 = layers.fc(action_dim)
def value(self, img):
# define how to estimate the Q value based on the image of atari games.
img = img / 255.0
l = self.cnn1(img)
...
Q = self.fc1(l)
return Q
""" """
three steps to build an agent three steps to build an agent
1. define a forward model which is critic_model is this example 1. define a forward model which is critic_model is this example
...@@ -41,8 +57,8 @@ three steps to build an agent ...@@ -41,8 +57,8 @@ three steps to build an agent
3. define the I/O part in AtariAgent so that it could update the algorithm based on the interactive data 3. define the I/O part in AtariAgent so that it could update the algorithm based on the interactive data
""" """
critic_model = CriticModel(act_dim=2) model = AtariModel(img_shape=(32, 32), action_dim=4)
algorithm = DQN(critic_model) algorithm = DQN(model)
agent = AtariAgent(aglrotihm) agent = AtariAgent(aglrotihm)
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册