-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
38 lines (31 loc) · 945 Bytes
/
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 numpy as np
import torch.nn as nn
from torch.distributions import Normal
class PPO(nn.Module):
def __init__(self, num_inputs, num_outputs, std = 0.0):
super(PPO, self).__init__()
self.critic = nn.Sequential(
nn.Linear(num_inputs, 64),
nn.Tanh(),
nn.Linear(64, 64),
nn.Tanh(),
nn.Linear(64, 1)
)
# policy net
self.actor = nn.Sequential(
nn.Linear(num_inputs, 64),
nn.Tanh(),
nn.Linear(64, 64),
nn.Tanh(),
nn.Linear(64, num_outputs)
)
# std of action
self.std = nn.Parameter(torch.zeros(1, num_outputs) * std)
def forward(self, x):
mu = self.actor(x)
std = self.std.expand_as(mu)
action_std = torch.exp(std)
dist = Normal(mu, action_std)
value = self.critic(x)
return dist, value