class_docstr: Implementation of Walker's alias method.
  
  This method generates a random sample from given probabilities
  :math:`p_1, \dots, p_n` in :math:`O(1)` time.
  It is more efficient than :func:`~numpy.random.choice`.
  This class works on both CPU and GPU.
  
  Args:
      probs (float list): Probabilities of entries. They are normalized with
                          `sum(probs)`.
  
  See: `Wikipedia article <https://en.wikipedia.org/wiki/Alias_method>`_
code: def __init__(self, probs):
      super(WalkerAlias, self).__init__()
  
      prob = numpy.array(probs, numpy.float32)
      prob /= numpy.sum(prob)
      threshold = numpy.ndarray(len(probs), numpy.float32)
      values = numpy.ndarray(len(probs) * 2, numpy.int32)
      il, ir = 0, 0
      pairs = list(zip(prob, range(len(probs))))
      pairs.sort()
      for prob, i in pairs:
          p = prob * len(probs)
          while p > 1 and ir < il:
              values[ir * 2 + 1] = i
              p -= 1.0 - threshold[ir]
              ir += 1
          threshold[il] = p
          values[il * 2] = i
          il += 1
      # fill the rest
      for i in range(ir, len(probs)):
          values[i * 2 + 1] = 0
  
      assert (values < len(threshold)).all()
      self.threshold = threshold
      self.values = values
  
file_path: chainer/chainer/utils/walker_alias.py
imports: import numpy
  import chainer
  from chainer.backends import cuda
  from chainer import device_resident
label_desc: Use image node_id 1 to create a new WalkerAlias object from inherited base classes: device_resident with example: obj = WalkerAlias(probs)