-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCNN.py
More file actions
40 lines (32 loc) · 1.11 KB
/
Copy pathCNN.py
File metadata and controls
40 lines (32 loc) · 1.11 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
# Convolutional Neural Network
import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.nn.functional as F
NUM_DIR = 4
VALUE_STATE = 1
class CNN(nn.Module):
def __init__(self, inputDim):
super(CNN, self).__init__()
self.hidden1 = nn.Linear(inputDim, inputDim)
self.hidden2 = nn.Linear(inputDim, inputDim)
self.hidden3 = nn.Linear(inputDim, inputDim)
self.hidden4 = nn.Linear(inputDim, NUM_DIR + VALUE_STATE)
self.dropout = nn.Dropout(p=0.2)
self.softmax = nn.Softmax(dim=1)
def forward(self, x):
x = F.sigmoid(x)
x = self.hidden1(x)
x = self.dropout(x)
x = F.sigmoid(x)
x = self.hidden2(x)
x = self.dropout(x)
x = F.sigmoid(x)
x = self.hidden3(x)
x = self.dropout(x)
x = F.sigmoid(x)
x = self.hidden4(x)
x_stateActionProbabilities = self.softmax(x[:,0:4])
x_stateValue = F.sigmoid(torch.unsqueeze(x[:,4],1))
x = torch.cat((x_stateActionProbabilities,x_stateValue),1)
return x