docstr: input:
      obs (array): agent i's obs
      last_action (int): agent i's last action
      agent_id (int): agent index
      avail_actions (one_hot): available actions
      epsilon (float): e_greed discount
      test (bool): train or test
  output:
      action: int
      prob: probability of every action, float, 0 ~ 1
docstr_tok: ["input",":","obs","(","array",")",":","agent","i","'s","obs","last_action","(","int",")",":","agent","i","'s","last","action","agent_id","(","int",")",":","agent","index","avail_actions","(","one_hot",")",":","available","actions","epsilon","(","float",")",":","e_greed","discount","test","(","bool",")",":","train","or","test","output",":","action",":","int","prob",":","probability","of","every","action",",","float",",","0","~","1"]
code: def sample(
      self,
      obs,
      last_action,
      agent_id,
      avail_actions,
      epsilon,
      test=False,
  ):
      """input:
          obs (array): agent i's obs
          last_action (int): agent i's last action
          agent_id (int): agent index
          avail_actions (one_hot): available actions
          epsilon (float): e_greed discount
          test (bool): train or test
      output:
          action: int
          prob: probability of every action, float, 0 ~ 1
      """
      obs = obs.copy()
      # make obs: obs + agent's last action(one_hot) + agent's id(one_hot)
      last_act_one_hot = np.zeros(self.n_actions)
      last_act_one_hot[last_action] = 1.0
      id_one_hot = np.zeros(self.n_agents)
      id_one_hot[agent_id] = 1.0
      obs = np.hstack((obs, last_act_one_hot))
      obs = np.hstack((obs, id_one_hot))
  
      # predict action prob
      prob, self.rnn_h[agent_id] = self.predict(
          obs, self.rnn_h[agent_id]
      )
  
      # add noise
      avail_actions = (
          torch.tensor(avail_actions, dtype=torch.float32)
          .unsqueeze(0)
          .to(device)
      )  # shape: (1, n_actions)
      action_num = avail_actions.sum()  # how many actions are available
      prob = (1 - epsilon) * prob + torch.ones_like(
          prob
      ) * epsilon / action_num
      prob[avail_actions == 0] = 0.0  # set avail action
  
      # choose action
      if epsilon == 0 or test:
          action = torch.argmax(prob)
      else:
          action = Categorical(prob).sample().long()
      return action.cpu()
  
file_path: PARL/benchmark/torch/coma/sc2_agent.py
imports: import numpy
  import parl
  import torch
  from torch.distributions import Categorical
label_desc: Use image node_id 4 for calling the Agents obj's underlying member method code with example usage: obj.sample(obs, last_action, agent_id, avail_actions, epsilon, test) and returns: action