org.apache.commons.math.MathRuntimeException.createIllegalArgumentException() - java examples

Here are the examples of the java api org.apache.commons.math.MathRuntimeException.createIllegalArgumentException() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : Covariance.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Computes the covariance between the two arrays.
 *
 * <p>Array lengths must match and the common length must be at least 2.</p>
 *
 * @param xArray first data array
 * @param yArray second data array
 * @param biasCorrected if true, returned value will be bias-corrected
 * @return returns the covariance for the two arrays
 * @throws  IllegalArgumentException if the arrays lengths do not match or
 * there is insufficient data
 */
public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected) throws IllegalArgumentException {
    Mean mean = new Mean();
    double result = 0d;
    int length = xArray.length;
    if (length == yArray.length && length > 1) {
        double xMean = mean.evaluate(xArray);
        double yMean = mean.evaluate(yArray);
        for (int i = 0; i < length; i++) {
            double xDev = xArray[i] - xMean;
            double yDev = yArray[i] - yMean;
            result += (xDev * yDev - result) / (i + 1);
        }
    } else {
        throw MathRuntimeException.createIllegalArgumentException("arrays must have the same length and both must have at " + "least two elements. xArray has size {0}, yArray has {1} elements", length, yArray.length);
    }
    return biasCorrected ? result * ((double) length / (double) (length - 1)) : result;
}

19 View Complete Implementation : PolynomialFunction.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Uses Horner's Method to evaluate the polynomial with the given coefficients at
 * the argument.
 *
 * @param coefficients  the coefficients of the polynomial to evaluate
 * @param argument  the input value
 * @return  the value of the polynomial
 * @throws IllegalArgumentException if coefficients is empty
 * @throws NullPointerException if coefficients is null
 */
protected static double evaluate(double[] coefficients, double argument) {
    int n = coefficients.length;
    if (n < 1) {
        throw MathRuntimeException.createIllegalArgumentException("empty polynomials coefficients array");
    }
    double result = coefficients[n - 1];
    for (int j = n - 2; j >= 0; j--) {
        result = argument * result + coefficients[j];
    }
    return result;
}

19 View Complete Implementation : FractionFormat.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Formats an object and appends the result to a StringBuffer. <code>obj</code> must be either a
 * {@link Fraction} object or a {@link Number} object.  Any other type of
 * object will result in an {@link IllegalArgumentException} being thrown.
 *
 * @param obj the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value preplaceded in as toAppendTo.
 * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
 * @throws IllegalArgumentException is <code>obj</code> is not a valid type.
 */
@Override
public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) {
    StringBuffer ret = null;
    if (obj instanceof Fraction) {
        ret = format((Fraction) obj, toAppendTo, pos);
    } else if (obj instanceof Number) {
        try {
            ret = format(new Fraction(((Number) obj).doubleValue()), toAppendTo, pos);
        } catch (ConvergenceException ex) {
            throw MathRuntimeException.createIllegalArgumentException("cannot convert given object to a fraction number: {0}", ex.getLocalizedMessage());
        }
    } else {
        throw MathRuntimeException.createIllegalArgumentException("cannot format given object as a fraction number");
    }
    return ret;
}

19 View Complete Implementation : AbstractRealMatrix.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
public void setSubMatrix(final double[][] subMatrix, final int row, final int column) throws MatrixIndexException {
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
    }
    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
    }
    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw MathRuntimeException.createIllegalArgumentException("some rows have length {0} while others have length {1}", nCols, subMatrix[r].length);
        }
    }
    MatrixUtils.checkRowIndex(this, row);
    MatrixUtils.checkColumnIndex(this, column);
    MatrixUtils.checkRowIndex(this, nRows + row - 1);
    MatrixUtils.checkColumnIndex(this, nCols + column - 1);
    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
    lu = null;
}

19 View Complete Implementation : Array2DRowRealMatrix.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
@Override
public double[] preMultiply(final double[] v) throws IllegalArgumentException {
    final int nRows = getRowDimension();
    final int nCols = getColumnDimension();
    if (v.length != nRows) {
        throw MathRuntimeException.createIllegalArgumentException(VECTOR_LENGTHS_MISMATCH, v.length, nRows);
    }
    final double[] out = new double[nCols];
    for (int col = 0; col < nCols; ++col) {
        double sum = 0;
        for (int i = 0; i < nRows; ++i) {
            sum += data[i][col] * v[i];
        }
        out[col] = sum;
    }
    return out;
}

19 View Complete Implementation : ProperBigFractionFormat.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Modify the whole format.
 * @param format The new whole format value.
 * @throws IllegalArgumentException if <code>format</code> is
 *         <code>null</code>.
 */
public void setWholeFormat(final NumberFormat format) {
    if (format == null) {
        throw MathRuntimeException.createIllegalArgumentException("whole format can not be null");
    }
    this.wholeFormat = format;
}

