| 3 | import paddle.nn.functional as F |
| 4 | |
| 5 | class Actor(nn.Layer): |
| 6 | def __init__(self, state_dim, action_dim, max_action): |
| 7 | super(Actor, self).__init__() |
| 8 | |
| 9 | self.l1 = nn.Linear(state_dim, 400) |
| 10 | self.l2 = nn.Linear(400, 300) |
| 11 | self.l3 = nn.Linear(300, action_dim) |
| 12 | |
| 13 | self.max_action = max_action |
| 14 | |
| 15 | def forward(self, state): |
| 16 | a = F.relu(self.l1(state)) |
| 17 | a = F.relu(self.l2(a)) |
| 18 | |
| 19 | return self.max_action * F.tanh(self.l3(a)) |
| 20 | |
| 21 | def select_action(self, state): |
| 22 | state = paddle.to_tensor(state.reshape(1, -1)).astype('float32') |
| 23 | return self.forward(state).numpy()[0] |
| 24 | |
| 25 | class Critic(nn.Layer): |
| 26 | def __init__(self, state_dim, action_dim): |