Class FastRandomSubsetSelector

java.lang.Object
com.irurueta.numerical.robust.SubsetSelector
com.irurueta.numerical.robust.FastRandomSubsetSelector

public class FastRandomSubsetSelector extends SubsetSelector
This class computes indices of subsets of samples using a uniform randomizer to pick random samples as fast as possible. This class ensures that samples are not repeated within a single subset.
  • Field Details

    • DEFAULT_SEED_RANDOMIZER_WITH_TIME

      public static final boolean DEFAULT_SEED_RANDOMIZER_WITH_TIME
      Constant defining whether randomizer needs to be initialized with system timer. By disabling this option it is ensured that the same result is obtained on each execution.
      See Also:
    • randomizer

      private com.irurueta.statistics.UniformRandomizer randomizer
      Randomizer to pick random indexes.
    • selectedIndices

      private final Set<Integer> selectedIndices
      Set containing selected indices on a given run. This is kept around between executions to avoid excessive calls to garbage collector, as random subset generation is likely to be called a large number of times during robust estimations. Because of that, if a robust estimator is capable of spanning multiple executions at once on different threads, then each thread needs to have a different subset selector instance.
  • Constructor Details

    • FastRandomSubsetSelector

      public FastRandomSubsetSelector(int numSamples)
      Constructor.
      Parameters:
      numSamples - number of samples to select subsets from
      Throws:
      IllegalArgumentException - if provided number of samples is zero or negative
    • FastRandomSubsetSelector

      public FastRandomSubsetSelector(int numSamples, boolean seedRandomizerWithTime)
      Constructor.
      Parameters:
      numSamples - number of samples to select subsets from.
      seedRandomizerWithTime - true if randomizer seed must be initialized to system timer to obtain more random results.
      Throws:
      IllegalArgumentException - if provided number of samples is zero or negative.
  • Method Details

    • getType

      public SubsetSelectorType getType()
      Returns type of this subset selector.
      Specified by:
      getType in class SubsetSelector
      Returns:
      type of this subset selector.
    • computeRandomSubsets

      public void computeRandomSubsets(int subsetSize, int[] result) throws NotEnoughSamplesException, InvalidSubsetSizeException
      Computes a random subset of indices within range of number of samples to be used on robust estimators.
      Specified by:
      computeRandomSubsets in class SubsetSelector
      Parameters:
      subsetSize - subset size to be computed. This value must be smaller than total number of samples.
      result - array containing indices to be picked. Provided array must be at least of length subsetSize. The former subsetSize entries of the array will be modified by this method.
      Throws:
      NotEnoughSamplesException - if subset size is greater than the total number of samples.
      InvalidSubsetSizeException - if subset size is zero or if result array does not have at least a length of subsetSize.
    • computeRandomSubsetsInRange

      public void computeRandomSubsetsInRange(int minPos, int maxPos, int subsetSize, boolean pickLast, int[] result) throws NotEnoughSamplesException, InvalidSubsetSizeException, InvalidSubsetRangeException
      Computes a random subset of indices within provided range of positions to be used on robust estimators.
      Specified by:
      computeRandomSubsetsInRange in class SubsetSelector
      Parameters:
      minPos - minimum position to be picked. This value must be greater or equal than zero and smaller than the total number of samples and less than maxPos.
      maxPos - maximum position to be picked. This value must be greater or equal than zero and smaller than the total number of samples and greater than minPos.
      subsetSize - subset size to be computed. This value must be smaller than total number of samples.
      pickLast - true indicates that last sample in range must always be picked within subset. This is done to obtain faster execution times and greater stability on some algorithms.
      result - array containing indices to be picked. Provided array must be at least of length subsetSize. The former subsetSize entries of the array will be modified by this method.
      Throws:
      NotEnoughSamplesException - if subset size is greater than the total number of samples or if maxPos is greater than the total number of samples.
      InvalidSubsetSizeException - if subset size is zero or if result array does not have at least a length of subsetSize, or ig subset size is greater than the allowed range of positions to be picked.
      InvalidSubsetRangeException - if maximum position is smaller than minimum position or maximum or minimum position are negative.
    • getRandomizer

      protected com.irurueta.statistics.UniformRandomizer getRandomizer()
      Returns internal randomizer to generate uniformly distributed random values.
      Returns:
      internal randomizer.
    • createRandomizer

      private void createRandomizer(boolean seedWithTime)
      Initializes randomizer for an instance of this class.
      Parameters:
      seedWithTime - if true randomizer will be initialized using current time as seed. If false, randomizer will always generate the same pseudo-random sequence on each JVM execution.