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

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#NUMBER_TOO_SMALL . 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: TriangularDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a triangular real distribution using the given lower limit,
 * upper limit, and mode.
 *
 * @param a Lower limit of this distribution (inclusive).
 * @param b Upper limit of this distribution (inclusive).
 * @param c Mode of this distribution.
 * @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}
 * @throws NumberIsTooSmallException if {@code c < a}
 */
public TriangularDistribution(double a, double c, double b)
    throws NumberIsTooLargeException, NumberIsTooSmallException {
    if (a >= b) {
        throw new NumberIsTooLargeException(
                        LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                        a, b, false);
    }
    if (c < a) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
    }
    if (c > b) {
        throw new NumberIsTooLargeException(
                LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
    }

    this.a = a;
    this.c = c;
    this.b = b;
    solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
 
Example 2
Source File: MultivariateNormalMixtureExpectationMaximization.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an object to fit a multivariate normal mixture model to data.
 *
 * @param data Data to use in fitting procedure
 * @throws NotStrictlyPositiveException if data has no rows
 * @throws DimensionMismatchException if rows of data have different numbers
 *             of columns
 * @throws NumberIsTooSmallException if the number of columns in the data is
 *             less than 2
 */
public MultivariateNormalMixtureExpectationMaximization(double[][] data)
    throws NotStrictlyPositiveException,
           DimensionMismatchException,
           NumberIsTooSmallException {
    if (data.length < 1) {
        throw new NotStrictlyPositiveException(data.length);
    }

    this.data = new double[data.length][data[0].length];

    for (int i = 0; i < data.length; i++) {
        if (data[i].length != data[0].length) {
            // Jagged arrays not allowed
            throw new DimensionMismatchException(data[i].length,
                                                 data[0].length);
        }
        if (data[i].length < 2) {
            throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_TOO_SMALL,
                                                data[i].length, 2, true);
        }
        this.data[i] = MathArrays.copyOf(data[i], data[i].length);
    }
}
 
Example 3
Source File: Primes.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prime factors decomposition
 *
 * @param n number to factorize: must be &ge; 2
 * @return list of prime factors of n
 * @throws MathIllegalArgumentException if n &lt; 2.
 */
public static List<Integer> primeFactors(int n) {

    if (n < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2);
    }
    // slower than trial div unless we do an awful lot of computation
    // (then it finally gets JIT-compiled efficiently
    // List<Integer> out = PollardRho.primeFactors(n);
    return SmallPrimes.trialDivision(n);

}
 
Example 4
Source File: GmmSemi.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates an object to fit a multivariate normal mixture model to data.
 *
 * @param data Data to use in fitting procedure
 * @throws NotStrictlyPositiveException if data has no rows
 * @throws DimensionMismatchException if rows of data have different numbers
 *             of columns
 * @throws NumberIsTooSmallException if the number of columns in the data is
 *             less than 2
 */
public GmmSemi(double[][] data, double[] labels)
    throws NotStrictlyPositiveException,
           DimensionMismatchException,
           NumberIsTooSmallException {
    if (data.length < 1) {
        throw new NotStrictlyPositiveException(data.length);
    }

    this.data = new double[data.length][data[0].length];

    for (int i = 0; i < data.length; i++) {
        if (data[i].length != data[0].length) {
            // Jagged arrays not allowed
            throw new DimensionMismatchException(data[i].length,
                                                 data[0].length);
        }
        if (data[i].length < 2) {
            throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_TOO_SMALL,
                                                data[i].length, 2, true);
        }
        this.data[i] = MathArrays.copyOf(data[i], data[i].length);
    }

    if (labels==null || !(labels.length==data.length)) {
        throw new DimensionMismatchException(labels.length, data.length);
    }

    this.labels = MathArrays.copyOf(labels, labels.length);

}
 
Example 5
Source File: TriangularDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a triangular distribution.
 *
 * @param rng Random number generator.
 * @param a Lower limit of this distribution (inclusive).
 * @param b Upper limit of this distribution (inclusive).
 * @param c Mode of this distribution.
 * @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
 * @throws NumberIsTooSmallException if {@code c < a}.
 * @since 3.1
 */
