Package org.plumelib.util
Class MultiRandSelector<T extends @Nullable Object>
java.lang.Object
org.plumelib.util.MultiRandSelector<T>
- Type Parameters:
T
- the type of elements to be selected among
Performs uniform random selection over an iterator, where the objects in the iterator may be
partitioned so that the random selection chooses the same number from each group.
For example, given data about incomes by state, it may be desirable to select 1000 people from each state rather than 50,000 from the nation. As another example, for selecting invocations in a Daikon trace file, it may be desirable to select an equal number of samples per program point.
The performance is the same as running a set of RandomSelector Objects, one for each bucket, plus some overhead for determining which bucket to assign to each Object in the iteration.
To use this class, call accept(T)
on every Object in the iteration to be sampled. Then,
call valuesIter()
to receive an iteration of all the values selected by the random
selection.
- See Also:
-
Constructor Summary
ConstructorDescriptionMultiRandSelector
(double keepProbability, Random r, Partitioner<T, T> eq) Create a MultiRandSelector that chooses each element with probabilitykeepProbability
., using the given Random.MultiRandSelector
(double keepProbability, Partitioner<T, T> eq) Create a MultiRandSelector that chooses each element with probabilitykeepProbability
.MultiRandSelector
(int numElts, Random r, Partitioner<T, T> eq) Create a MultiRandSelector that choosesnumElts
from each partition, using the given Random.MultiRandSelector
(int numElts, Partitioner<T, T> eq) Create a MultiRandSelector that choosesnumElts
elements from each bucket. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Use the given value as one of the objects in the pool to select from.void
acceptIter
(Iterator<T> iter) Use all the iterator's elements in the pool to select from.Returns an iterator of all objects selected.
-
Constructor Details
-
MultiRandSelector
Create a MultiRandSelector that choosesnumElts
elements from each bucket.- Parameters:
numElts
- the number of elements to select from each bucketeq
- partioner that determines how to partition the objects
-
MultiRandSelector
Create a MultiRandSelector that chooses each element with probabilitykeepProbability
.- Parameters:
keepProbability
- the likelihood to select each elementeq
- partioner that determines how to partition the objects
-
MultiRandSelector
Create a MultiRandSelector that choosesnumElts
from each partition, using the given Random.- Parameters:
numElts
- the number of elements to select from each bucketr
- the Random instance to use for making random choiceseq
- partioner that determines how to partition the objects
-
MultiRandSelector
Create a MultiRandSelector that chooses each element with probabilitykeepProbability
., using the given Random.- Parameters:
keepProbability
- likelihood to select each elementr
- the Random instance to use for making random choiceseq
- partioner that determines how to partition the objects
-
-
Method Details
-
acceptIter
Use all the iterator's elements in the pool to select from.- Parameters:
iter
- contains elements that are added to the pool to select from
-
accept
Use the given value as one of the objects in the pool to select from.- Parameters:
next
- element that is added to the pool to select from
-
valuesIter
Returns an iterator of all objects selected.- Returns:
- an iterator of all objects selected
-