19 View Complete Implementation : AbstractFieldMatrix.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
public T[] operate(final T[] v) throws IllegalArgumentException {
    final int nRows = getRowDimension();
    final int nCols = getColumnDimension();
    if (v.length != nCols) {
        throw MathRuntimeException.createIllegalArgumentException("vector length mismatch: got {0} but expected {1}", v.length, nCols);
    }
    final T[] out = buildArray(field, nRows);
    for (int row = 0; row < nRows; ++row) {
        T sum = field.getZero();
        for (int i = 0; i < nCols; ++i) {
            sum = sum.add(getEntry(row, i).multiply(v[i]));
        }
        out[row] = sum;
    }
    return out;
}

19 View Complete Implementation : AbstractRealMatrix.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
public double[] preMultiply(final double[] v) throws IllegalArgumentException {
    final int nRows = getRowDimension();
    final int nCols = getColumnDimension();
    if (v.length != nRows) {
        throw MathRuntimeException.createIllegalArgumentException("vector length mismatch: got {0} but expected {1}", v.length, nRows);
    }
    final double[] out = new double[nCols];
    for (int col = 0; col < nCols; ++col) {
        double sum = 0;
        for (int i = 0; i < nRows; ++i) {
            sum += getEntry(i, col) * v[i];
        }
        out[col] = sum;
    }
    return out;
}

19 View Complete Implementation : ResizableDoubleArray.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Checks the expansion factor and the contraction criteria and throws an
 * IllegalArgumentException if the contractionCriteria is less than the
 * expansionCriteria
 *
 * @param expansionFactor factor to be checked
 * @param contractionCriteria criteria to be checked
 * @throws IllegalArgumentException if the contractionCriteria is less than
 *         the expansionCriteria.
 */
protected void checkContractExpand(float contractionCriteria, float expansionFactor) {
    if (contractionCriteria < expansionFactor) {
        throw MathRuntimeException.createIllegalArgumentException("contraction criteria ({0}) smaller than the expansion factor ({1}).  This would " + "lead to a never ending loop of expansion and contraction as a newly expanded " + "internal storage array would immediately satisfy the criteria for contraction", contractionCriteria, expansionFactor);
    }
    if (contractionCriteria <= 1.0) {
        throw MathRuntimeException.createIllegalArgumentException("contraction criteria smaller than one ({0}).  This would lead to a never ending " + "loop of expansion and contraction as an internal storage array length equal " + "to the number of elements would satisfy the contraction criteria.", contractionCriteria);
    }
    if (expansionFactor <= 1.0) {
        throw MathRuntimeException.createIllegalArgumentException("expansion factor smaller than one ({0})", expansionFactor);
    }
}

19 View Complete Implementation : ComplexFormat.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Modify the imaginaryCharacter.
 * @param imaginaryCharacter The new imaginaryCharacter value.
 * @throws IllegalArgumentException if <code>imaginaryCharacter</code> is
 *         <code>null</code> or an empty string.
 */
public void setImaginaryCharacter(String imaginaryCharacter) {
    if (imaginaryCharacter == null || imaginaryCharacter.length() == 0) {
        throw MathRuntimeException.createIllegalArgumentException("empty string for imaginary character");
    }
    this.imaginaryCharacter = imaginaryCharacter;
}

19 View Complete Implementation : PoissonDistributionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Set the Poisson mean for the distribution. The mean value must be
 * positive; otherwise an <code>IllegalArgument</code> is thrown.
 *
 * @param p the Poisson mean value
 * @throws IllegalArgumentException if p ≤ 0
 */
public void setMean(double p) {
    if (p <= 0) {
        throw MathRuntimeException.createIllegalArgumentException("the Poisson mean must be positive ({0})", p);
    }
    this.mean = p;
    normal.setMean(p);
    normal.setStandardDeviation(Math.sqrt(p));
}

19 View Complete Implementation : AbstractDistribution.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * For a random variable X whose values are distributed according
 * to this distribution, this method returns P(x0 ≤ X ≤ x1).
 * <p>
 * The default implementation uses the idenreplacedy</p>
 * <p>
 * P(x0 ≤ X ≤ x1) = P(X ≤ x1) - P(X ≤ x0) </p>
 *
 * @param x0 the (inclusive) lower bound
 * @param x1 the (inclusive) upper bound
 * @return the probability that a random variable with this distribution
 * will take a value between <code>x0</code> and <code>x1</code>,
 * including the endpoints.
 * @throws MathException if the replacedulative probability can not be
 * computed due to convergence or other numerical errors.
 * @throws IllegalArgumentException if <code>x0 > x1</code>
 */
public double replacedulativeProbability(double x0, double x1) throws MathException {
    if (x0 > x1) {
        throw MathRuntimeException.createIllegalArgumentException("lower endpoint ({0}) must be less than or equal to upper endpoint ({1})", x0, x1);
    }
    return replacedulativeProbability(x1) - replacedulativeProbability(x0);
}

