Example usage for org.apache.commons.math3.exception NotPositiveException NotPositiveException

List of usage examples for org.apache.commons.math3.exception NotPositiveException NotPositiveException

Introduction

In this page you can find the example usage for org.apache.commons.math3.exception NotPositiveException NotPositiveException.

Prototype

public NotPositiveException(Localizable specific, Number value) 

Source Link

Document

Construct the exception with a specific context.

Usage

From source file:cz.cuni.lf1.lge.ThunderSTORM.results.ModifiedLoess.java

/**
 * Construct a new {@link LoessInterpolator}
 * with given bandwidth, number of robustness iterations and accuracy.
 *
 * @param bandwidth  when computing the loess fit at
 * a particular point, this fraction of source points closest
 * to the current point is taken into account for computing
 * a least-squares regression.</br>
 * A sensible value is usually 0.25 to 0.5, the default value is
 * {@link #DEFAULT_BANDWIDTH}./*w  w  w  .  j av a  2  s .c o m*/
 * @param robustnessIters This many robustness iterations are done.</br>
 * A sensible value is usually 0 (just the initial fit without any
 * robustness iterations) to 4, the default value is
 * {@link #DEFAULT_ROBUSTNESS_ITERS}.
 * @param accuracy If the median residual at a certain robustness iteration
 * is less than this amount, no more iterations are done.
 * @throws OutOfRangeException if bandwidth does not lie in the interval [0,1].
 * @throws NotPositiveException if {@code robustnessIters} is negative.
 * @see #LoessInterpolator(double, int)
 * @since 2.1
 */
public ModifiedLoess(double bandwidth, int robustnessIters, double accuracy)
        throws OutOfRangeException, NotPositiveException {
    if (bandwidth < 0 || bandwidth > 1) {
        throw new OutOfRangeException(LocalizedFormats.BANDWIDTH, bandwidth, 0, 1);
    }
    this.bandwidth = bandwidth;
    if (robustnessIters < 0) {
        throw new NotPositiveException(LocalizedFormats.ROBUSTNESS_ITERATIONS, robustnessIters);
    }
    this.robustnessIters = robustnessIters;
    this.accuracy = accuracy;
}

From source file:com.cloudera.oryx.common.math.OpenMapRealVector.java

@Override
public OpenMapRealVector getSubVector(int index, int n) {
    checkIndex(index);// w  ww. ja va  2  s.  c  o m
    if (n < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n);
    }
    checkIndex(index + n - 1);
    OpenMapRealVector res = new OpenMapRealVector(n);
    int end = index + n;
    OpenIntToDoubleHashMap.Iterator iter = entries.iterator();
    while (iter.hasNext()) {
        iter.advance();
        int key = iter.key();
        if (key >= index && key < end) {
            res.setEntry(key - index, iter.value());
        }
    }
    return res;
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.lib.ListPopulation.java

/**
 * Creates a new ListPopulation instance.
 * <p>/*from   w  w  w .  j a  v a2  s.com*/
 * Note: the chromosomes of the specified list are added to the population.
 *
 * @param chromosomes list of chromosomes to be added to the population
 * @param populationLimit maximal size of the population
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NotPositiveException if the population limit is not a positive number (&lt; 1)
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 */
public ListPopulation(final List<Chromosome> chromosomes, final int populationLimit)
        throws NullArgumentException, NotPositiveException, NumberIsTooLargeException {

    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (populationLimit <= 0) {
        throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit);
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                chromosomes.size(), populationLimit, false);
    }
    this.populationLimit = populationLimit;
    this.chromosomes = new ArrayList<Chromosome>(populationLimit);
    this.chromosomes.addAll(chromosomes);
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.lib.ListPopulation.java

/**
 * Sets the maximal population size./*  ww  w .j  a v  a2s .  c  o  m*/
 * @param populationLimit maximal population size.
 * @throws NotPositiveException if the population limit is not a positive number (&lt; 1)
 * @throws NumberIsTooSmallException if the new population size is smaller than the current number
 *   of chromosomes in the population
 */
public void setPopulationLimit(final int populationLimit)
        throws NotPositiveException, NumberIsTooSmallException {
    if (populationLimit <= 0) {
        throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit);
    }
    if (populationLimit < chromosomes.size()) {
        throw new NumberIsTooSmallException(populationLimit, chromosomes.size(), true);
    }
    this.populationLimit = populationLimit;
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.CombinatoricsUtils.java

/**
 * Returns n!. Shorthand for {@code n} <a
 * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the
 * product of the numbers {@code 1, ..., n}.
 * <p>//from  w w w  . ja  va  2s .  c  o  m
 * <Strong>Preconditions</strong>:
 * <ul>
 * <li> {@code n >= 0} (otherwise
 * {@code IllegalArgumentException} is thrown)</li>
 * <li> The result is small enough to fit into a {@code long}. The
 * largest value of {@code n} for which {@code n!} <
 * Long.MAX_VALUE} is 20. If the computed value exceeds {@code Long.MAX_VALUE}
 * an {@code ArithMeticException } is thrown.</li>
 * </ul>
 * </p>
 *
 * @param n argument
 * @return {@code n!}
 * @throws MathArithmeticException if the result is too large to be represented
 *                                 by a {@code long}.
 * @throws NotPositiveException    if {@code n < 0}.
 * @throws MathArithmeticException if {@code n > 20}: The factorial value is too
 *                                 large to fit in a {@code long}.
 */