public TriangularDistribution(RandomGenerator rng,
                              double a,
                              double c,
                              double b)
    throws NumberIsTooLargeException, NumberIsTooSmallException {
    super(rng);

    if (a >= b) {
        throw new NumberIsTooLargeException(
                        LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                        a, b, false);
    }
    if (c < a) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
    }
    if (c > b) {
        throw new NumberIsTooLargeException(
                LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
    }

    this.a = a;
    this.c = c;
    this.b = b;
    solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
 
Example 6
Source File: TriangularDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a triangular distribution.
 *
 * @param rng Random number generator.
 * @param a Lower limit of this distribution (inclusive).
 * @param b Upper limit of this distribution (inclusive).
 * @param c Mode of this distribution.
 * @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
 * @throws NumberIsTooSmallException if {@code c < a}.
 * @since 3.1
 */
public TriangularDistribution(RandomGenerator rng,
                              double a,
                              double c,
                              double b)
    throws NumberIsTooLargeException, NumberIsTooSmallException {
    super(rng);

    if (a >= b) {
        throw new NumberIsTooLargeException(
                        LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                        a, b, false);
    }
    if (c < a) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
    }
    if (c > b) {
        throw new NumberIsTooLargeException(
                LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
    }

    this.a = a;
    this.c = c;
    this.b = b;
    solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
 
Example 7
Source File: NumberIsTooSmallException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct the exception.
 *
 * @param wrong Value that is smaller than the minimum.
 * @param min Minimum.
 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
 */
public NumberIsTooSmallException(Number wrong,
                                 Number min,
                                 boolean boundIsAllowed) {
    this(boundIsAllowed ?
         LocalizedFormats.NUMBER_TOO_SMALL :
         LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
         wrong, min, boundIsAllowed);
}
 
Example 8
Source File: Primes.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the smallest prime greater than or equal to n.
 *
 * @param n a positive number.
 * @return the smallest prime greater than or equal to n.
 * @throws MathIllegalArgumentException if n &lt; 0.
 */
public static int nextPrime(int n) {
    if (n < 0) {
        throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 0);
    }
    if (n == 2) {
        return 2;
    }
    n = n | 1;//make sure n is odd
    if (n == 1) {
        return 2;
    }

    if (isPrime(n)) {
        return n;
    }

    // prepare entry in the +2, +4 loop:
    // n should not be a multiple of 3
    final int rem = n % 3;
    if (0 == rem) { // if n % 3 == 0
        n += 2; // n % 3 == 2
    } else if (1 == rem) { // if n % 3 == 1
        // if (isPrime(n)) return n;
        n += 4; // n % 3 == 2
    }
    while (true) { // this loop skips all multiple of 3
        if (isPrime(n)) {
            return n;
        }
        n += 2; // n % 3 == 1
        if (isPrime(n)) {
            return n;
        }
        n += 4; // n % 3 == 2
    }
}
 
Example 9
Source File: Primes.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the smallest prime greater than or equal to n.
 *
 * @param n a positive number.
 * @return the smallest prime greater than or equal to n.
 * @throws MathIllegalArgumentException if n &lt; 0.
 */
public static int nextPrime(int n) {
    if (n < 0) {
        throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 0);
    }
    if (n == 2) {
        return 2;
    }
    n = n | 1;//make sure n is odd
    if (n == 1) {
        return 2;
    }

    if (isPrime(n)) {
        return n;
    }

    // prepare entry in the +2, +4 loop:
    // n should not be a multiple of 3
    final int rem = n % 3;
    if (0 == rem) { // if n % 3 == 0
        n += 2; // n % 3 == 2
    } else if (1 == rem) { // if n % 3 == 1
        // if (isPrime(n)) return n;
        n += 4; // n % 3 == 2
    }
    while (true) { // this loop skips all multiple of 3
        if (isPrime(n)) {
            return n;
        }
        n += 2; // n % 3 == 1
        if (isPrime(n)) {
            return n;
        }
        n += 4; // n % 3 == 2
    }
}
 
Example 10
Source File: TriangularDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a triangular distribution.
 *
 * @param rng Random number generator.
 * @param a Lower limit of this distribution (inclusive).
 * @param b Upper limit of this distribution (inclusive).
 * @param c Mode of this distribution.
 * @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
 * @throws NumberIsTooSmallException if {@code c < a}.
 * @since 3.1
 */
public TriangularDistribution(RandomGenerator rng,
                              double a,
                              double c,
                              double b)
    throws NumberIsTooLargeException, NumberIsTooSmallException {
    super(rng);

    if (a >= b) {
        throw new NumberIsTooLargeException(
                        LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                        a, b, false);
    }
    if (c < a) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
    }
    if (c > b) {
        throw new NumberIsTooLargeException(
                LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
    }

    this.a = a;
    this.c = c;
    this.b = b;
    solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
 
Example 11
Source File: NumberIsTooSmallException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct the exception.
 *
 * @param wrong Value that is smaller than the minimum.
 * @param min Minimum.
 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
 */
public NumberIsTooSmallException(Number wrong,
                                 Number min,
                                 boolean boundIsAllowed) {
    this(boundIsAllowed ?
         LocalizedFormats.NUMBER_TOO_SMALL :
         LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
         wrong, min, boundIsAllowed);
}
 
Example 12
Source File: NumberIsTooSmallException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct the exception.
 *
 * @param wrong Value that is smaller than the minimum.
 * @param min Minimum.
 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
 */
public NumberIsTooSmallException(Number wrong,
                                 Number min,
                                 boolean boundIsAllowed) {
    this(boundIsAllowed ?
         LocalizedFormats.NUMBER_TOO_SMALL :
         LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
         wrong, min, boundIsAllowed);
}
 
Example 13
Source File: Primes.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prime factors decomposition
 *
 * @param n number to factorize: must be &ge; 2
 * @return list of prime factors of n
 * @throws MathIllegalArgumentException if n &lt; 2.
 */
public static List<Integer> primeFactors(int n) {

    if (n < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2);
    }
    // slower than trial div unless we do an awful lot of computation
    // (then it finally gets JIT-compiled efficiently
    // List<Integer> out = PollardRho.primeFactors(n);
    return SmallPrimes.trialDivision(n);

}
 