19 View Complete Implementation : ZipfDistributionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Set the number of elements (e.g. corpus size) for the distribution.
 * The parameter value must be positive; otherwise an
 * <code>IllegalArgumentException</code> is thrown.
 *
 * @param n the number of elements
 * @exception IllegalArgumentException if n ≤ 0
 */
public void setNumberOfElements(final int n) throws IllegalArgumentException {
    if (n <= 0) {
        throw MathRuntimeException.createIllegalArgumentException("invalid number of elements {0} (must be positive)", n);
    }
    this.numberOfElements = n;
}

19 View Complete Implementation : MatrixUtils.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Creates a column {@link FieldMatrix} using the data from the input
 * array.
 *
 * @param <T> the type of the field elements
 * @param columnData  the input column data
 * @return a columnData x 1 FieldMatrix
 * @throws IllegalArgumentException if <code>columnData</code> is empty
 * @throws NullPointerException if <code>columnData</code>is null
 */
public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) {
    final int nRows = columnData.length;
    if (nRows == 0) {
        throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
    }
    final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1);
    for (int i = 0; i < nRows; ++i) {
        m.setEntry(i, 0, columnData[i]);
    }
    return m;
}

19 View Complete Implementation : Fraction.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * <p>Multiplies the value of this fraction by another, returning the
 * result in reduced form.</p>
 *
 * @param fraction  the fraction to multiply by, must not be <code>null</code>
 * @return a <code>Fraction</code> instance with the resulting values
 * @throws IllegalArgumentException if the fraction is <code>null</code>
 * @throws ArithmeticException if the resulting numerator or denominator exceeds
 *  <code>Integer.MAX_VALUE</code>
 */
public Fraction multiply(Fraction fraction) {
    if (fraction == null) {
        throw MathRuntimeException.createIllegalArgumentException("null fraction");
    }
    if (numerator == 0 || fraction.numerator == 0) {
        return ZERO;
    }
    // knuth 4.5.1
    // make sure we don't overflow unless the result *must* overflow.
    int d1 = MathUtils.gcd(numerator, fraction.denominator);
    int d2 = MathUtils.gcd(fraction.numerator, denominator);
    return getReducedFraction(MathUtils.mulAndCheck(numerator / d1, fraction.numerator / d2), MathUtils.mulAndCheck(denominator / d2, fraction.denominator / d1));
}

19 View Complete Implementation : PolynomialFunctionNewtonForm.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Verifies that the input arrays are valid.
 * <p>
 * The centers must be distinct for interpolation purposes, but not
 * for general use. Thus it is not verified here.</p>
 *
 * @param a the coefficients in Newton form formula
 * @param c the centers
 * @throws IllegalArgumentException if not valid
 * @see DividedDifferenceInterpolator#computeDividedDifference(double[],
 * double[])
 */
protected static void verifyInputArray(double[] a, double[] c) throws IllegalArgumentException {
    if (a.length < 1 || c.length < 1) {
        throw MathRuntimeException.createIllegalArgumentException("empty polynomials coefficients array");
    }
    if (a.length != c.length + 1) {
        throw MathRuntimeException.createIllegalArgumentException("array sizes should have difference 1 ({0} != {1} + 1)", a.length, c.length);
    }
}

19 View Complete Implementation : MatrixUtils.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Check if matrices are multiplication compatible
 * @param left left hand side matrix
 * @param right right hand side matrix
 * @exception IllegalArgumentException if matrices are not multiplication compatible
 */
public static void checkMultiplicationCompatible(final AnyMatrix left, final AnyMatrix right) throws IllegalArgumentException {
    if (left.getColumnDimension() != right.getRowDimension()) {
        throw MathRuntimeException.createIllegalArgumentException("{0}x{1} and {2}x{3} matrices are not multiplication compatible", left.getRowDimension(), left.getColumnDimension(), right.getRowDimension(), right.getColumnDimension());
    }
}

19 View Complete Implementation : BinomialDistributionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Change the probability of success for this distribution.
 * @param p the new probability of success.
 * @throws IllegalArgumentException if <code>p</code> is not a valid
 *         probability.
 */
public void setProbabilityOfSuccess(double p) {
    if (p < 0.0 || p > 1.0) {
        throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", p, 0.0, 1.0);
    }
    probabilityOfSuccess = p;
}

19 View Complete Implementation : SingularValueDecompositionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
public RealMatrix getCovariance(final double minSingularValue) {
    // get the number of singular values to consider
    final int p = singularValues.length;
    int dimension = 0;
    while ((dimension < p) && (singularValues[dimension] >= minSingularValue)) {
        ++dimension;
    }
    if (dimension == 0) {
        throw MathRuntimeException.createIllegalArgumentException("cutoff singular value is {0}, should be at most {1}", minSingularValue, singularValues[0]);
    }
    final double[][] data = new double[dimension][p];
    getVT().walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void visit(final int row, final int column, final double value) {
            data[row][column] = value / singularValues[row];
        }
    }, 0, dimension - 1, 0, p - 1);
    RealMatrix jv = new Array2DRowRealMatrix(data, false);
    return jv.transpose().multiply(jv);
}

