forked from EgOrlukha/MuJoCo-PyTorch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
40 lines (34 loc) · 1.17 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
37
38
39
40
import torch
import torch.nn as nn
import torch.nn.functional as F
from hparams import HyperParams as hp
class Actor(nn.Module):
def __init__(self, num_inputs, num_outputs):
self.num_inputs = num_inputs
self.num_outputs = num_outputs
super(Actor, self).__init__()
self.fc1 = nn.Linear(num_inputs, hp.hidden)
self.fc2 = nn.Linear(hp.hidden, hp.hidden)
self.fc3 = nn.Linear(hp.hidden, num_outputs)
self.fc3.weight.data.mul_(0.1)
self.fc3.bias.data.mul_(0.0)
def forward(self, x):
x = F.tanh(self.fc1(x))
x = F.tanh(self.fc2(x))
mu = self.fc3(x)
logstd = torch.zeros_like(mu)
std = torch.exp(logstd)
return mu, std, logstd
class Critic(nn.Module):
def __init__(self, num_inputs):
super(Critic, self).__init__()
self.fc1 = nn.Linear(num_inputs, hp.hidden)
self.fc2 = nn.Linear(hp.hidden, hp.hidden)
self.fc3 = nn.Linear(hp.hidden, 1)
self.fc3.weight.data.mul_(0.1)
self.fc3.bias.data.mul_(0.0)
def forward(self, x):
x = F.tanh(self.fc1(x))
x = F.tanh(self.fc2(x))
v = self.fc3(x)
return v