Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#NUMBER_OF_SAMPLES

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#NUMBER_OF_SAMPLES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 1_DiscreteDistribution.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Generate a random sample from the distribution.
     *
     * @param sampleSize the number of random values to generate.
     * @return an array representing the random sample.
     * @throws NotStrictlyPositiveException if {@code sampleSize} is not
     * positive.
     */
    public T[] sample(int sampleSize) throws NotStrictlyPositiveException {
        if (sampleSize <= 0) {
            throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                    sampleSize);
        }

        final T[]out = (T[]) java.lang.reflect.Array.newInstance(singletons.get(0).getClass(), sampleSize);

// start of generated patch
for(int i=sampleSize;i<sampleSize;i++){
out[i]=sample();
}
// end of generated patch
/* start of original code
        for (int i = 0; i < sampleSize; i++) {
            out[i] = sample();
        }
 end of original code*/

        return out;

    }
 
Example 2
Source File: JGenProg2017_0035_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Generate a random sample from the distribution.
 *
 * @param sampleSize the number of random values to generate.
 * @return an array representing the random sample.
 * @throws NotStrictlyPositiveException if {@code sampleSize} is not
 * positive.
 */
public T[] sample(int sampleSize) throws NotStrictlyPositiveException {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                sampleSize);
    }

    final T[]out = (T[]) java.lang.reflect.Array.newInstance(singletons.get(0).getClass(), sampleSize);

    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }

    return out;

}
 
Example 3
Source File: Arja_00158_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Generate a random sample from the distribution.
 *
 * @param sampleSize the number of random values to generate.
 * @return an array representing the random sample.
 * @throws NotStrictlyPositiveException if {@code sampleSize} is not
 * positive.
 */
public T[] sample(int sampleSize) throws NotStrictlyPositiveException {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                sampleSize);
    }

    final T[]out = (T[]) java.lang.reflect.Array.newInstance(singletons.get(0).getClass(), sampleSize);

    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }

    return out;

}
 
Example 4
Source File: JGenProg2017_0070_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Generate a random sample from the distribution.
 *
 * @param sampleSize the number of random values to generate.
 * @return an array representing the random sample.
 * @throws NotStrictlyPositiveException if {@code sampleSize} is not
 * positive.
 */
public T[] sample(int sampleSize) throws NotStrictlyPositiveException {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                sampleSize);
    }

    final T[]out = (T[]) java.lang.reflect.Array.newInstance(singletons.get(0).getClass(), sampleSize);

    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }

    return out;

}
 
Example 5
Source File: Cardumen_00179_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Generate a random sample from the distribution.
 *
 * @param sampleSize the number of random values to generate.
 * @return an array representing the random sample.
 * @throws NotStrictlyPositiveException if {@code sampleSize} is not
 * positive.
 */
public T[] sample(int sampleSize) throws NotStrictlyPositiveException {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                sampleSize);
    }

    final T[]out = (T[]) java.lang.reflect.Array.newInstance(singletons.get(0).getClass(), sampleSize);

   for (int i = 0; sampleSize < sampleSize; i++) {
        out[i] = sample();
    }

    return out;

}
 
Example 6
Source File: AbstractIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 7
Source File: jMutRepair_008_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 8
Source File: AbstractIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 9
Source File: HypergeometricDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new hypergeometric distribution.
 *
 * @param rng Random number generator.
 * @param populationSize Population size.
 * @param numberOfSuccesses Number of successes in the population.
 * @param sampleSize Sample size.
 * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
 * @throws NotStrictlyPositiveException if {@code populationSize <= 0}.
 * @throws NumberIsTooLargeException if {@code numberOfSuccesses > populationSize},
 * or {@code sampleSize > populationSize}.
 * @since 3.1
 */
public HypergeometricDistribution(RandomGenerator rng,
                                  int populationSize,
                                  int numberOfSuccesses,
                                  int sampleSize)
