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

Class Policy

distributed/rpc/batch/reinforce.py:40–58  ·  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

38
39
40class Policy(nn.Module):
41 r"""
42 Borrowing the ``Policy`` class from the Reinforcement Learning example.
43 Copying the code to make these two examples independent.
44 See https://github.com/pytorch/examples/tree/main/reinforcement_learning
45 """
46 def __init__(self, batch=True):
47 super(Policy, self).__init__()
48 self.affine1 = nn.Linear(4, 128)
49 self.dropout = nn.Dropout(p=0.6)
50 self.affine2 = nn.Linear(128, 2)
51 self.dim = 2 if batch else 1
52
53 def forward(self, x):
54 x = self.affine1(x)
55 x = self.dropout(x)
56 x = F.relu(x)
57 action_scores = self.affine2(x)
58 return F.softmax(action_scores, dim=self.dim)
59
60
61class Observer:

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected