MCPcopy Create free account
hub / github.com/BIT-MCS/DRL-eFresh / forward

Method forward

utils/main_mp_github.py:22–32  ·  view source on GitHub ↗

Sample action from agents output distribution over actions.

(self, observation)

Source from the content-addressed store, hash-verified

20 self.rewards = []
21
22 def forward(self, observation):
23 """Sample action from agents output distribution over actions.
24 """
25 # Unsqueeze to give a batch size of 1.
26 state = torch.from_numpy(observation).float().unsqueeze(0)
27 action_scores, _ = self.agent(state)
28 action_probs = F.softmax(action_scores, dim=-1)
29 dist = torch.distributions.Categorical(action_probs)
30 action = dist.sample()
31 self.saved_log_probs.append(dist.log_prob(action))
32 return action.item()
33
34
35def finish_episode(optimizer, policy, config):

Callers

nothing calls this directly

Calls 1

sampleMethod · 0.95

Tested by

no test coverage detected