/** * Samples a multiple indices with replacement from an array of cumulative * proportions. * * @param random * The random number generator to use. * @param cumulativeProportions * The array of cumulative proportions. The entries must be * non-negative and monotonically increasing. * @param sampleSize * The number of samples to draw from the cumulative proportions. * @return * An array of indices of sampled with replacement according to * the given cumulative proportions. */ public static int[] sampleIndicesFromCumulativeProportions( final Random random, final double[] cumulativeProportions, final int sampleSize) { final int[] result = new int[sampleSize]; for (int i = 0; i < sampleSize; i++) { result[i] = sampleIndexFromCumulativeProportions( random, cumulativeProportions); } return result; }
/** * Samples a multiple indices with replacement from an array of cumulative * proportions. * * @param random * The random number generator to use. * @param cumulativeProportions * The array of cumulative proportions. The entries must be * non-negative and monotonically increasing. * @param sampleSize * The number of samples to draw from the cumulative proportions. * @return * An array of indices of sampled with replacement according to * the given cumulative proportions. */ public static int[] sampleIndicesFromCumulativeProportions( final Random random, final double[] cumulativeProportions, final int sampleSize) { final int[] result = new int[sampleSize]; for (int i = 0; i < sampleSize; i++) { result[i] = sampleIndexFromCumulativeProportions( random, cumulativeProportions); } return result; }
/** * Samples a multiple indices with replacement from an array of cumulative * proportions. * * @param random * The random number generator to use. * @param cumulativeProportions * The array of cumulative proportions. The entries must be * non-negative and monotonically increasing. * @param sampleSize * The number of samples to draw from the cumulative proportions. * @return * An array of indices of sampled with replacement according to * the given cumulative proportions. */ public static int[] sampleIndicesFromCumulativeProportions( final Random random, final double[] cumulativeProportions, final int sampleSize) { final int[] result = new int[sampleSize]; for (int i = 0; i < sampleSize; i++) { result[i] = sampleIndexFromCumulativeProportions( random, cumulativeProportions); } return result; }
return DiscreteSamplingUtil.sampleIndexFromCumulativeProportions(this.random, topicCumulativeProportions);
return DiscreteSamplingUtil.sampleIndexFromCumulativeProportions(this.random, topicCumulativeProportions);
return DiscreteSamplingUtil.sampleIndexFromCumulativeProportions(this.random, topicCumulativeProportions);
/** * Samples an element from the domain proportionately to the * cumulative weights in the given weight array using a fast * binary search algorithm. * @param <DataType> * Type of data to be sampled * @param cumulativeWeights * Cumulative weights to sample from * @param domain * Domain from which to sample * @param random * Random number generator * @return * A sample from the domain according to the weights. */ public static <DataType> DataType sample( final double[] cumulativeWeights, final List<? extends DataType> domain, final Random random) { final int index = DiscreteSamplingUtil.sampleIndexFromCumulativeProportions( random, cumulativeWeights); return domain.get(index); }
/** * Samples an element from the domain proportionately to the * cumulative weights in the given weight array using a fast * binary search algorithm. * @param <DataType> * Type of data to be sampled * @param cumulativeWeights * Cumulative weights to sample from * @param domain * Domain from which to sample * @param random * Random number generator * @return * A sample from the domain according to the weights. */ public static <DataType> DataType sample( final double[] cumulativeWeights, final List<? extends DataType> domain, final Random random) { final int index = DiscreteSamplingUtil.sampleIndexFromCumulativeProportions( random, cumulativeWeights); return domain.get(index); }
/** * Samples an element from the domain proportionately to the * cumulative weights in the given weight array using a fast * binary search algorithm. * @param <DataType> * Type of data to be sampled * @param cumulativeWeights * Cumulative weights to sample from * @param domain * Domain from which to sample * @param random * Random number generator * @return * A sample from the domain according to the weights. */ public static <DataType> DataType sample( final double[] cumulativeWeights, final List<? extends DataType> domain, final Random random) { final int index = DiscreteSamplingUtil.sampleIndexFromCumulativeProportions( random, cumulativeWeights); return domain.get(index); }
return DiscreteSamplingUtil.sampleIndexFromCumulativeProportions( this.getRandom(), cumulativeDistribution);
return DiscreteSamplingUtil.sampleIndexFromCumulativeProportions( this.getRandom(), cumulativeDistribution);
return DiscreteSamplingUtil.sampleIndexFromCumulativeProportions( this.getRandom(), cumulativeDistribution);