MCPcopy Create free account
hub / github.com/pytorch/examples / Policy

Class Policy

distributed/rpc/rl/main.py:50–70  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

48
49
50class 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
72class Observer:
73 r"""

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected