代码拉取完成,页面将自动刷新
import torch as th
import torch.nn as nn
import torch.nn.functional as F
class Critic(nn.Module):
def __init__(self, n_agent, dim_observation, dim_action):
super(Critic, self).__init__()
self.n_agent = n_agent
self.dim_observation = dim_observation
self.dim_action = dim_action
obs_dim = dim_observation * n_agent
act_dim = self.dim_action * n_agent
self.FC1 = nn.Linear(obs_dim, 1024)
self.FC2 = nn.Linear(1024+act_dim, 512)
self.FC3 = nn.Linear(512, 300)
self.FC4 = nn.Linear(300, 1)
# obs: batch_size * obs_dim
def forward(self, obs, acts):
result = F.relu(self.FC1(obs))
combined = th.cat([result, acts], 1)
result = F.relu(self.FC2(combined))
return self.FC4(F.relu(self.FC3(result)))
class Actor(nn.Module):
def __init__(self, dim_observation, dim_action):
super(Actor, self).__init__()
self.FC1 = nn.Linear(dim_observation, 500)
self.FC2 = nn.Linear(500, 128)
self.FC3 = nn.Linear(128, dim_action)
# action output between -2 and 2
def forward(self, obs):
result = F.relu(self.FC1(obs))
result = F.relu(self.FC2(result))
result = F.tanh(self.FC3(result))
return result
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。