19 View Complete Implementation : NormalDistributionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Modify the standard deviation.
 * @param sd standard deviation for this distribution
 * @throws IllegalArgumentException if <code>sd</code> is not positive.
 */
public void setStandardDeviation(double sd) {
    if (sd <= 0.0) {
        throw MathRuntimeException.createIllegalArgumentException("standard deviation must be positive ({0})", sd);
    }
    standardDeviation = sd;
}

19 View Complete Implementation : UnivariateRealSolverUtils.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Checks to see if f is null, throwing IllegalArgumentException if so.
 * @param f  input function
 * @throws IllegalArgumentException if f is null
 */
private static void setup(UnivariateRealFunction f) {
    if (f == null) {
        throw MathRuntimeException.createIllegalArgumentException("function is null");
    }
}

19 View Complete Implementation : PolynomialFunction.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Uses Horner's Method to evaluate the polynomial with the given coefficients at
 * the argument.
 *
 * @param coefficients  the coefficients of the polynomial to evaluate
 * @param argument  the input value
 * @return  the value of the polynomial
 * @throws IllegalArgumentException if coefficients is empty
 * @throws NullPointerException if coefficients is null
 */
protected static double evaluate(double[] coefficients, double argument) {
    int n = coefficients.length;
    if (n < 1) {
        throw MathRuntimeException.createIllegalArgumentException("empty polynomials coefficients array");
    }
    double result = coefficients[n - 1];
    for (int j = n - 2; j >= 0; j--) {
        result = argument * result + coefficients[j];
    }
    return result;
}

19 View Complete Implementation : AbstractMultipleLinearRegression.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Validates sample data.
 *
 * @param x the [n,k] array representing the x sample
 * @param y the [n,1] array representing the y sample
 * @throws IllegalArgumentException if the x and y array data are not
 *             compatible for the regression
 */
protected void validateSampleData(double[][] x, double[] y) {
    if ((x == null) || (y == null) || (x.length != y.length)) {
        throw MathRuntimeException.createIllegalArgumentException("dimension mismatch {0} != {1}", (x == null) ? 0 : x.length, (y == null) ? 0 : y.length);
    } else if ((x.length > 0) && (x[0].length > x.length)) {
        throw MathRuntimeException.createIllegalArgumentException("not enough data ({0} rows) for this many predictors ({1} predictors)", x.length, x[0].length);
    }
}

19 View Complete Implementation : TTestImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Check significance level.
 * @param alpha significance level
 * @exception IllegalArgumentException if significance level is out of bounds
 */
private void checkSignificanceLevel(final double alpha) throws IllegalArgumentException {
    if ((alpha <= 0) || (alpha > 0.5)) {
        throw MathRuntimeException.createIllegalArgumentException("out of bounds significance level {0}, must be between {1} and {2}", alpha, 0.0, 0.5);
    }
}

19 View Complete Implementation : RealMatrixImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
@Override
public double[] preMultiply(final double[] v) throws IllegalArgumentException {
    final int nRows = getRowDimension();
    final int nCols = getColumnDimension();
    if (v.length != nRows) {
        throw MathRuntimeException.createIllegalArgumentException("vector length mismatch: got {0} but expected {1}", v.length, nRows);
    }
    final double[] out = new double[nCols];
    for (int col = 0; col < nCols; ++col) {
        double sum = 0;
        for (int i = 0; i < nRows; ++i) {
            sum += data[i][col] * v[i];
        }
        out[col] = sum;
    }
    return out;
}

19 View Complete Implementation : RandomDataImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Returns a random value from an Exponential distribution with the given
 * mean.
 * <p>
 * <strong>Algorithm Description</strong>: Uses the <a
 * href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html"> Inversion
 * Method</a> to generate exponentially distributed random values from
 * uniform deviates.
 * </p>
 *
 * @param mean the mean of the distribution
 * @return the random Exponential value
 */
public double nextExponential(double mean) {
    // bug id 309
    if (mean < 0.0) {
        // FIX
        // if (mean <= 0.0) {
        throw MathRuntimeException.createIllegalArgumentException("mean must be positive ({0})", mean);
    }
    final RandomGenerator generator = getRan();
    double unif = generator.nextDouble();
    while (unif == 0.0d) {
        unif = generator.nextDouble();
    }
    return -mean * Math.log(unif);
}

19 View Complete Implementation : ExponentialDistributionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * For this distribution, X, this method returns the critical point x, such
 * that P(X < x) = <code>p</code>.
 * <p>
 * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
 *
 * @param p the desired probability
 * @return x, such that P(X < x) = <code>p</code>
 * @throws MathException if the inverse replacedulative probability can not be
 *            computed due to convergence or other numerical errors.
 * @throws IllegalArgumentException if p < 0 or p > 1.
 */
