-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdqn.py
More file actions
22 lines (17 loc) · 695 Bytes
/
dqn.py
File metadata and controls
22 lines (17 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import torch
from torch import nn
import torch.nn.functional as F
class DQN(nn.Module):
def __init__(self, state_dim, action_dim, hidden_dim1, hidden_dim2, hidden_dim3, hidden_dim4):
super(DQN, self).__init__()
self.fc1 = nn.Linear(state_dim, hidden_dim1)
self.fc2 = nn.Linear(hidden_dim1, hidden_dim2)
self.fc3 = nn.Linear(hidden_dim2, hidden_dim3)
self.fc4 = nn.Linear(hidden_dim3, hidden_dim4)
self.output = nn.Linear(hidden_dim4, action_dim)
def forward(self, x):
x1 = F.relu(self.fc1(x))
x2 = F.relu(self.fc2(x1))
x3 = F.relu(self.fc3(x2))
x4 = F.relu(self.fc4(x3))
return self.output(x4)