-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
36 lines (30 loc) · 1.04 KB
/
model.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
import torch
import torch.nn as nn
import torch.nn.functional as F
class DDPGNet(nn.Module):
"""
Actor Critic model that gets trained by DDPG agent
"""
def __init__(self, input_dim, hidden_in_dim, hidden_out_dim, output_dim, actor = False):
super(DDPGNet, self).__init__()
self.fc1 = nn.Linear(input_dim,hidden_in_dim)
self.fc2 = nn.Linear(hidden_in_dim,hidden_out_dim)
self.fc3 = nn.Linear(hidden_out_dim,output_dim)
self.relu = F.relu
self.is_actor = actor
def actor_network(self, x):
h1 = self.relu(self.fc1(x))
h2 = self.relu(self.fc2(h1))
h3 = (self.fc3(h2))
return torch.tanh(h3)
def critic_network(self, x):
h1 = self.relu(self.fc1(x))
h2 = self.relu(self.fc2(h1))
h3 = (self.fc3(h2))
return h3
def forward(self, x):
if self.is_actor:
return self.actor_network(x)
else:
# critic network simply outputs a number
return self.critic_network(x)