-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
46 lines (33 loc) · 1.18 KB
/
models.py
File metadata and controls
46 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import torch
import torch.nn as nn
import torch.nn.functional as F
class Critic(nn.Module):
def __init__(self, obs_dim, action_dim):
super(Critic, self).__init__()
self.obs_dim = obs_dim
self.action_dim = action_dim
self.linear1 = nn.Linear(self.obs_dim+ self.action_dim, 1024)
self.linear2 = nn.Linear(1024, 512)
self.linear3 = nn.Linear(512, 300)
self.linear4 = nn.Linear(300, 1)
def forward(self, x, a):
#x = F.relu(self.linear1(x))
xa_cat = torch.cat([x,a], 1)
xa = F.relu(self.linear1(xa_cat))
xa = F.relu(self.linear2(xa))
xa = F.relu(self.linear3(xa))
qval = self.linear4(xa)
return qval
class Actor(nn.Module):
def __init__(self, obs_dim, action_dim):
super(Actor, self).__init__()
self.obs_dim = obs_dim
self.action_dim = action_dim
self.linear1 = nn.Linear(self.obs_dim, 512)
self.linear2 = nn.Linear(512, 128)
self.linear3 = nn.Linear(128, self.action_dim)
def forward(self, obs):
x = F.relu(self.linear1(obs))
x = F.relu(self.linear2(x))
x = torch.tanh(self.linear3(x))
return x