public static long factorial(final int n) throws NotPositiveException, MathArithmeticException {
    if (n < 0) {
        throw new NotPositiveException(LocalizedFormats.FACTORIAL_NEGATIVE_PARAMETER, n);
    }
    if (n > 20) {
        throw new MathArithmeticException();
    }
    return FACTORIALS[n];
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.CombinatoricsUtils.java

/**
 * Compute n!, the<a href="http://mathworld.wolfram.com/Factorial.html">
 * factorial</a> of {@code n} (the product of the numbers 1 to n), as a
 * {@code double}.//from  w w  w  .ja va 2s.c  o  m
 * The result should be small enough to fit into a {@code double}: The
 * largest {@code n} for which {@code n! < Double.MAX_VALUE} is 170.
 * If the computed value exceeds {@code Double.MAX_VALUE},
 * {@code Double.POSITIVE_INFINITY} is returned.
 *
 * @param n Argument.
 * @return {@code n!}
 * @throws NotPositiveException if {@code n < 0}.
 */
public static double factorialDouble(final int n) throws NotPositiveException {
    if (n < 0) {
        throw new NotPositiveException(LocalizedFormats.FACTORIAL_NEGATIVE_PARAMETER, n);
    }
    if (n < 21) {
        return FACTORIALS[n];
    }
    return FastMath.floor(FastMath.exp(CombinatoricsUtils.factorialLog(n)) + 0.5);
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.CombinatoricsUtils.java

/**
 * Compute the natural logarithm of the factorial of {@code n}.
 *
 * @param n Argument./*from   w  w  w .j av a  2  s. c o  m*/
 * @return {@code n!}
 * @throws NotPositiveException if {@code n < 0}.
 */
public static double factorialLog(final int n) throws NotPositiveException {
    if (n < 0) {
        throw new NotPositiveException(LocalizedFormats.FACTORIAL_NEGATIVE_PARAMETER, n);
    }
    if (n < 21) {
        return FastMath.log(FACTORIALS[n]);
    }
    double logSum = 0;
    for (int i = 2; i <= n; i++) {
        logSum += FastMath.log(i);
    }
    return logSum;
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.CombinatoricsUtils.java

/**
 * Check binomial preconditions./*from w  w w  .ja va  2 s .com*/
 *
 * @param n Size of the set.
 * @param k Size of the subsets to be counted.
 * @throws NotPositiveException      if {@code n < 0}.
 * @throws NumberIsTooLargeException if {@code k > n}.
 */
public static void checkBinomial(final int n, final int k)
        throws NumberIsTooLargeException, NotPositiveException {
    if (n < k) {
        throw new NumberIsTooLargeException(LocalizedFormats.BINOMIAL_INVALID_PARAMETERS_ORDER, k, n, true);
    }
    if (n < 0) {
        throw new NotPositiveException(LocalizedFormats.BINOMIAL_NEGATIVE_PARAMETER, n);
    }
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.MathArrays.java

/**
 * This method is used//w ww.  j  a v  a2s. c  o m
 * to verify that the input parameters designate a subarray of positive length.
 * <p>
 * <ul>
 * <li>returns <code>true</code> iff the parameters designate a subarray of
 * non-negative length</li>
 * <li>throws <code>IllegalArgumentException</code> if the array is null or
 * or the indices are invalid</li>
 * <li>returns <code>false</li> if the array is non-null, but
 * <code>length</code> is 0 unless <code>allowEmpty</code> is <code>true</code>
 * </ul></p>
 *
 * @param values     the input array
 * @param begin      index of the first array element to include
 * @param length     the number of elements to include
 * @param allowEmpty if <code>true</code> then zero length arrays are allowed
 * @return true if the parameters are valid
 * @throws MathIllegalArgumentException if the indices are invalid or the array is null
 * @since 3.3
 */
public static boolean verifyValues(final double[] values, final int begin, final int length,
        final boolean allowEmpty) throws MathIllegalArgumentException {

    if (values == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }

    if (begin < 0) {
        throw new NotPositiveException(LocalizedFormats.START_POSITION, Integer.valueOf(begin));
    }

    if (length < 0) {
        throw new NotPositiveException(LocalizedFormats.LENGTH, Integer.valueOf(length));
    }

    if (begin + length > values.length) {
        throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END,
                Integer.valueOf(begin + length), Integer.valueOf(values.length), true);
    }

    if (length == 0 && !allowEmpty) {
        return false;
    }

    return true;

}

From source file:org.nd4j.linalg.api.rng.distribution.impl.BinomialDistribution.java

/**
 * Creates a binomial distribution./*from   ww  w .j  a v a 2  s .co m*/
 *
 * @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;
}