@Override
public double inversereplacedulativeProbability(double p) throws MathException {
    double ret;
    if (p < 0.0 || p > 1.0) {
        throw MathRuntimeException.createIllegalArgumentException("{0} out of [{1}, {2}] range", p, 0.0, 1.0);
    } else if (p == 1.0) {
        ret = Double.POSITIVE_INFINITY;
    } else {
        ret = -getMean() * Math.log(1.0 - p);
    }
    return ret;
}

19 View Complete Implementation : BitsStreamGenerator.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
public int nextInt(int n) throws IllegalArgumentException {
    if (n < 1) {
        throw MathRuntimeException.createIllegalArgumentException("upper bound must be positive ({0})", n);
    }
    // find bit mask for n
    int mask = n;
    mask |= mask >> 1;
    mask |= mask >> 2;
    mask |= mask >> 4;
    mask |= mask >> 8;
    mask |= mask >> 16;
    while (true) {
        final int random = next(32) & mask;
        if (random < n) {
            return random;
        }
    }
}

19 View Complete Implementation : SingularValueDecompositionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
public RealMatrix getCovariance(final double minSingularValue) {
    // get the number of singular values to consider
    int dimension = 0;
    while ((dimension < n) && (singularValues[dimension] >= minSingularValue)) {
        ++dimension;
    }
    if (dimension == 0) {
        throw MathRuntimeException.createIllegalArgumentException("cutoff singular value is {0}, should be at most {1}", minSingularValue, singularValues[0]);
    }
    final double[][] data = new double[dimension][n];
    getVT().walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void visit(final int row, final int column, final double value) {
            data[row][column] = value / singularValues[row];
        }
    }, 0, dimension - 1, 0, n - 1);
    RealMatrix jv = new Array2DRowRealMatrix(data, false);
    return jv.transpose().multiply(jv);
}

19 View Complete Implementation : TTestImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Check significance level.
 * @param alpha significance level
 * @exception IllegalArgumentException if significance level is out of bounds
 */
private void checkSignificanceLevel(final double alpha) throws IllegalArgumentException {
    if ((alpha <= 0) || (alpha > 0.5)) {
        throw MathRuntimeException.createIllegalArgumentException("out of bounds significance level {0}, must be between {1} and {2}", alpha, 0.0, 0.5);
    }
}

19 View Complete Implementation : Array2DRowFieldMatrix.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
@Override
public T[] preMultiply(final T[] v) throws IllegalArgumentException {
    final int nRows = getRowDimension();
    final int nCols = getColumnDimension();
    if (v.length != nRows) {
        throw MathRuntimeException.createIllegalArgumentException("vector length mismatch: got {0} but expected {1}", v.length, nRows);
    }
    final T[] out = buildArray(getField(), nCols);
    for (int col = 0; col < nCols; ++col) {
        T sum = getField().getZero();
        for (int i = 0; i < nRows; ++i) {
            sum = sum.add(data[i][col].multiply(v[i]));
        }
        out[col] = sum;
    }
    return out;
}

19 View Complete Implementation : HypergeometricDistributionImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Modify the population size.
 *
 * @param size the new population size.
 * @throws IllegalArgumentException if <code>size</code> is not positive.
 */
public void setPopulationSize(int size) {
    if (size <= 0) {
        throw MathRuntimeException.createIllegalArgumentException("population size must be positive ({0})", size);
    }
    populationSize = size;
}

19 View Complete Implementation : TTestImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Check sample data.
 * @param data sample data
 * @exception IllegalArgumentException if there is not enough sample data
 */
private void checkSampleData(final double[] data) throws IllegalArgumentException {
    if ((data == null) || (data.length < 2)) {
        throw MathRuntimeException.createIllegalArgumentException("insufficient data for t statistic, needs at least 2, got {0}", (data == null) ? 0 : data.length);
    }
}

19 View Complete Implementation : FastFourierTransformer.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Sample the given univariate real function on the given interval.
 * <p>
 * The interval is divided equally into N sections and sample points
 * are taken from min to max-(max-min)/N. Usually f(x) is periodic
 * such that f(min) = f(max) (note max is not sampled), but we don't
 * require that.</p>
 *
 * @param f the function to be sampled
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param n the number of sample points
 * @return the samples array
 * @throws FunctionEvaluationException if function cannot be evaluated
 * at some point
 * @throws IllegalArgumentException if any parameters are invalid
 */
public static double[] sample(UnivariateRealFunction f, double min, double max, int n) throws FunctionEvaluationException, IllegalArgumentException {
    if (n <= 0) {
        throw MathRuntimeException.createIllegalArgumentException("number of sample is not positive: {0}", n);
    }
    verifyInterval(min, max);
    double[] s = new double[n];
    double h = (max - min) / n;
    for (int i = 0; i < n; i++) {
        s[i] = f.value(min + i * h);
    }
    return s;
}

