-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
78 lines (57 loc) · 2.67 KB
/
models.py
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
72
73
74
75
76
import torch.nn as nn
import torch.nn.functional as F
#===============#
# LexDNN # ==========================================================
#===============#
# A lexicographic DNN; has an input size of state_size and and output size
# of action_size * sample_size * reward size.
# Has 3 layers, the first two of which perform relu activation
# The nohid parameter can remove the intermediate layer
#===========================================================================
class LexDNN(nn.Module):
def __init__(self, state_size, action_size, sample_size, hidden_size, reward_size, nohid, bias):
super(LexDNN, self).__init__()
self.state_size = state_size
self.hidden_size = hidden_size
self.action_size = action_size
self.sample_size = sample_size
self.reward_size = reward_size
self.nohid = nohid
self.bias = bias
self.fc1 = nn.Linear(self.state_size, self.hidden_size, bias = bias)
self.fc2 = nn.Linear(self.hidden_size, self.hidden_size, bias = bias)
self.fc3 = nn.Linear(self.hidden_size, self.action_size * self.sample_size * self.reward_size, bias = bias)
def forward(self, x):
x = F.relu(self.fc1(x))
if not self.nohid:
x = F.relu(self.fc2(x))
x = self.fc3(x)
x = x.view(-1, self.action_size, self.sample_size, self.reward_size)
return x
#============#
# DNN # ==========================================================
#============#
# A DNN; has an input size of state_size and and output size
# of action_size * sample_size.
# Has 3 layers, the first two of which perform relu activation
# The nohid parameter can remove the intermediate layer
#===========================================================================
class DNN(nn.Module):
def __init__(self, state_size, action_size, sample_size, hidden_size, nohid, bias):
super(DNN, self).__init__()
self.state_size = state_size
self.hidden_size = hidden_size
self.action_size = action_size
self.sample_size = sample_size
self.nohid = nohid
self.bias = bias
self.fc1 = nn.Linear(self.state_size, self.hidden_size, bias = bias)
self.fc2 = nn.Linear(self.hidden_size, self.hidden_size, bias = bias)
self.fc3 = nn.Linear(self.hidden_size, self.action_size * self.sample_size, bias = bias)
def forward(self, x):
x = F.relu(self.fc1(x))
if not self.nohid:
x = F.relu(self.fc2(x))
x = self.fc3(x)
x = x.view(-1, self.action_size, self.sample_size)
return x