parameters: (class_counts, n_draws, rng)
return_statement: return floored.astype(np.int)
docstring: Computes approximate mode of multivariate hypergeometric.
  
      This is an approximation to the mode of the multivariate
      hypergeometric given by class_counts and n_draws.
      It shouldn't be off by more than one.
  
      It is the mostly likely outcome of drawing n_draws many
      samples from the population given by class_counts.
  
      Parameters
      ----------
      class_counts : ndarray of int
          Population per class.
      n_draws : int
          Number of draws (samples to draw) from the overall population.
      rng : random state
          Used to break ties.
  
      Returns
      -------
      sampled_classes : ndarray of int
          Number of samples drawn from each class.
          np.sum(sampled_classes) == n_draws
  
      Examples
      --------
      >>> import numpy as np
      >>> from sklearn.utils import _approximate_mode
      >>> _approximate_mode(class_counts=np.array([4, 2]), n_draws=3, rng=0)
      array([2, 1])
      >>> _approximate_mode(class_counts=np.array([5, 2]), n_draws=4, rng=0)
      array([3, 1])
      >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
      ...                   n_draws=2, rng=0)
      array([0, 1, 1, 0])
      >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
      ...                   n_draws=2, rng=42)
      array([1, 1, 0, 0])
docstring_summary: Computes approximate mode of multivariate hypergeometric.
docstring_tokens: Computes approximate mode of multivariate hypergeometric .
function: def _approximate_mode(class_counts, n_draws, rng):
      """Computes approximate mode of multivariate hypergeometric.
  
      This is an approximation to the mode of the multivariate
      hypergeometric given by class_counts and n_draws.
      It shouldn't be off by more than one.
  
      It is the mostly likely outcome of drawing n_draws many
      samples from the population given by class_counts.
  
      Parameters
      ----------
      class_counts : ndarray of int
          Population per class.
      n_draws : int
          Number of draws (samples to draw) from the overall population.
      rng : random state
          Used to break ties.
  
      Returns
      -------
      sampled_classes : ndarray of int
          Number of samples drawn from each class.
          np.sum(sampled_classes) == n_draws
  
      Examples
      --------
      >>> import numpy as np
      >>> from sklearn.utils import _approximate_mode
      >>> _approximate_mode(class_counts=np.array([4, 2]), n_draws=3, rng=0)
      array([2, 1])
      >>> _approximate_mode(class_counts=np.array([5, 2]), n_draws=4, rng=0)
      array([3, 1])
      >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
      ...                   n_draws=2, rng=0)
      array([0, 1, 1, 0])
      >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
      ...                   n_draws=2, rng=42)
      array([1, 1, 0, 0])
      """
      rng = check_random_state(rng)
      # this computes a bad approximation to the mode of the
      # multivariate hypergeometric given by class_counts and n_draws
      continuous = n_draws * class_counts / class_counts.sum()
      # floored means we don't overshoot n_samples, but probably undershoot
      floored = np.floor(continuous)
      # we add samples according to how much "left over" probability
      # they had, until we arrive at n_samples
      need_to_add = int(n_draws - floored.sum())
      if need_to_add > 0:
          remainder = continuous - floored
          values = np.sort(np.unique(remainder))[::-1]
          # add according to remainder, but break ties
          # randomly to avoid biases
          for value in values:
              inds, = np.where(remainder == value)
              # if we need_to_add less than what's in inds
              # we draw randomly from them.
              # if we need to add more, we add them all and
              # go to the next value
              add_now = min(len(inds), need_to_add)
              inds = rng.choice(inds, size=add_now, replace=False)
              floored[inds] += 1
              need_to_add -= add_now
              if need_to_add == 0:
                  break
      return floored.astype(np.int)
function_tokens: def _approximate_mode ( class_counts , n_draws , rng ) : rng = check_random_state ( rng ) # this computes a bad approximation to the mode of the # multivariate hypergeometric given by class_counts and n_draws continuous = n_draws * class_counts / class_counts . sum ( ) # floored means we don't overshoot n_samples, but probably undershoot floored = np . floor ( continuous ) # we add samples according to how much "left over" probability # they had, until we arrive at n_samples need_to_add = int ( n_draws - floored . sum ( ) ) if need_to_add > 0 : remainder = continuous - floored values = np . sort ( np . unique ( remainder ) ) [ : : - 1 ] # add according to remainder, but break ties # randomly to avoid biases for value in values : inds , = np . where ( remainder == value ) # if we need_to_add less than what's in inds # we draw randomly from them. # if we need to add more, we add them all and # go to the next value add_now = min ( len ( inds ) , need_to_add ) inds = rng . choice ( inds , size = add_now , replace = False ) floored [ inds ] += 1 need_to_add -= add_now if need_to_add == 0 : break return floored . astype ( np . int )