mirror of
https://github.com/wassname/pytorch-soft-actor-critic.git
synced 2026-08-12 12:20:51 +08:00
Update model.py
This commit is contained in:
@@ -11,16 +11,13 @@ LOG_SIG_MIN = -20
|
||||
|
||||
|
||||
class ValueNetwork(nn.Module):
|
||||
def __init__(self, state_dim, hidden_dim, init_w=1e-3):
|
||||
def __init__(self, state_dim, hidden_dim):
|
||||
super(ValueNetwork, self).__init__()
|
||||
|
||||
self.linear1 = nn.Linear(state_dim, hidden_dim)
|
||||
self.linear2 = nn.Linear(hidden_dim, hidden_dim)
|
||||
self.linear3 = nn.Linear(hidden_dim, 1)
|
||||
|
||||
self.linear3.weight.data.uniform_(-init_w, init_w)
|
||||
self.linear3.bias.data.uniform_(-init_w, init_w)
|
||||
|
||||
def forward(self, state):
|
||||
x = F.relu(self.linear1(state))
|
||||
x = F.relu(self.linear2(x))
|
||||
@@ -29,16 +26,13 @@ class ValueNetwork(nn.Module):
|
||||
|
||||
|
||||
class QNetwork(nn.Module):
|
||||
def __init__(self, num_inputs, num_actions, hidden_size, init_w=1e-3):
|
||||
def __init__(self, num_inputs, num_actions, hidden_size):
|
||||
super(QNetwork, self).__init__()
|
||||
|
||||
self.linear1 = nn.Linear(num_inputs + num_actions, hidden_size)
|
||||
self.linear2 = nn.Linear(hidden_size, hidden_size)
|
||||
self.linear3 = nn.Linear(hidden_size, 1)
|
||||
|
||||
self.linear3.weight.data.uniform_(-init_w, init_w)
|
||||
self.linear3.bias.data.uniform_(-init_w, init_w)
|
||||
|
||||
def forward(self, state, action):
|
||||
x = torch.cat([state, action], 1)
|
||||
x = F.relu(self.linear1(x))
|
||||
@@ -48,19 +42,15 @@ class QNetwork(nn.Module):
|
||||
|
||||
|
||||
class GaussianPolicy(nn.Module):
|
||||
def __init__(self, num_inputs, num_actions, hidden_size, init_w=1e-3):
|
||||
def __init__(self, num_inputs, num_actions, hidden_size):
|
||||
super(GaussianPolicy, self).__init__()
|
||||
|
||||
self.linear1 = nn.Linear(num_inputs, hidden_size)
|
||||
self.linear2 = nn.Linear(hidden_size, hidden_size)
|
||||
|
||||
self.mean_linear = nn.Linear(hidden_size, num_actions)
|
||||
self.mean_linear.weight.data.uniform_(-init_w, init_w)
|
||||
self.mean_linear.bias.data.uniform_(-init_w, init_w)
|
||||
|
||||
self.log_std_linear = nn.Linear(hidden_size, num_actions)
|
||||
self.log_std_linear.weight.data.uniform_(-init_w, init_w)
|
||||
self.log_std_linear.bias.data.uniform_(-init_w, init_w)
|
||||
|
||||
def forward(self, state):
|
||||
x = F.relu(self.linear1(state))
|
||||
@@ -79,7 +69,7 @@ class GaussianPolicy(nn.Module):
|
||||
normal = Normal(mean, std)
|
||||
|
||||
if reparam == True:
|
||||
x_t = normal.rsample() # or mean + std * torch.randn(1,6)
|
||||
x_t = normal.rsample() #mean + std * torch.randn(1,6)
|
||||
else:
|
||||
x_t = normal.sample()
|
||||
|
||||
@@ -103,7 +93,6 @@ class GaussianMixturePolicy(nn.Module):
|
||||
super(GaussianMixturePolicy, self).__init__()
|
||||
self.actions = num_actions
|
||||
self.k = k
|
||||
self.log_std_max = LOG_SIG_MAX
|
||||
|
||||
self.linear1 = nn.Linear(num_inputs, hidden_size)
|
||||
self.linear2 = nn.Linear(hidden_size, hidden_size)
|
||||
|
||||
Reference in New Issue
Block a user