org.apache.commons.math3.exception.NotFiniteNumberException Java Examples

The following examples show how to use org.apache.commons.math3.exception.NotFiniteNumberException. 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: EnumeratedDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an enumerated distribution using the given random number generator
 * and probability mass function enumeration.
 *
 * @param rng random number generator.
 * @param pmf probability mass function enumerated as a list of <T, probability>
 * pairs.
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedDistribution(final RandomGenerator rng, final List<Pair<T, Double>> pmf)
    throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException {
    random = rng;

    singletons = new ArrayList<T>(pmf.size());
    final double[] probs = new double[pmf.size()];

    for (int i = 0; i < pmf.size(); i++) {
        final Pair<T, Double> sample = pmf.get(i);
        singletons.add(sample.getKey());
        final double p = sample.getValue();
        if (p < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        if (Double.isInfinite(p)) {
            throw new NotFiniteNumberException(p);
        }
        if (Double.isNaN(p)) {
            throw new NotANumberException();
        }
        probs[i] = p;
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example #2
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param singletons array of random variable values.
 * @param probabilities array of probabilities.
 * @throws DimensionMismatchException if
 * {@code singletons.length != probabilities.length}
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedIntegerDistribution(final RandomGenerator rng,
                                   final int[] singletons, final double[] probabilities)
    throws DimensionMismatchException, NotPositiveException, MathArithmeticException,
            NotFiniteNumberException, NotANumberException {
    super(rng);
    if (singletons.length != probabilities.length) {
        throw new DimensionMismatchException(probabilities.length, singletons.length);
    }

    final List<Pair<Integer, Double>> samples = new ArrayList<Pair<Integer, Double>>(singletons.length);

    for (int i = 0; i < singletons.length; i++) {
        samples.add(new Pair<Integer, Double>(singletons[i], probabilities[i]));
    }

    innerDistribution = new EnumeratedDistribution<Integer>(rng, samples);
}
 
Example #3
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function enumeration.
 *
 * @param rng random number generator.
 * @param singletons array of random variable values.
 * @param probabilities array of probabilities.
 * @throws DimensionMismatchException if
 * {@code singletons.length != probabilities.length}
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedRealDistribution(final RandomGenerator rng,
                                final double[] singletons, final double[] probabilities)
    throws DimensionMismatchException, NotPositiveException, MathArithmeticException,
           NotFiniteNumberException, NotANumberException {
    super(rng);
    if (singletons.length != probabilities.length) {
        throw new DimensionMismatchException(probabilities.length, singletons.length);
    }

    List<Pair<Double, Double>> samples = new ArrayList<Pair<Double, Double>>(singletons.length);

    for (int i = 0; i < singletons.length; i++) {
        samples.add(new Pair<Double, Double>(singletons[i], probabilities[i]));
    }

    innerDistribution = new EnumeratedDistribution<Double>(rng, samples);
}
 
Example #4
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param singletons array of random variable values.
 * @param probabilities array of probabilities.
 * @throws DimensionMismatchException if
 * {@code singletons.length != probabilities.length}
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedIntegerDistribution(final RandomGenerator rng,
                                   final int[] singletons, final double[] probabilities)
    throws DimensionMismatchException, NotPositiveException, MathArithmeticException,
            NotFiniteNumberException, NotANumberException {
    super(rng);
    if (singletons.length != probabilities.length) {
        throw new DimensionMismatchException(probabilities.length, singletons.length);
    }

    final List<Pair<Integer, Double>> samples = new ArrayList<Pair<Integer, Double>>(singletons.length);

    for (int i = 0; i < singletons.length; i++) {
        samples.add(new Pair<Integer, Double>(singletons[i], probabilities[i]));
    }

    innerDistribution = new EnumeratedDistribution<Integer>(rng, samples);
}
 
Example #5
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param singletons array of random variable values.
 * @param probabilities array of probabilities.
 * @throws DimensionMismatchException if
 * {@code singletons.length != probabilities.length}
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedIntegerDistribution(final RandomGenerator rng,
                                   final int[] singletons, final double[] probabilities)
    throws DimensionMismatchException, NotPositiveException, MathArithmeticException,
            NotFiniteNumberException, NotANumberException {
    super(rng);
    if (singletons.length != probabilities.length) {
        throw new DimensionMismatchException(probabilities.length, singletons.length);
    }

    final List<Pair<Integer, Double>> samples = new ArrayList<Pair<Integer, Double>>(singletons.length);

    for (int i = 0; i < singletons.length; i++) {
        samples.add(new Pair<Integer, Double>(singletons[i], probabilities[i]));
    }

    innerDistribution = new EnumeratedDistribution<Integer>(rng, samples);
}
 
Example #6
Source File: EnumeratedDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create an enumerated distribution using the given random number generator
 * and probability mass function enumeration.
 *
 * @param rng random number generator.
 * @param pmf probability mass function enumerated as a list of <T, probability>
 * pairs.
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedDistribution(final RandomGenerator rng, final List<Pair<T, Double>> pmf)
    throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException {
    random = rng;

    singletons = new ArrayList<T>(pmf.size());
    final double[] probs = new double[pmf.size()];

    for (int i = 0; i < pmf.size(); i++) {
        final Pair<T, Double> sample = pmf.get(i);
        singletons.add(sample.getKey());
        final double p = sample.getValue();
        if (p < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        if (Double.isInfinite(p)) {
            throw new NotFiniteNumberException(p);
        }
        if (Double.isNaN(p)) {
            throw new NotANumberException();
        }
        probs[i] = p;
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example #7
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that all the elements are real numbers.
 *
 * @param val Arguments.
 * @throws NotFiniteNumberException if any values of the array is not a
 * finite real number.
 */
public static void checkFinite(final double[] val) {
    for (int i = 0; i < val.length; i++) {
        final double x = val[i];
        if (Double.isInfinite(x) || Double.isNaN(x)) {
            throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i);
        }
    }
}
 
Example #8
Source File: EnumeratedDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an enumerated distribution using the given random number generator
 * and probability mass function enumeration.
 *
 * @param rng random number generator.
 * @param pmf probability mass function enumerated as a list of <T, probability>
 * pairs.
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedDistribution(final RandomGenerator rng, final List<Pair<T, Double>> pmf)
    throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException {
    random = rng;

    singletons = new ArrayList<T>(pmf.size());
    final double[] probs = new double[pmf.size()];

    for (int i = 0; i < pmf.size(); i++) {
        final Pair<T, Double> sample = pmf.get(i);
        singletons.add(sample.getKey());
        final double p = sample.getValue();
        if (p < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        if (Double.isInfinite(p)) {
            throw new NotFiniteNumberException(p);
        }
        if (Double.isNaN(p)) {
            throw new NotANumberException();
        }
        probs[i] = p;
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);

    cumulativeProbabilities = new double[probabilities.length];
    double sum = 0;
    for (int i = 0; i < probabilities.length; i++) {
        sum += probabilities[i];
        cumulativeProbabilities[i] = sum;
    }
}
 
Example #9
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that all the elements are real numbers.
 *
 * @param val Arguments.
 * @throws NotFiniteNumberException if any values of the array is not a
 * finite real number.
 */
public static void checkFinite(final double[] val)
    throws NotFiniteNumberException {
    for (int i = 0; i < val.length; i++) {
        final double x = val[i];
        if (Double.isInfinite(x) || Double.isNaN(x)) {
            throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i);
        }
    }
}
 
Example #10
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 #11
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 #12
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 #13
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that all the elements are real numbers.
 *
 * @param val Arguments.
 * @throws NotFiniteNumberException if any values of the array is not a
 * finite real number.
 */
public static void checkFinite(final double[] val)
    throws NotFiniteNumberException {
    for (int i = 0; i < val.length; i++) {
        final double x = val[i];
        if (Double.isInfinite(x) || Double.isNaN(x)) {
            throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i);
        }
    }
}
 
Example #14
Source File: ParamUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Checks that the  input is not infinity nor NaN or throws an {@link IllegalArgumentException}
 * @param val value to check
 * @param message the text message that would be pass to the exception thrown
 * @return the same value
 * @throws IllegalArgumentException
 */
public static double isFinite(final double val, final String message) {
    try {
        MathUtils.checkFinite(val);
    } catch (final NotFiniteNumberException ne) {
        throw new IllegalArgumentException(message);
    }
    return val;
}
 
Example #15
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that all the elements are real numbers.
 *
 * @param val Arguments.
 * @throws NotFiniteNumberException if any values of the array is not a
 * finite real number.
 */
public static void checkFinite(final double[] val) {
    for (int i = 0; i < val.length; i++) {
        final double x = val[i];
        if (Double.isInfinite(x) || Double.isNaN(x)) {
            throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i);
        }
    }
}
 
Example #16
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that all the elements are real numbers.
 *
 * @param val Arguments.
 * @throws NotFiniteNumberException if any values of the array is not a
 * finite real number.
 */
public static void checkFinite(final double[] val)
    throws NotFiniteNumberException {
    for (int i = 0; i < val.length; i++) {
        final double x = val[i];
        if (Double.isInfinite(x) || Double.isNaN(x)) {
            throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i);
        }
    }
}
 
Example #17
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 #18
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 #19
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal5() {
    new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.POSITIVE_INFINITY});
}
 
