@Override public void sampleInto( final Random random, final int sampleCount, final Collection<? super KeyType> output) { // Compute the cumulative weights final int size = this.getDomainSize(); double[] cumulativeWeights = new double[size]; double cumulativeSum = 0.0; ArrayList<KeyType> domain = new ArrayList<KeyType>(size); int index = 0; for (ScalarMap.Entry<KeyType> entry : this.entrySet()) { domain.add(entry.getKey()); final double value = entry.getValue(); cumulativeSum += value; cumulativeWeights[index] = cumulativeSum; index++; } ProbabilityMassFunctionUtil.sampleMultipleInto( cumulativeWeights, domain, random, sampleCount, output); }
@Override public void sampleInto( final Random random, final int sampleCount, final Collection<? super KeyType> output) { // Compute the cumulative weights final int size = this.getDomainSize(); double[] cumulativeWeights = new double[size]; double cumulativeSum = 0.0; ArrayList<KeyType> domain = new ArrayList<KeyType>(size); int index = 0; for (ScalarMap.Entry<KeyType> entry : this.entrySet()) { domain.add(entry.getKey()); final double value = entry.getValue(); cumulativeSum += value; cumulativeWeights[index] = cumulativeSum; index++; } ProbabilityMassFunctionUtil.sampleMultipleInto( cumulativeWeights, domain, random, sampleCount, output); }
@Override public void sampleInto( final Random random, final int sampleCount, final Collection<? super KeyType> output) { // Compute the cumulative weights final int size = this.getDomainSize(); double[] cumulativeWeights = new double[size]; double cumulativeSum = 0.0; ArrayList<KeyType> domain = new ArrayList<KeyType>(size); int index = 0; for (ScalarMap.Entry<KeyType> entry : this.entrySet()) { domain.add(entry.getKey()); final double value = entry.getValue(); cumulativeSum += value; cumulativeWeights[index] = cumulativeSum; index++; } ProbabilityMassFunctionUtil.sampleMultipleInto( cumulativeWeights, domain, random, sampleCount, output); }