-
Notifications
You must be signed in to change notification settings - Fork 2
/
DDPG.py
34 lines (30 loc) · 927 Bytes
/
DDPG.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
import torch
import torch.nn as nn
class Actor(nn.Module):
def __init__(self, n_states):
super(Actor, self).__init__()
self.net = nn.Sequential(
nn.Linear(n_states, 20),
nn.ReLU(),
nn.Linear(20, 20),
nn.ReLU(),
nn.Linear(20, 20),
nn.ReLU(),
nn.Linear(20, 1)
)
def forward(self, state):
return self.net(state)
class Critic(nn.Module):
def __init__(self, n_states, n_actions):
super(Critic, self).__init__()
self.net = nn.Sequential(
nn.Linear(n_states + n_actions, 20),
nn.ReLU(),
nn.Linear(20, 20),
nn.ReLU(),
nn.Linear(20, 20),
nn.ReLU(),
nn.Linear(20, n_actions)
)
def forward(self, state, action):
return self.net(torch.cat((state, action), 1))