-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmodel.py
More file actions
71 lines (56 loc) · 1.92 KB
/
Copy pathmodel.py
File metadata and controls
71 lines (56 loc) · 1.92 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import torch
import torch.nn as nn
class QNET(nn.Module):
def __init__(self, input_dim=3, output_dim=1):
super(QNET, self).__init__()
self.fc = nn.Sequential(
nn.Linear(in_features=input_dim, out_features=128),
nn.ReLU(),
nn.Linear(in_features=128, out_features=64),
nn.ReLU(),
nn.Linear(in_features=64, out_features=32),
nn.ReLU(),
nn.Linear(in_features=32, out_features=output_dim),
)
def forward(self, x):
x = x.type(torch.float32)
return self.fc(x)
class PolicyNet(nn.Module):
def __init__(self, input_dim=2, output_dim=5):
super(PolicyNet, self).__init__()
self.fc = nn.Sequential(
nn.Linear(in_features=input_dim, out_features=100),
nn.ReLU(),
nn.Linear(in_features=100, out_features=output_dim),
nn.Softmax(dim=1)
)
def forward(self, x):
x = x.type(torch.float32)
return self.fc(x)
class DPolicyNet(nn.Module):
def __init__(self, input_dim=2, output_dim=1):
super(DPolicyNet, self).__init__()
self.fc = nn.Sequential(
nn.Linear(in_features=input_dim, out_features=100),
nn.ReLU(),
nn.Linear(in_features=100, out_features=output_dim),
)
def forward(self, x):
x = x.type(torch.float32)
return self.fc(x)
class ValueNet(torch.nn.Module):
def __init__(self, input_dim=2, output_dim=1):
super(ValueNet, self).__init__()
self.fc = nn.Sequential(
nn.Linear(in_features=input_dim, out_features=100),
nn.ReLU(),
nn.Linear(in_features=100, out_features=output_dim),
)
def forward(self, x):
x = x.type(torch.float32)
return self.fc(x)
if __name__ == '__main__':
dqn = PolicyNet()
input = torch.tensor([[2, 1], [3, 1]])
print(dqn)
print(dqn(input))