Example 14
Source File: NumberIsTooSmallException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct the exception.
 *
 * @param wrong Value that is smaller than the minimum.
 * @param min Minimum.
 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
 */
public NumberIsTooSmallException(Number wrong,
                                 Number min,
                                 boolean boundIsAllowed) {
    this(boundIsAllowed ?
         LocalizedFormats.NUMBER_TOO_SMALL :
         LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
         wrong, min, boundIsAllowed);
}
 
Example 15
Source File: TriangularDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a triangular distribution.
 *
 * @param rng Random number generator.
 * @param a Lower limit of this distribution (inclusive).
 * @param b Upper limit of this distribution (inclusive).
 * @param c Mode of this distribution.
 * @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
 * @throws NumberIsTooSmallException if {@code c < a}.
 * @since 3.1
 */
public TriangularDistribution(RandomGenerator rng,
                              double a,
                              double c,
                              double b)
    throws NumberIsTooLargeException, NumberIsTooSmallException {
    super(rng);

    if (a >= b) {
        throw new NumberIsTooLargeException(
                        LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                        a, b, false);
    }
    if (c < a) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
    }
    if (c > b) {
        throw new NumberIsTooLargeException(
                LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
    }

    this.a = a;
    this.c = c;
    this.b = b;
    solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
 
Example 16
Source File: Primes.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prime factors decomposition
 *
 * @param n number to factorize: must be &ge; 2
 * @return list of prime factors of n
 * @throws MathIllegalArgumentException if n &lt; 2.
 */
public static List<Integer> primeFactors(int n) {

    if (n < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2);
    }
    // slower than trial div unless we do an awful lot of computation
    // (then it finally gets JIT-compiled efficiently
    // List<Integer> out = PollardRho.primeFactors(n);
    return SmallPrimes.trialDivision(n);

}
 
Example 17
Source File: NumberIsTooSmallException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct the exception.
 *
 * @param wrong Value that is smaller than the minimum.
 * @param min Minimum.
 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
 */
public NumberIsTooSmallException(Number wrong,
                                 Number min,
                                 boolean boundIsAllowed) {
    this(boundIsAllowed ?
         LocalizedFormats.NUMBER_TOO_SMALL :
         LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
         wrong, min, boundIsAllowed);
}
 
Example 18
Source File: NumberIsTooSmallException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct the exception.
 *
 * @param wrong Value that is smaller than the minimum.
 * @param min Minimum.
 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
 */
public NumberIsTooSmallException(Number wrong,
                                 Number min,
                                 boolean boundIsAllowed) {
    this(boundIsAllowed ?
         LocalizedFormats.NUMBER_TOO_SMALL :
         LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
         wrong, min, boundIsAllowed);
}
 
Example 19
Source File: TriangularDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a triangular distribution.
 *
 * @param rng Random number generator.
 * @param a Lower limit of this distribution (inclusive).
 * @param b Upper limit of this distribution (inclusive).
 * @param c Mode of this distribution.
 * @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
 * @throws NumberIsTooSmallException if {@code c < a}.
 * @since 3.1
 */
public TriangularDistribution(RandomGenerator rng,
                              double a,
                              double c,
                              double b)
    throws NumberIsTooLargeException, NumberIsTooSmallException {
    super(rng);

    if (a >= b) {
        throw new NumberIsTooLargeException(
                        LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                        a, b, false);
    }
    if (c < a) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
    }
    if (c > b) {
        throw new NumberIsTooLargeException(
                LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
    }

    this.a = a;
    this.c = c;
    this.b = b;
    solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
 
Example 20
Source File: Primes.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prime factors decomposition
 *
 * @param n number to factorize: must be &ge; 2
 * @return list of prime factors of n
 * @throws MathIllegalArgumentException if n &lt; 2.
 */
public static List<Integer> primeFactors(int n) {

    if (n < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2);
    }
    // slower than trial div unless we do an awful lot of computation
    // (then it finally gets JIT-compiled efficiently
    // List<Integer> out = PollardRho.primeFactors(n);
    return SmallPrimes.trialDivision(n);

}