public class DiscreteSamplingUtil
extends java.lang.Object
Constructor and Description |
---|
DiscreteSamplingUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
sampleIndexFromCumulativeProportions(java.util.Random random,
double[] cumulativeProportions)
Samples a random index from an array of cumulative proportions.
|
static int |
sampleIndexFromProbabilities(java.util.Random random,
double[] probabilities)
Samples an random index according to the given array of probabilities.
|
static int |
sampleIndexFromProbabilities(java.util.Random random,
Vector probabilities)
Samples an random index according to the given vector of probabilities.
|
static int |
sampleIndexFromProportions(java.util.Random random,
double[] proportions)
Samples a random index according to the given proportions.
|
static int |
sampleIndexFromProportions(java.util.Random random,
double[] proportions,
double proportionSum)
Samples a random index according to the given proportions.
|
static int[] |
sampleIndicesFromCumulativeProportions(java.util.Random random,
double[] cumulativeProportions,
int sampleSize)
Samples a multiple indices with replacement from an array of cumulative
proportions.
|
static int[] |
sampleIndicesFromProportions(java.util.Random random,
double[] proportions,
int sampleSize)
Samples an array of indices from a given set of proportions.
|
static <DataType> java.util.List<DataType> |
sampleWithoutReplacement(java.util.Random random,
java.util.List<DataType> data,
int sampleSize)
Samples a a given number of items from a list without replacement.
|
static <DataType> java.util.ArrayList<DataType> |
sampleWithReplacement(java.util.Random random,
java.util.List<? extends DataType> data,
int sampleSize)
Samples a a given number of items from a list with replacement.
|
static <DataType> void |
sampleWithReplacementInto(java.util.Random random,
java.util.List<? extends DataType> data,
int sampleSize,
java.util.Collection<? super DataType> result)
Samples a a given number of items from a list with replacement and puts
the samples into the given collection.
|
public static int sampleIndexFromProbabilities(java.util.Random random, double[] probabilities)
random
- The random number generator to use.probabilities
- The array of probabilities. Must sum to 1.0.public static int sampleIndexFromProbabilities(java.util.Random random, Vector probabilities)
random
- The random number generator to use.probabilities
- The vector of probabilities. Must sum to 1.0.public static int sampleIndexFromProportions(java.util.Random random, double[] proportions)
random
- The random number generator to use.proportions
- The array of proportions. All entries must be greater than or
equal to zero.public static int[] sampleIndicesFromProportions(java.util.Random random, double[] proportions, int sampleSize)
random
- The random number generator to use.proportions
- The array of proportions. All entries must be greater than or
equal to zero.sampleSize
- The number of samples to make.public static int sampleIndexFromProportions(java.util.Random random, double[] proportions, double proportionSum)
random
- The random number generator to use.proportions
- An array of proportions. None of the entries can be negative. It
must sum to proportionSum.proportionSum
- The sum of the given proportions array.public static int sampleIndexFromCumulativeProportions(java.util.Random random, double[] cumulativeProportions)
random
- The random number generator to use.cumulativeProportions
- The array of cumulative proportions. The entries must be
non-negative and monotonically increasing.public static int[] sampleIndicesFromCumulativeProportions(java.util.Random random, double[] cumulativeProportions, int sampleSize)
random
- The random number generator to use.cumulativeProportions
- The array of cumulative proportions. The entries must be
non-negative and monotonically increasing.sampleSize
- The number of samples to draw from the cumulative proportions.public static <DataType> java.util.ArrayList<DataType> sampleWithReplacement(java.util.Random random, java.util.List<? extends DataType> data, int sampleSize)
DataType
- The type of data in the list.random
- The random number generator.data
- The list to sample from.sampleSize
- The sample size. Must be positive.public static <DataType> void sampleWithReplacementInto(java.util.Random random, java.util.List<? extends DataType> data, int sampleSize, java.util.Collection<? super DataType> result)
DataType
- The type of data in the list.random
- The random number generator.data
- The list to sample from.sampleSize
- The sample size. Must be positive.result
- The resulting collection to sample into. All sampled elements will
be added to this collection..public static <DataType> java.util.List<DataType> sampleWithoutReplacement(java.util.Random random, java.util.List<DataType> data, int sampleSize)
DataType
- The type of data in the list.random
- The random number generator.data
- The list to sample from.sampleSize
- The sample size. Must be positive and less than or equal to
the data size.