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

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#NUMBER_OF_TRIALS . 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: BinomialDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 2
Source File: IntervalUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies that parameters satisfy preconditions.
 *
 * @param numberOfTrials number of trials (must be positive)
 * @param numberOfSuccesses number of successes (must not exceed numberOfTrials)
 * @param confidenceLevel confidence level (must be strictly between 0 and 1)
 * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
 * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
 * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
 * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
 */
static void checkParameters(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    if (numberOfTrials <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_TRIALS, numberOfTrials);
    }
    if (numberOfSuccesses < 0) {
        throw new NotPositiveException(LocalizedFormats.NEGATIVE_NUMBER_OF_SUCCESSES, numberOfSuccesses);
    }
    if (numberOfSuccesses > numberOfTrials) {
        throw new NumberIsTooLargeException(LocalizedFormats.NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE,
                                            numberOfSuccesses, numberOfTrials, true);
    }
    if (confidenceLevel <= 0 || confidenceLevel >= 1) {
        throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_CONFIDENCE_LEVEL,
                                      confidenceLevel, 0, 1);
    }
}
 
Example 3
Source File: BinomialDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 4
Source File: BinomialDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 5
Source File: BinomialDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 6
Source File: BinomialDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 7
Source File: BinomialDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 8
Source File: BinomialDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 9
Source File: IntervalUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies that parameters satisfy preconditions.
 *
 * @param numberOfTrials number of trials (must be positive)
 * @param numberOfSuccesses number of successes (must not exceed numberOfTrials)
 * @param confidenceLevel confidence level (must be strictly between 0 and 1)
 * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
 * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
 * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
 * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
 */
static void checkParameters(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    if (numberOfTrials <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_TRIALS, numberOfTrials);
    }
    if (numberOfSuccesses < 0) {
        throw new NotPositiveException(LocalizedFormats.NEGATIVE_NUMBER_OF_SUCCESSES, numberOfSuccesses);
    }
    if (numberOfSuccesses > numberOfTrials) {
        throw new NumberIsTooLargeException(LocalizedFormats.NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE,
                                            numberOfSuccesses, numberOfTrials, true);
    }
    if (confidenceLevel <= 0 || confidenceLevel >= 1) {
        throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_CONFIDENCE_LEVEL,
                                      confidenceLevel, 0, 1);
    }
}
 
Example 10
Source File: BinomialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a binomial distribution with the given number of trials and
 * probability of success.
 *
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 */
public BinomialDistribution(int trials, double p) {
    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 11
Source File: BinomialDistribution.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng    Random number generator.
 * @param trials Number of trials.
 * @param p      Probability of success.
 * @throws org.apache.commons.math3.exception.NotPositiveException if {@code trials < 0}.
 * @throws org.apache.commons.math3.exception.OutOfRangeException  if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(Random rng, int trials, double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS, trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
Example 12
Source File: BinomialDistribution.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a binomial distribution.
 *
 * @param rng    Random number generator.
 * @param trials Number of trials.
 * @param p      Probability of success.
 * @throws org.apache.commons.math3.exception.NotPositiveException if {@code trials < 0}.
 * @throws org.apache.commons.math3.exception.OutOfRangeException  if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(Random rng, int trials, double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS, trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}