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: Sets the value of a leaf node and updates internal nodes accordingly.
  
  This operation takes O(log(capacity)).
  Args:
    node_index: int, the index of the leaf node to be updated.
    value: float, the value which we assign to the node. This value must be
      nonnegative. Setting value = 0 will cause the element to never be
      sampled.
  
  Raises:
    ValueError: If the given value is negative.
docstr_tok: ["Sets","the","value","of","a","leaf","node","and","updates","internal","nodes","accordingly",".","This","operation","takes","O","(","log","(","capacity",")",")",".","Args",":","node_index",":","int",",","the","index","of","the","leaf","node","to","be","updated",".","value",":","float",",","the","value","which","we","assign","to","the","node",".","This","value","must","be","nonnegative",".","Setting","value","=","0","will","cause","the","element","to","never","be","sampled",".","Raises",":","ValueError",":","If","the","given","value","is","negative","."]
code: def set(self, node_index, value):
      """Sets the value of a leaf node and updates internal nodes accordingly.
  
      This operation takes O(log(capacity)).
      Args:
        node_index: int, the index of the leaf node to be updated.
        value: float, the value which we assign to the node. This value must be
          nonnegative. Setting value = 0 will cause the element to never be
          sampled.
  
      Raises:
        ValueError: If the given value is negative.
      """
      if value < 0.0:
          raise ValueError(
              "Sum tree values should be nonnegative. Got {}".format(
                  value
              )
          )
      self.max_recorded_priority = max(
          value, self.max_recorded_priority
      )
  
      delta_value = value - self.nodes[-1][node_index]
  
      # Now traverse back the tree, adjusting all sums along the way.
      for nodes_at_this_depth in reversed(self.nodes):
          # Note: Adding a delta leads to some tolerable numerical inaccuracies.
          nodes_at_this_depth[node_index] += delta_value
          node_index //= 2
  
      assert node_index == 0, (
          "Sum tree traversal failed, final node index " "is not 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 6 for calling the SumTree obj's underlying member method code with example usage: obj.set(node_index, value) without return types