19 View Complete Implementation : SimpleRegression.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Returns the half-width of a (100-100*alpha)% confidence interval for
 * the slope estimate.
 * <p>
 * The (100-100*alpha)% confidence interval is </p>
 * <p>
 * <code>(getSlope() - getSlopeConfidenceInterval(),
 * getSlope() + getSlopeConfidenceInterval())</code></p>
 * <p>
 * To request, for example, a 99% confidence interval, use
 * <code>alpha = .01</code></p>
 * <p>
 * <strong>Usage Note</strong>:<br>
 * The validity of this statistic depends on the replacedumption that the
 * observations included in the model are drawn from a
 * <a href="http://mathworld.wolfram.com/BivariateNormalDistribution.html">
 * Bivariate Normal Distribution</a>.</p>
 * <p>
 * <strong> Preconditions:</strong><ul>
 * <li>If there are fewer that <strong>three</strong> observations in the
 * model, or if there is no variation in x, this returns
 * <code>Double.NaN</code>.
 * </li>
 * <li><code>(0 < alpha < 1)</code>; otherwise an
 * <code>IllegalArgumentException</code> is thrown.
 * </li></ul></p>
 *
 * @param alpha the desired significance level
 * @return half-width of 95% confidence interval for the slope estimate
 * @throws MathException if the confidence interval can not be computed.
 */
public double getSlopeConfidenceInterval(double alpha) throws MathException {
    if (alpha >= 1 || alpha <= 0) {
        throw MathRuntimeException.createIllegalArgumentException("out of bounds significance level {0}, must be between {1} and {2}", alpha, 0.0, 1.0);
    }
    return getSlopeStdErr() * distribution.inversereplacedulativeProbability(1d - alpha / 2d);
}

19 View Complete Implementation : Covariance.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Computes the covariance between the two arrays.
 *
 * <p>Array lengths must match and the common length must be at least 2.</p>
 *
 * @param xArray first data array
 * @param yArray second data array
 * @param biasCorrected if true, returned value will be bias-corrected
 * @return returns the covariance for the two arrays
 * @throws  IllegalArgumentException if the arrays lengths do not match or
 * there is insufficient data
 */
public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected) throws IllegalArgumentException {
    Mean mean = new Mean();
    double result = 0d;
    int length = xArray.length;
    if (length == yArray.length && length > 1) {
        double xMean = mean.evaluate(xArray);
        double yMean = mean.evaluate(yArray);
        for (int i = 0; i < length; i++) {
            double xDev = xArray[i] - xMean;
            double yDev = yArray[i] - yMean;
            result += (xDev * yDev - result) / (i + 1);
        }
    } else {
        throw MathRuntimeException.createIllegalArgumentException("arrays must have the same length and both must have at " + "least two elements. xArray has size {0}, yArray has {1} elements", length, yArray.length);
    }
    return biasCorrected ? result * ((double) length / (double) (length - 1)) : result;
}

19 View Complete Implementation : FastFourierTransformer.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Sample the given univariate real function on the given interval.
 * <p>
 * The interval is divided equally into N sections and sample points
 * are taken from min to max-(max-min)/N. Usually f(x) is periodic
 * such that f(min) = f(max) (note max is not sampled), but we don't
 * require that.</p>
 *
 * @param f the function to be sampled
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param n the number of sample points
 * @return the samples array
 * @throws FunctionEvaluationException if function cannot be evaluated
 * at some point
 * @throws IllegalArgumentException if any parameters are invalid
 */
public static double[] sample(UnivariateRealFunction f, double min, double max, int n) throws FunctionEvaluationException, IllegalArgumentException {
    if (n <= 0) {
        throw MathRuntimeException.createIllegalArgumentException("number of sample is not positive: {0}", n);
    }
    verifyInterval(min, max);
    double[] s = new double[n];
    double h = (max - min) / n;
    for (int i = 0; i < n; i++) {
        s[i] = f.value(min + i * h);
    }
    return s;
}

19 View Complete Implementation : Array2DRowFieldMatrix.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
@Override
public void setSubMatrix(final T[][] subMatrix, final int row, final int column) throws MatrixIndexException {
    if (data == null) {
        if (row > 0) {
            throw MathRuntimeException.createIllegalStateException("first {0} rows are not initialized yet", row);
        }
        if (column > 0) {
            throw MathRuntimeException.createIllegalStateException("first {0} columns are not initialized yet", column);
        }
        final int nRows = subMatrix.length;
        if (nRows == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
        }
        final int nCols = subMatrix[0].length;
        if (nCols == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
        }
        data = buildArray(getField(), subMatrix.length, nCols);
        for (int i = 0; i < data.length; ++i) {
            if (subMatrix[i].length != nCols) {
                throw MathRuntimeException.createIllegalArgumentException("some rows have length {0} while others have length {1}", nCols, subMatrix[i].length);
            }
            System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
        }
    } else {
        super.setSubMatrix(subMatrix, row, column);
    }
}

