Class SubsetSamplerUtils

java.lang.Object
org.apache.commons.rng.sampling.SubsetSamplerUtils

final class SubsetSamplerUtils extends Object
Utility class for selecting a subset of a sequence of integers.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    No public construction.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static void
    checkSubset(int n, int k)
    Checks the subset of length k from n is valid.
    (package private) static int[]
    partialSample(int[] domain, int steps, UniformRandomProvider rng, boolean upper)
    Perform a partial Fisher-Yates shuffle of the domain in-place and return either the upper fully shuffled section or the remaining lower partially shuffled section.
    (package private) static void
    swap(int[] array, int i, int j)
    Swaps the two specified elements in the specified array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SubsetSamplerUtils

      private SubsetSamplerUtils()
      No public construction.
  • Method Details

    • checkSubset

      static void checkSubset(int n, int k)
      Checks the subset of length k from n is valid.

      If n <= 0 or k <= 0 or k > n then no subset is required and an exception is raised.

      Parameters:
      n - Size of the set.
      k - Size of the subset.
      Throws:
      IllegalArgumentException - if n <= 0 or k <= 0 or k > n.
    • partialSample

      static int[] partialSample(int[] domain, int steps, UniformRandomProvider rng, boolean upper)
      Perform a partial Fisher-Yates shuffle of the domain in-place and return either the upper fully shuffled section or the remaining lower partially shuffled section.

      The returned combination will have a length of steps for upper=true, or domain.length - steps otherwise.

      Sampling uses UniformRandomProvider.nextInt(int).

      Parameters:
      domain - The domain.
      steps - The number of shuffle steps.
      rng - Generator of uniformly distributed random numbers.
      upper - Set to true to return the upper fully shuffled section.
      Returns:
      a random combination.
    • swap

      static void swap(int[] array, int i, int j)
      Swaps the two specified elements in the specified array.
      Parameters:
      array - the array
      i - the first index
      j - the second index