-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmodels.py
More file actions
45 lines (36 loc) · 1.12 KB
/
Copy pathmodels.py
File metadata and controls
45 lines (36 loc) · 1.12 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
import numpy as np
import random
import torch
import torch.nn as nn
import torch.nn.functional as F
# TODO(Lab-02): Complete the network model.
class PolicyNet(nn.Module):
def __init__(self):
super(PolicyNet, self).__init__()
self.fc1 = nn.Linear(23, 512)
self.fc2 = nn.Linear(512, 512)
self.fc3 = nn.Linear(512, 512)
self.action = nn.Linear(512, 2)
self.tanh = nn.Tanh()
self.relu = nn.ReLU()
def forward(self, s):
x = self.relu(self.fc1(s))
x = self.relu(self.fc2(x))
x = self.relu(self.fc3(x))
x = self.tanh(self.action(x))
return x
class QNet(nn.Module):
def __init__(self):
super(QNet, self).__init__()
self.fc1 = nn.Linear(23, 512)
self.fc2 = nn.Linear(514, 512)
self.fc3 = nn.Linear(512, 512)
self.action = nn.Linear(512, 1)
self.relu = nn.ReLU()
def forward(self, s, a):
x = self.relu(self.fc1(s))
x = torch.cat((x, a), 1)
x = self.relu(self.fc2(x))
x = self.relu(self.fc3(x))
x = self.action(x)
return x