class_docstr: Proportional Prioritized Experience Replay.
      
class_docstr_tok: ["Proportional","Prioritized","Experience","Replay","."]
docstr: sample a batch of `seg_num` transitions
  Args:
      beta: float, degree of using importance sampling weights,
          0 - no corrections, 1 - full correction
  
  Return:
      items: sampled transitions
      indices: idxs of sampled items, used to update priorities later
      sample_weights: importance sampling weight
docstr_tok: ["sample","a","batch","of","`","seg_num","`","transitions","Args",":","beta",":","float",",","degree","of","using","importance","sampling","weights",",","0","-","no","corrections",",","1","-","full","correction","Return",":","items",":","sampled","transitions","indices",":","idxs","of","sampled","items",",","used","to","update","priorities","later","sample_weights",":","importance","sampling","weight"]
code: def sample(self, beta=1):
      """sample a batch of `seg_num` transitions
      Args:
          beta: float, degree of using importance sampling weights,
              0 - no corrections, 1 - full correction
  
      Return:
          items: sampled transitions
          indices: idxs of sampled items, used to update priorities later
          sample_weights: importance sampling weight
      """
      assert self.elements.full(), "The replay memory is not full!"
      seg_size = self.elements.total_p / self.seg_num
      seg_bound = [
          (seg_size * i, seg_size * (i + 1))
          for i in range(self.seg_num)
      ]
      items, indices, priorities = [], [], []
      for low, high in seg_bound:
          sample_val = np.random.uniform(low, high)
          _, tree_idx, priority = self.elements.retrieve(sample_val)
          elem_idx = tree_idx - self.elements.capacity + 1
          item = self._get_stacked_item(elem_idx)
          items.append(item)
          indices.append(tree_idx)
          priorities.append(priority)
  
      batch_probs = (
          self.size * np.array(priorities) / self.elements.total_p
      )
      min_prob = self.size * self.elements._min / self.elements.total_p
      sample_weights = np.power(batch_probs / min_prob, -beta)
      return np.array(items), np.array(indices), sample_weights
  
file_path: PARL/benchmark/fluid/Prioritized_DQN/proportional_per.py
imports: import numpy
label_desc: Use image node_id 6 for calling the ProportionalPER obj's underlying member method code with example usage: obj.sample(beta) and returns: np,  np,  sample_weights