docstr: sample data from replay memory for training
          
code: def sample_batch(self, advantages, num_mini_batch=None):
      """sample data from replay memory for training"""
      episode_length, env_num = self.rewards.shape[0:2]
      batch_size = env_num * episode_length
      mini_batch_size = batch_size // num_mini_batch
  
      rand = torch.randperm(batch_size).numpy()
      sampler = [
          rand[i * mini_batch_size : (i + 1) * mini_batch_size]
          for i in range(num_mini_batch)
      ]
  
      share_obs = self.share_obs[:-1].reshape(
          -1, *self.share_obs.shape[2:]
      )
      obs = self.obs[:-1].reshape(-1, *self.obs.shape[2:])
      actions = self.actions.reshape(-1, self.actions.shape[-1])
      value_preds = self.value_preds[:-1].reshape(-1, 1)
      returns = self.returns[:-1].reshape(-1, 1)
      masks = self.masks[:-1].reshape(-1, 1)
      active_masks = self.active_masks[:-1].reshape(-1, 1)
      action_log_probs = self.action_log_probs.reshape(
          -1, self.action_log_probs.shape[-1]
      )
      advantages = advantages.reshape(-1, 1)
  
      for indices in sampler:
          share_obs_batch = share_obs[indices]
          obs_batch = obs[indices]
          actions_batch = actions[indices]
          value_preds_batch = value_preds[indices]
          return_batch = returns[indices]
          masks_batch = masks[indices]
          active_masks_batch = active_masks[indices]
          old_action_log_probs_batch = action_log_probs[indices]
          if advantages is None:
              adv_targ = None
          else:
              adv_targ = advantages[indices]
  
          yield share_obs_batch, obs_batch, actions_batch, value_preds_batch, return_batch, masks_batch, active_masks_batch, old_action_log_probs_batch, adv_targ
  
file_path: PARL/benchmark/torch/mappo/mappo_buffer.py
imports: import torch
  import numpy
label_desc: Use image node_id 5 for calling the SeparatedReplayBuffer obj's underlying member method code with example usage: obj.sample_batch(advantages, num_mini_batch) without return types