class_docstr: A sum tree data structure for storing replay priorities.
  
  A sum tree is a complete binary tree whose leaves contain values called
  priorities. Internal nodes maintain the sum of the priorities of all leaf
  nodes in their subtree.
  
  For capacity = 4, the tree may look like this:
  
               +---+
               |2.5|
               +-+-+
                 |
         +-------+--------+
         |                |
       +-+-+            +-+-+
       |1.5|            |1.0|
       +-+-+            +-+-+
         |                |
    +----+----+      +----+----+
    |         |      |         |
  +-+-+     +-+-+  +-+-+     +-+-+
  |0.5|     |1.0|  |0.5|     |0.5|
  +---+     +---+  +---+     +---+
  
  This is stored in a list of numpy arrays:
  self.nodes = [ [2.5], [1.5, 1], [0.5, 1, 0.5, 0.5] ]
  
  For conciseness, we allocate arrays as powers of two, and pad the excess
  elements with zero values.
  
  This is similar to the usual array-based representation of a complete binary
  tree, but is a little more user-friendly.
docstr: Creates the sum tree data structure for the given replay capacity.
  
  Args:
    capacity: int, the maximum number of elements that can be stored in this
      data structure.
  
  Raises:
    ValueError: If requested capacity is not positive.
docstr_tok: ["Creates","the","sum","tree","data","structure","for","the","given","replay","capacity",".","Args",":","capacity",":","int",",","the","maximum","number","of","elements","that","can","be","stored","in","this","data","structure",".","Raises",":","ValueError",":","If","requested","capacity","is","not","positive","."]
code: def __init__(self, capacity):
      """Creates the sum tree data structure for the given replay capacity.
  
      Args:
        capacity: int, the maximum number of elements that can be stored in this
          data structure.
  
      Raises:
        ValueError: If requested capacity is not positive.
      """
      assert isinstance(capacity, int)
      if capacity <= 0:
          raise ValueError(
              "Sum tree capacity should be positive. Got: {}".format(
                  capacity
              )
          )
  
      self.nodes = []
      tree_depth = int(math.ceil(np.log2(capacity)))
      level_size = 1
      for _ in range(tree_depth + 1):
          nodes_at_this_depth = np.zeros(level_size)
          self.nodes.append(nodes_at_this_depth)
  
          level_size *= 2
  
      self.max_recorded_priority = 1.0
  
file_path: dopamine/dopamine/replay_memory/sum_tree.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import random
  import numpy
label_desc: Use image node_id 1 to create a new SumTree object from inherited base classes: object with example: obj = SumTree(capacity)