-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlp_critic.py
30 lines (24 loc) · 902 Bytes
/
mlp_critic.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
import torch.nn as nn
import torch
class Value(nn.Module):
def __init__(self, state_dim, hidden_size=(128, 128), activation='tanh'):
super().__init__()
if activation == 'tanh':
self.activation = torch.tanh
elif activation == 'relu':
self.activation = torch.relu
elif activation == 'sigmoid':
self.activation = torch.sigmoid
self.affine_layers = nn.ModuleList()
last_dim = state_dim
for nh in hidden_size:
self.affine_layers.append(nn.Linear(last_dim, nh))
last_dim = nh
self.value_head = nn.Linear(last_dim, 1)
self.value_head.weight.data.mul_(0.1)
self.value_head.bias.data.mul_(0.0)
def forward(self, x):
for affine in self.affine_layers:
x = self.activation(affine(x))
value = self.value_head(x)
return value