-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_val.py
58 lines (51 loc) · 1.55 KB
/
model_val.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
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
class Actor(nn.Module):
def __init__(self):
super(Actor, self).__init__()
#128 input features, 64 output features (see sizing flow below)
self.fc1 = nn.Linear(8*4, 32)
self.fc2 = nn.Linear(32, 16)
self.fc3 = nn.Linear(16, 3)
def forward(self, state):
x = F.relu(self.fc1(state))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return F.softmax(x, dim=0)
class Critic(nn.Module):
def __init__(self):
super(Critic, self).__init__()
#128 input features, 64 output features (see sizing flow below)
self.fc1 = nn.Linear(8*4, 32)
self.fc2 = nn.Linear(32, 16)
self.fc3 = nn.Linear(16, 1)
def forward(self, state):
x = F.relu(self.fc1(state))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
class ActorCritic(nn.Module):
def __init__(self):
super(ActorCritic, self).__init__()
self.actor = nn.Sequential(
nn.Linear(8*4, 32),
nn.ReLU(),
nn.Linear(32, 16),
nn.ReLU(),
nn.Linear(16, 3),
nn.Softmax(dim=-1),
)
self.critic = nn.Sequential(
nn.Linear(8*4, 32),
nn.ReLU(),
nn.Linear(32, 16),
nn.ReLU(),
nn.Linear(16, 1),
)
def forward(self, x):
value = self.critic(x)
probs = self.actor(x)
# dist = Categorical(probs)
return probs, value