r""" Borrowing the ``Policy`` class from the Reinforcement Learning example. Copying the code to make these two examples independent. See https://github.com/pytorch/examples/tree/main/reinforcement_learning
| 48 | |
| 49 | |
| 50 | class Policy(nn.Module): |
| 51 | r""" |
| 52 | Borrowing the ``Policy`` class from the Reinforcement Learning example. |
| 53 | Copying the code to make these two examples independent. |
| 54 | See https://github.com/pytorch/examples/tree/main/reinforcement_learning |
| 55 | """ |
| 56 | def __init__(self): |
| 57 | super(Policy, self).__init__() |
| 58 | self.affine1 = nn.Linear(4, 128) |
| 59 | self.dropout = nn.Dropout(p=0.6) |
| 60 | self.affine2 = nn.Linear(128, 2) |
| 61 | |
| 62 | self.saved_log_probs = [] |
| 63 | self.rewards = [] |
| 64 | |
| 65 | def forward(self, x): |
| 66 | x = self.affine1(x) |
| 67 | x = self.dropout(x) |
| 68 | x = F.relu(x) |
| 69 | action_scores = self.affine2(x) |
| 70 | return F.softmax(action_scores, dim=1) |
| 71 | |
| 72 | class Observer: |
| 73 | r""" |