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

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#INFINITE_BOUND . 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: RandomDataGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws NumberIsTooLargeException if {@code lower >= upper}
 * @throws NotFiniteNumberException if one of the bounds is infinite
 * @throws NotANumberException if one of the bounds is NaN
 */
public double nextUniform(double lower, double upper, boolean lowerInclusive)
    throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, lower);
    }
    if (Double.isInfinite(upper)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, upper);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new NotANumberException();
    }

    final RandomGenerator generator = getRandomGenerator();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}
 
Example 2
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws N if one of the bounds is infinite or
 * {@code NaN}
 * @throws NumberIsTooLargeException if {@code lower >= upper}
 * @throws NotFiniteNumberException if one of the bounds is infinite
 * @throws NotANumberException if one of the bounds is not a number
 */
public double nextUniform(double lower, double upper, boolean lowerInclusive)
    throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, lower);
    }
    if (Double.isInfinite(upper)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, upper);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new NotANumberException();
    }

    final RandomGenerator generator = getRan();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}
 
Example 3
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws MathIllegalArgumentException if one of the bounds is infinite or
 * {@code NaN}
 * @since 3.0
 */
public double nextUniform(double lower, double upper,
    boolean lowerInclusive) {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower) || Double.isInfinite(upper)) {
        throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_BOUND);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new MathIllegalArgumentException(LocalizedFormats.NAN_NOT_ALLOWED);
    }

    final RandomGenerator generator = getRan();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}
 
Example 4
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws NumberIsTooLargeException if {@code lower >= upper}
 * @throws NotFiniteNumberException if one of the bounds is infinite
 * @throws NotANumberException if one of the bounds is NaN
 */
public double nextUniform(double lower, double upper, boolean lowerInclusive)
    throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, lower);
    }
    if (Double.isInfinite(upper)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, upper);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new NotANumberException();
    }

    final RandomGenerator generator = getRandomGenerator();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}
 
Example 5
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws MathIllegalArgumentException if one of the bounds is infinite or
 * {@code NaN}
 * @since 3.0
 */
public double nextUniform(double lower, double upper,
    boolean lowerInclusive) {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower) || Double.isInfinite(upper)) {
        throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_BOUND);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new MathIllegalArgumentException(LocalizedFormats.NAN_NOT_ALLOWED);
    }

    final RandomGenerator generator = getRan();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}
 
Example 6
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws NumberIsTooLargeException if {@code lower >= upper}
 * @throws NotFiniteNumberException if one of the bounds is infinite
 * @throws NotANumberException if one of the bounds is NaN
 */
public double nextUniform(double lower, double upper, boolean lowerInclusive)
    throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, lower);
    }
    if (Double.isInfinite(upper)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, upper);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new NotANumberException();
    }

    final RandomGenerator generator = getRandomGenerator();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}
 
Example 7
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws NumberIsTooLargeException if {@code lower >= upper}
 * @throws NotFiniteNumberException if one of the bounds is infinite
 * @throws NotANumberException if one of the bounds is NaN
 */
public double nextUniform(double lower, double upper, boolean lowerInclusive)
    throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, lower);
    }
    if (Double.isInfinite(upper)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, upper);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new NotANumberException();
    }

    final RandomGenerator generator = getRandomGenerator();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}
 
Example 8
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: if the lower bound is excluded,
 * scales the output of Random.nextDouble(), but rejects 0 values (i.e.,
 * will generate another random double if Random.nextDouble() returns 0).
 * This is necessary to provide a symmetric output interval (both
 * endpoints excluded).
 * </p>
 *
 * @throws NumberIsTooLargeException if {@code lower >= upper}
 * @throws NotFiniteNumberException if one of the bounds is infinite
 * @throws NotANumberException if one of the bounds is NaN
 */
public double nextUniform(double lower, double upper, boolean lowerInclusive)
    throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException {

    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }

    if (Double.isInfinite(lower)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, lower);
    }
    if (Double.isInfinite(upper)) {
        throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, upper);
    }

    if (Double.isNaN(lower) || Double.isNaN(upper)) {
        throw new NotANumberException();
    }

    final RandomGenerator generator = getRandomGenerator();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (!lowerInclusive && u <= 0.0) {
        u = generator.nextDouble();
    }

    return u * upper + (1.0 - u) * lower;
}