19 View Complete Implementation : BitsStreamGenerator.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
public int nextInt(int n) throws IllegalArgumentException {
    if (n < 1) {
        throw MathRuntimeException.createIllegalArgumentException("upper bound must be positive ({0})", n);
    }
    // find bit mask for n
    int mask = n;
    mask |= mask >> 1;
    mask |= mask >> 2;
    mask |= mask >> 4;
    mask |= mask >> 8;
    mask |= mask >> 16;
    while (true) {
        final int random = next(32) & mask;
        if (random < n) {
            return random;
        }
    }
}

19 View Complete Implementation : ProperBigFractionFormat.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Modify the whole format.
 * @param format The new whole format value.
 * @throws IllegalArgumentException if <code>format</code> is
 *         <code>null</code>.
 */
public void setWholeFormat(final NumberFormat format) {
    if (format == null) {
        throw MathRuntimeException.createIllegalArgumentException("whole format can not be null");
    }
    this.wholeFormat = format;
}

19 View Complete Implementation : ComplexUtils.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Creates a complex number from the given polar representation.
 * <p>
 * The value returned is <code>r·e<sup>i·theta</sup></code>,
 * computed as <code>r·cos(theta) + r·sin(theta)i</code></p>
 * <p>
 * If either <code>r</code> or <code>theta</code> is NaN, or
 * <code>theta</code> is infinite, {@link Complex#NaN} is returned.</p>
 * <p>
 * If <code>r</code> is infinite and <code>theta</code> is finite,
 * infinite or NaN values may be returned in parts of the result, following
 * the rules for double arithmetic.<pre>
 * Examples:
 * <code>
 * polar2Complex(INFINITY, π/4) = INFINITY + INFINITY i
 * polar2Complex(INFINITY, 0) = INFINITY + NaN i
 * polar2Complex(INFINITY, -π/4) = INFINITY - INFINITY i
 * polar2Complex(INFINITY, 5π/4) = -INFINITY - INFINITY i </code></pre></p>
 *
 * @param r the modulus of the complex number to create
 * @param theta  the argument of the complex number to create
 * @return <code>r·e<sup>i·theta</sup></code>
 * @throws IllegalArgumentException  if r is negative
 * @since 1.1
 */
public static Complex polar2Complex(double r, double theta) {
    if (r < 0) {
        throw MathRuntimeException.createIllegalArgumentException("negative complex module {0}", r);
    }
    return new Complex(r * Math.cos(theta), r * Math.sin(theta));
}

19 View Complete Implementation : ResizableDoubleArray.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Checks the expansion factor and the contraction criteria and throws an
 * IllegalArgumentException if the contractionCriteria is less than the
 * expansionCriteria
 *
 * @param expansion factor to be checked
 * @param contraction criteria to be checked
 * @throws IllegalArgumentException if the contractionCriteria is less than
 *         the expansionCriteria.
 */
protected void checkContractExpand(float contraction, float expansion) {
    if (contraction < expansion) {
        throw MathRuntimeException.createIllegalArgumentException("contraction criteria ({0}) smaller than the expansion factor ({1}).  This would " + "lead to a never ending loop of expansion and contraction as a newly expanded " + "internal storage array would immediately satisfy the criteria for contraction", contraction, expansion);
    }
    if (contraction <= 1.0) {
        throw MathRuntimeException.createIllegalArgumentException("contraction criteria smaller than one ({0}).  This would lead to a never ending " + "loop of expansion and contraction as an internal storage array length equal " + "to the number of elements would satisfy the contraction criteria.", contraction);
    }
    if (expansion <= 1.0) {
        throw MathRuntimeException.createIllegalArgumentException("expansion factor smaller than one ({0})", expansion);
    }
}

19 View Complete Implementation : DescriptiveStatistics.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Returns an estimate for the pth percentile of the stored values.
 * <p>
 * The implementation provided here follows the first estimation procedure presented
 * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a>
 * </p><p>
 * <strong>Preconditions</strong>:<ul>
 * <li><code>0 < p ≤ 100</code> (otherwise an
 * <code>IllegalArgumentException</code> is thrown)</li>
 * <li>at least one value must be stored (returns <code>Double.NaN
 *     </code> otherwise)</li>
 * </ul></p>
 *
 * @param p the requested percentile (scaled from 0 - 100)
 * @return An estimate for the pth percentile of the stored data
 * @throws IllegalStateException if percentile implementation has been
 *  overridden and the supplied implementation does not support setQuantile
 * values
 */
public double getPercentile(double p) {
    if (percentileImpl instanceof Percentile) {
        ((Percentile) percentileImpl).setQuantile(p);
    } else {
        try {
            percentileImpl.getClreplaced().getMethod("setQuantile", new Clreplaced[] { Double.TYPE }).invoke(percentileImpl, new Object[] { Double.valueOf(p) });
        } catch (NoSuchMethodException e1) {
            // Setter guard should prevent
            throw MathRuntimeException.createIllegalArgumentException("percentile implementation {0} does not support setQuantile", percentileImpl.getClreplaced().getName());
        } catch (IllegalAccessException e2) {
            throw MathRuntimeException.createIllegalArgumentException("cannot access setQuantile method in percentile implementation {0}", percentileImpl.getClreplaced().getName());
        } catch (InvocationTargetException e3) {
            throw MathRuntimeException.createIllegalArgumentException(e3.getCause());
        }
    }
    return apply(percentileImpl);
}

19 View Complete Implementation : ResizableDoubleArray.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Sets the <code>expansionMode</code>. The specified value must be one of
 * ADDITIVE_MODE, MULTIPLICATIVE_MODE.
 *
 * @param expansionMode The expansionMode to set.
 * @throws IllegalArgumentException if the specified mode value is not valid
 */
public void setExpansionMode(int expansionMode) {
    if (expansionMode != MULTIPLICATIVE_MODE && expansionMode != ADDITIVE_MODE) {
        throw MathRuntimeException.createIllegalArgumentException("unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})", expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE", ADDITIVE_MODE, "ADDITIVE_MODE");
    }
    synchronized (this) {
        this.expansionMode = expansionMode;
    }
}

19 View Complete Implementation : ChiSquareTestImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * @param counts array representation of 2-way table
 * @param alpha significance level of the test
 * @return true iff null hypothesis can be rejected with confidence
 * 1 - alpha
 * @throws IllegalArgumentException if preconditions are not met
 * @throws MathException if an error occurs performing the test
 */
public boolean chiSquareTest(long[][] counts, double alpha) throws IllegalArgumentException, MathException {
    if ((alpha <= 0) || (alpha > 0.5)) {
        throw MathRuntimeException.createIllegalArgumentException("out of bounds significance level {0}, must be between {1} and {2}", alpha, 0.0, 0.5);
    }
    return (chiSquareTest(counts) < alpha);
}

19 View Complete Implementation : RandomDataImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Generate a random value from a Normal (a.k.a. Gaussian) distribution with
 * the given mean, <code>mu</code> and the given standard deviation,
 * <code>sigma</code>.
 *
 * @param mu
 *            the mean of the distribution
 * @param sigma
 *            the standard deviation of the distribution
 * @return the random Normal value
 */
public double nextGaussian(double mu, double sigma) {
    if (sigma <= 0) {
        throw MathRuntimeException.createIllegalArgumentException("standard deviation must be positive ({0})", sigma);
    }
    RandomGenerator rand = getRan();
    return sigma * rand.nextGaussian() + mu;
}

19 View Complete Implementation : TTestImpl.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Check sample data.
 * @param data sample data
 * @exception IllegalArgumentException if there is not enough sample data
 */
private void checkSampleData(final double[] data) throws IllegalArgumentException {
    if ((data == null) || (data.length < 2)) {
        throw MathRuntimeException.createIllegalArgumentException("insufficient data for t statistic, needs at least 2, got {0}", (data == null) ? 0 : data.length);
    }
}

19 View Complete Implementation : ArrayRealVector.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Check if instance dimension is equal to some expected value.
 *
 * @param n expected dimension.
 * @exception IllegalArgumentException if the dimension is
 * inconsistent with vector size
 */
protected void checkVectorDimensions(int n) throws IllegalArgumentException {
    if (data.length != n) {
        throw MathRuntimeException.createIllegalArgumentException("vector length mismatch: got {0} but expected {1}", data.length, n);
    }
}

19 View Complete Implementation : FastFourierTransformer.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * Verifies that the data set has length of power of 2.
 *
 * @param o the data array
 * @throws IllegalArgumentException if array length is not power of 2
 */
public static void verifyDataSet(Object[] o) throws IllegalArgumentException {
    if (!isPowerOf2(o.length)) {
        throw MathRuntimeException.createIllegalArgumentException("{0} is not a power of 2, consider padding for fix", o.length);
    }
}

19 View Complete Implementation : Array2DRowRealMatrix.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
/**
 * {@inheritDoc}
 */
@Override
public void setSubMatrix(final double[][] subMatrix, final int row, final int column) throws MatrixIndexException {
    if (data == null) {
        if (row > 0) {
            throw MathRuntimeException.createIllegalStateException("first {0} rows are not initialized yet", row);
        }
        if (column > 0) {
            throw MathRuntimeException.createIllegalStateException("first {0} columns are not initialized yet", column);
        }
        final int nRows = subMatrix.length;
        if (nRows == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
        }
        final int nCols = subMatrix[0].length;
        if (nCols == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
        }
        data = new double[subMatrix.length][nCols];
        for (int i = 0; i < data.length; ++i) {
            if (subMatrix[i].length != nCols) {
                throw MathRuntimeException.createIllegalArgumentException("some rows have length {0} while others have length {1}", nCols, subMatrix[i].length);
            }
            System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
        }
    } else {
        super.setSubMatrix(subMatrix, row, column);
    }
}