Package com.irurueta.numerical.robust
Class FastRandomSubsetSelector
java.lang.Object
com.irurueta.numerical.robust.SubsetSelector
com.irurueta.numerical.robust.FastRandomSubsetSelector
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final boolean
Constant defining whether randomizer needs to be initialized with system timer.private com.irurueta.statistics.UniformRandomizer
Randomizer to pick random indexes.Set containing selected indices on a given run.Fields inherited from class com.irurueta.numerical.robust.SubsetSelector
DEFAULT_SUBSET_SELECTOR_TYPE, MIN_NUM_SAMPLES, numSamples
-
Constructor Summary
ConstructorsConstructorDescriptionFastRandomSubsetSelector
(int numSamples) Constructor.FastRandomSubsetSelector
(int numSamples, boolean seedRandomizerWithTime) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
computeRandomSubsets
(int subsetSize, int[] result) Computes a random subset of indices within range of number of samples to be used on robust estimators.void
computeRandomSubsetsInRange
(int minPos, int maxPos, int subsetSize, boolean pickLast, int[] result) Computes a random subset of indices within provided range of positions to be used on robust estimators.private void
createRandomizer
(boolean seedWithTime) Initializes randomizer for an instance of this class.protected com.irurueta.statistics.UniformRandomizer
Returns internal randomizer to generate uniformly distributed random values.getType()
Returns type of this subset selector.Methods inherited from class com.irurueta.numerical.robust.SubsetSelector
computeRandomSubsets, computeRandomSubsetsInRange, create, getNumSamples, setNumSamples
-
Field Details
-
DEFAULT_SEED_RANDOMIZER_WITH_TIME
public static final boolean DEFAULT_SEED_RANDOMIZER_WITH_TIMEConstant 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 randomizerRandomizer to pick random indexes. -
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
Returns type of this subset selector.- Specified by:
getType
in classSubsetSelector
- 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 classSubsetSelector
- 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 classSubsetSelector
- 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.
-