Package com.irurueta.numerical.robust
Class SubsetSelector
java.lang.Object
com.irurueta.numerical.robust.SubsetSelector
- Direct Known Subclasses:
FastRandomSubsetSelector
Base class to pick subsets of samples.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SubsetSelectorType
Defines default subset selector type.static final int
Constant defining minimum amount of allowed samples.protected int
Total number of samples to pick subsets from. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]
computeRandomSubsets
(int subsetSize) Computes a random subset of indices within range of number of samples to be used on robust estimators.abstract void
computeRandomSubsets
(int subsetSize, int[] result) Computes a random subset of indices within range of number of samples to be used on robust estimators.int[]
computeRandomSubsetsInRange
(int minPos, int maxPos, int subsetSize, boolean pickLast) Computes a random subset of indices within provided range of positions to be used on robust estimators.abstract 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.static SubsetSelector
create
(int numSamples) Creates a new subset selector instance using provided total number of samples and default subset selector type.int
Returns number of samples to select subsets from.abstract SubsetSelectorType
getType()
Returns type of this subset selector.final void
setNumSamples
(int numSamples) Sets number of samples to select subsets from.
-
Field Details
-
MIN_NUM_SAMPLES
public static final int MIN_NUM_SAMPLESConstant defining minimum amount of allowed samples.- See Also:
-
DEFAULT_SUBSET_SELECTOR_TYPE
Defines default subset selector type. -
numSamples
protected int numSamplesTotal number of samples to pick subsets from. Subsets need to be always smaller or equal than total number of samples.
-
-
Constructor Details
-
SubsetSelector
protected SubsetSelector(int numSamples) Constructor.- Parameters:
numSamples
- number of samples to select subsets from.- Throws:
IllegalArgumentException
- if provided number of samples is zero or negative.
-
-
Method Details
-
getNumSamples
public int getNumSamples()Returns number of samples to select subsets from.- Returns:
- number of samples to select subsets from.
-
setNumSamples
public final void setNumSamples(int numSamples) Sets number of samples to select subsets from.- Parameters:
numSamples
- number of samples to select subsets from.- Throws:
IllegalArgumentException
- if provided number of samples is zero or negative.
-
computeRandomSubsets
public int[] computeRandomSubsets(int subsetSize) throws NotEnoughSamplesException, InvalidSubsetSizeException Computes a random subset of indices within range of number of samples to be used on robust estimators. If subsets need to be computed repeatedly in a small span of time then it is suggested to use computeRandomSubsets(int, int[]) for better memory usage.- Parameters:
subsetSize
- subset size to be computed. This value must be smaller than total number of samples.- Returns:
- array containing indices to be picked.
- 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.- See Also:
-
computeRandomSubsetsInRange
public int[] computeRandomSubsetsInRange(int minPos, int maxPos, int subsetSize, boolean pickLast) throws NotEnoughSamplesException, InvalidSubsetSizeException, InvalidSubsetRangeException Computes a random subset of indices within provided range of positions to be used on robust estimators. If subsets need to be computed repeatedly in a small span of time then it is suggested to use computeRandomSubsets(int, int, int, bool, int[]) for better memory usage.- 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.- Returns:
- array containing indices to be picked.
- 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 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.
-
getType
Returns type of this subset selector.- Returns:
- type of this subset selector.
-
computeRandomSubsets
public abstract 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.- 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 abstract 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.- 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 if 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.
-
create
Creates a new subset selector instance using provided total number of samples and default subset selector type.- Parameters:
numSamples
- number of samples to select subsets from.- Returns:
- a subset selector.
- Throws:
IllegalArgumentException
- if provided number of samples is zero or negative.
-