-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActorCritic.py
48 lines (41 loc) · 1.37 KB
/
ActorCritic.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
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.autograd
from torch.autograd import Variable
torch.set_default_dtype(torch.float64)
class Critic(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(Critic, self).__init__()
self.OneFunc = nn.Sequential(
nn.Linear(input_size, hidden_size),
nn.ELU(),
nn.BatchNorm1d(hidden_size),
nn.Linear(hidden_size, hidden_size),
nn.ELU(),
nn.BatchNorm1d(hidden_size),
nn.Linear(hidden_size, output_size)
)
def forward(self, state, action):
self.eval()
x = torch.cat((state, action),dim=1)
x = self.OneFunc(x)
return x
class Actor(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(Actor, self).__init__()
self.OneFunc = nn.Sequential(
nn.BatchNorm1d(input_size),
nn.Linear(input_size, hidden_size),
nn.ELU(),
nn.BatchNorm1d(hidden_size),
nn.Linear(hidden_size, hidden_size),
nn.ELU(),
nn.BatchNorm1d(hidden_size),
nn.Linear(hidden_size, output_size),
nn.Tanh()
)
def forward(self, state):
self.eval()
state = state.to(torch.float64)
return 5 * self.OneFunc(state)