-
Notifications
You must be signed in to change notification settings - Fork 2
/
NNs.py
39 lines (31 loc) · 1.17 KB
/
NNs.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
from torch import nn
import torch
import Config
torch.manual_seed(Config.seed)
class PolicyNN(nn.Module):
def __init__(self, input_state, output_action):
super(PolicyNN, self).__init__()
self.model = nn.Sequential(
nn.Linear(input_state, Config.hidden_sizes[0]),
nn.ReLU(),
nn.Linear(Config.hidden_sizes[0], Config.hidden_sizes[1]),
nn.ReLU(),
nn.Linear(Config.hidden_sizes[1], output_action),
nn.Tanh()
)
def forward(self, state):
actions = self.model(state)
return actions
class CriticNN(nn.Module):
def __init__(self, input_state, input_actions):
super(CriticNN, self).__init__()
self.value = nn.Sequential(
nn.Linear(input_state + input_actions, Config.hidden_sizes[0]),
nn.ReLU(),
nn.Linear(Config.hidden_sizes[0], Config.hidden_sizes[0]),
nn.ReLU(),
nn.Linear(Config.hidden_sizes[0], 1)
)
def forward(self, state, actions):
input_state_action = torch.cat((state, actions), 1)
return self.value(input_state_action)