throws NotPositiveException, NotStrictlyPositiveException, NumberIsTooLargeException {
    super(rng);

    if (populationSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.POPULATION_SIZE,
                                               populationSize);
    }
    if (numberOfSuccesses < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_SUCCESSES,
                                       numberOfSuccesses);
    }
    if (sampleSize < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                                       sampleSize);
    }

    if (numberOfSuccesses > populationSize) {
        throw new NumberIsTooLargeException(LocalizedFormats.NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE,
                                            numberOfSuccesses, populationSize, true);
    }
    if (sampleSize > populationSize) {
        throw new NumberIsTooLargeException(LocalizedFormats.SAMPLE_SIZE_LARGER_THAN_POPULATION_SIZE,
                                            sampleSize, populationSize, true);
    }

    this.numberOfSuccesses = numberOfSuccesses;
    this.populationSize = populationSize;
    this.sampleSize = sampleSize;
}
 
Example 10
Source File: Arja_00176_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 11
Source File: Arja_00176_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 12
Source File: JGenProg2017_0070_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Generate a random sample from the distribution.
 *
 * @param sampleSize the number of random values to generate.
 * @return an array representing the random sample.
 * @throws NotStrictlyPositiveException if {@code sampleSize} is not
 * positive.
 */
public T[] sample(int sampleSize) throws NotStrictlyPositiveException {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                sampleSize);
    }

    final T[]out = (T[]) java.lang.reflect.Array.newInstance(singletons.get(0).getClass(), sampleSize);

    for (int i = 0; i < sampleSize; i++) {
    }

    return out;

}
 
Example 13
Source File: AbstractRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public double[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                sampleSize);
    }
    double[] out = new double[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 14
Source File: AbstractMultivariateRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double[][] sample(final int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                                               sampleSize);
    }
    final double[][] out = new double[sampleSize][dimension];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 15
Source File: Arja_00153_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 16
Source File: AbstractRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public double[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                sampleSize);
    }
    double[] out = new double[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 17
Source File: JGenProg2017_0088_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 18
Source File: Cardumen_00162_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Creates a new hypergeometric distribution.
 *
 * @param rng Random number generator.
 * @param populationSize Population size.
 * @param numberOfSuccesses Number of successes in the population.
 * @param sampleSize Sample size.
 * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
 * @throws NotStrictlyPositiveException if {@code populationSize <= 0}.
 * @throws NumberIsTooLargeException if {@code numberOfSuccesses > populationSize},
 * or {@code sampleSize > populationSize}.
 * @since 3.1
 */
public HypergeometricDistribution(RandomGenerator rng,
                                  int populationSize,
                                  int numberOfSuccesses,
                                  int sampleSize)
throws NotPositiveException, NotStrictlyPositiveException, NumberIsTooLargeException {
    super(rng);

    if (populationSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.POPULATION_SIZE,
                                               populationSize);
    }
    if (numberOfSuccesses < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_SUCCESSES,
                                       numberOfSuccesses);
    }
    if (sampleSize < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                                       sampleSize);
    }

    if (numberOfSuccesses > populationSize) {
        throw new NumberIsTooLargeException(LocalizedFormats.NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE,
                                            numberOfSuccesses, populationSize, true);
    }
    if (sampleSize > populationSize) {
        throw new NumberIsTooLargeException(LocalizedFormats.SAMPLE_SIZE_LARGER_THAN_POPULATION_SIZE,
                                            sampleSize, populationSize, true);
    }

    this.numberOfSuccesses = numberOfSuccesses;
    this.populationSize = populationSize;
    this.sampleSize = sampleSize;
}
 
Example 19
Source File: Elixir_0020_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}
 
Example 20
Source File: Cardumen_00106_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation generates the sample by calling
 * {@link #sample()} in a loop.
 */
public int[] sample(int sampleSize) {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(
                LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }
    int[] out = new int[sampleSize];
    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }
    return out;
}