This commit is contained in:
JohnJim0816
2020-09-08 13:36:26 +08:00
parent f0d19ac14f
commit 106cfcc714
10 changed files with 108 additions and 83 deletions

View File

@@ -5,7 +5,7 @@
@Email: johnjim0816@gmail.com
@Date: 2020-06-12 00:47:02
@LastEditor: John
@LastEditTime: 2020-06-14 11:23:04
LastEditTime: 2020-08-19 16:55:54
@Discription:
@Environment: python 3.7.7
'''
@@ -14,17 +14,17 @@ import torch.nn.functional as F
class FCN(nn.Module):
def __init__(self, n_states=4, n_actions=18):
"""
Initialize a deep Q-learning network for testing algorithm
n_states: number of features of input.
n_actions: number of action-value to output, one-to-one correspondence to action in game.
""" 初始化q网络为全连接网络
n_states: 输入的feature即环境的state数目
n_actions: 输出的action总个数
"""
super(FCN, self).__init__()
self.fc1 = nn.Linear(n_states, 128)
self.fc2 = nn.Linear(128, 128)
self.fc3 = nn.Linear(128, n_actions)
self.fc1 = nn.Linear(n_states, 128) # 输入层
self.fc2 = nn.Linear(128, 128) # 隐藏层
self.fc3 = nn.Linear(128, n_actions) # 输出层
def forward(self, x):
x = F.relu(self.fc1(x))
# 各层对应的激活函数
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
return self.fc3(x)