Example #20
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal6() {
    new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NEGATIVE_INFINITY});
}
 
Example #21
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal3() {
    new LoessInterpolator().smooth(new double[] {1,2,Double.NEGATIVE_INFINITY}, new double[] {3,4,5});
}
 
Example #22
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal3() {
    new LoessInterpolator().smooth(new double[] {1,2,Double.NEGATIVE_INFINITY}, new double[] {3,4,5});
}
 
Example #23
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal6() {
    new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NEGATIVE_INFINITY});
}
 
Example #24
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal6() {
    new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NEGATIVE_INFINITY});
}
 
Example #25
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal5() {
    new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.POSITIVE_INFINITY});
}
 
Example #26
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal3() {
    new LoessInterpolator().smooth(new double[] {1,2,Double.NEGATIVE_INFINITY}, new double[] {3,4,5});
}
 
Example #27
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal1() {
    new LoessInterpolator().smooth(new double[] {1,2,Double.NaN}, new double[] {3,4,5});
}
 
Example #28
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal3() {
    new LoessInterpolator().smooth(new double[] {1,2,Double.NEGATIVE_INFINITY}, new double[] {3,4,5});
}
 
Example #29
Source File: LoessInterpolator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a loess fit on the data at the original abscissae.
 *
 * @param xval the arguments for the interpolation points
 * @param yval the values for the interpolation points
 * @return values of the loess fit at corresponding original abscissae
 * @throws NonMonotonicSequenceException if {@code xval} not sorted in
 * strictly increasing order.
 * @throws DimensionMismatchException if {@code xval} and {@code yval} have
 * different sizes.
 * @throws NoDataException if {@code xval} or {@code yval} has zero size.
 * @throws NotFiniteNumberException if any of the arguments and values are
 * not finite real numbers.
 * @throws NumberIsTooSmallException if the bandwidth is too small to
 * accomodate the size of the input data (i.e. the bandwidth must be
 * larger than 2/n).
 */
public final double[] smooth(final double[] xval, final double[] yval)
    throws NonMonotonicSequenceException,
           DimensionMismatchException,
           NoDataException,
           NotFiniteNumberException,
           NumberIsTooSmallException {
    if (xval.length != yval.length) {
        throw new DimensionMismatchException(xval.length, yval.length);
    }

    final double[] unitWeights = new double[xval.length];
    Arrays.fill(unitWeights, 1.0);

    return smooth(xval, yval, unitWeights);
}
 
Example #30
Source File: LoessInterpolatorTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test(expected=NotFiniteNumberException.class)
public void testNotAllFiniteReal2() {
    new LoessInterpolator().smooth(new double[] {1,2,Double.POSITIVE_INFINITY}, new double[] {3,4,5});
}