• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MathRuntimeException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.math.MathRuntimeException的典型用法代码示例。如果您正苦于以下问题:Java MathRuntimeException类的具体用法?Java MathRuntimeException怎么用?Java MathRuntimeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MathRuntimeException类属于org.apache.commons.math包,在下文中一共展示了MathRuntimeException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: multiply

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * <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));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:Fraction.java


示例2: preMultiply

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/** {@inheritDoc} */
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(field, nCols);
    for (int col = 0; col < nCols; ++col) {
        T sum = field.getZero();
        for (int i = 0; i < nRows; ++i) {
            sum = sum.add(getEntry(i, col).multiply(v[i]));
        }
        out[col] = sum;
    }

    return out;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:AbstractFieldMatrix.java


示例3: operate

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public T[] operate(final T[] v)
    throws IllegalArgumentException {
    final int nRows = this.getRowDimension();
    final int nCols = this.getColumnDimension();
    if (v.length != nCols) {
        throw MathRuntimeException.createIllegalArgumentException(
              VECTOR_LENGTHS_MISMATCH, v.length, nCols);
    }
    final T[] out = buildArray(getField(), nRows);
    for (int row = 0; row < nRows; row++) {
        final T[] dataRow = data[row];
        T sum = getField().getZero();
        for (int i = 0; i < nCols; i++) {
            sum = sum.add(dataRow[i].multiply(v[i]));
        }
        out[row] = sum;
    }
    return out;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:Array2DRowFieldMatrix.java


示例4: covariance

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * 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) {
        throw MathRuntimeException.createIllegalArgumentException(
              LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length);
    } else if (length < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              LocalizedFormats.INSUFFICIENT_DIMENSION, length, 2);
    } else {
        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);
        }
    }
    return biasCorrected ? result * ((double) length / (double)(length - 1)) : result;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:Covariance.java


示例5: setNumElements

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * This function allows you to control the number of elements contained 
 * in this array, and can be used to "throw out" the last n values in an 
 * array. This function will also expand the internal array as needed.
 * 
 * @param i a new number of elements
 * @throws IllegalArgumentException if <code>i</code> is negative.
 */
public synchronized void setNumElements(int i) {

    // If index is negative thrown an error
    if (i < 0) {
        throw MathRuntimeException.createIllegalArgumentException(
                "index ({0}) is not positive",
                i);
    }

    // Test the new num elements, check to see if the array needs to be 
    // expanded to accommodate this new number of elements
    if ((startIndex + i) > internalArray.length) {
        expandTo(startIndex + i);
    }

    // Set the new number of elements to new value
    numElements = i;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:ResizableDoubleArray.java


示例6: preMultiply

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/** {@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_LENGTHS_MISMATCH, 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;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:Array2DRowFieldMatrix.java


示例7: addValue

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * Adds 1 to the frequency count for v.
 * <p>
 * If other objects have already been added to this Frequency, v must
 * be comparable to those that have already been added.
 * </p>
 *
 * @param v the value to add.
 * @throws IllegalArgumentException if <code>v</code> is not comparable with previous entries
 */
public void addValue(Comparable<?> v){
    Comparable<?> obj = v;
    if (v instanceof Integer) {
       obj = Long.valueOf(((Integer) v).longValue());
    }
    try {
        Long count = freqTable.get(obj);
        if (count == null) {
            freqTable.put(obj, Long.valueOf(1));
        } else {
            freqTable.put(obj, Long.valueOf(count.longValue() + 1));
        }
    } catch (ClassCastException ex) {
        //TreeMap will throw ClassCastException if v is not comparable
        throw MathRuntimeException.createIllegalArgumentException(
              "instance of class {0} not comparable to existing values",
              v.getClass().getName());
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:Frequency.java


示例8: AbstractFieldMatrix

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * Create a new FieldMatrix<T> with the supplied row and column dimensions.
 *
 * @param field field to which the elements belong
 * @param rowDimension  the number of rows in the new matrix
 * @param columnDimension  the number of columns in the new matrix
 * @throws IllegalArgumentException if row or column dimension is not positive
 */
protected AbstractFieldMatrix(final Field<T> field,
                              final int rowDimension, final int columnDimension)
    throws IllegalArgumentException {
    if (rowDimension <= 0 ) {
        throw MathRuntimeException.createIllegalArgumentException(
                "invalid row dimension {0} (must be positive)",
                rowDimension);
    }
    if (columnDimension <= 0) {
        throw MathRuntimeException.createIllegalArgumentException(
                "invalid column dimension {0} (must be positive)",
                columnDimension);
    }
    this.field = field;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:AbstractFieldMatrix.java


示例9: sample

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:FastFourierTransformer.java


示例10: set

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * Set a matrix element.
 * @param magnitude magnitude of the element
 * @param vector indices of the element
 * @return the previous value
 * @exception IllegalArgumentException if dimensions do not match
 */
public Complex set(Complex magnitude, int... vector)
    throws IllegalArgumentException {
    if (vector == null) {
        if (dimensionSize.length > 0) {
            throw MathRuntimeException.createIllegalArgumentException(
                    DIMENSION_MISMATCH_MESSAGE, 0, dimensionSize.length);
        }
        return null;
    }
    if (vector.length != dimensionSize.length) {
        throw MathRuntimeException.createIllegalArgumentException(
                DIMENSION_MISMATCH_MESSAGE, vector.length,dimensionSize.length);
    }

    Object[] lastDimension = (Object[]) multiDimensionalComplexArray;
    for (int i = 0; i < dimensionSize.length - 1; i++) {
        lastDimension = (Object[]) lastDimension[vector[i]];
    }

    Complex lastValue = (Complex) lastDimension[vector[dimensionSize.length - 1]];
    lastDimension[vector[dimensionSize.length - 1]] = magnitude;

    return lastValue;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:32,代码来源:FastFourierTransformer.java


示例11: nextInt

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/** {@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;
        }
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:BitsStreamGenerator.java


示例12: setWindowSize

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * WindowSize controls the number of values which contribute
 * to the reported statistics.  For example, if
 * windowSize is set to 3 and the values {1,2,3,4,5}
 * have been added <strong> in that order</strong>
 * then the <i>available values</i> are {3,4,5} and all
 * reported statistics will be based on these values
 * @param windowSize sets the size of the window.
 */
public void setWindowSize(int windowSize) {
    if (windowSize < 1) {
        if (windowSize != INFINITE_WINDOW) {
            throw MathRuntimeException.createIllegalArgumentException(
                  LocalizedFormats.NOT_POSITIVE_WINDOW_SIZE, windowSize);
        }
    }

    this.windowSize = windowSize;

    // We need to check to see if we need to discard elements
    // from the front of the array.  If the windowSize is less than
    // the current number of elements.
    if (windowSize != INFINITE_WINDOW && windowSize < eDA.getNumElements()) {
        eDA.discardFrontElements(eDA.getNumElements() - windowSize);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:DescriptiveStatistics.java


示例13: pow

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * Raise a long to a long power.
 * @param k number to raise
 * @param e exponent (must be positive or null)
 * @return k<sup>e</sup>
 * @exception IllegalArgumentException if e is negative
 */
public static long pow(final long k, long e)
    throws IllegalArgumentException {

    if (e < 0) {
        throw MathRuntimeException.createIllegalArgumentException(
            "cannot raise an integral value to a negative power ({0}^{1})",
            k, e);
    }

    long result = 1l;
    long k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:MathUtils.java


示例14: operate

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/** {@inheritDoc} */
public FieldVector<T> operate(final FieldVector<T> v)
    throws IllegalArgumentException {
    try {
        return new ArrayFieldVector<T>(operate(((ArrayFieldVector<T>) v).getDataRef()), false);
    } catch (ClassCastException cce) {
        final int nRows = getRowDimension();
        final int nCols = getColumnDimension();
        if (v.getDimension() != nCols) {
            throw MathRuntimeException.createIllegalArgumentException(
                    "vector length mismatch: got {0} but expected {1}",
                    v.getDimension(), 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.getEntry(i)));
            }
            out[row] = sum;
        }

        return new ArrayFieldVector<T>(out, false);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:AbstractFieldMatrix.java


示例15: pow

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * Raise a BigInteger to a long power.
 * @param k number to raise
 * @param e exponent (must be positive or null)
 * @return k<sup>e</sup>
 * @exception IllegalArgumentException if e is negative
 */
public static BigInteger pow(final BigInteger k, long e)
    throws IllegalArgumentException {

    if (e < 0) {
        throw MathRuntimeException.createIllegalArgumentException(
            "cannot raise an integral value to a negative power ({0}^{1})",
            k, e);
    }

    BigInteger result = BigInteger.ONE;
    BigInteger k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result = result.multiply(k2p);
        }
        k2p = k2p.multiply(k2p);
        e = e >> 1;
    }

    return result;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:MathUtils.java


示例16: pow

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * Raise an int to an int power.
 * @param k number to raise
 * @param e exponent (must be positive or null)
 * @return k<sup>e</sup>
 * @exception IllegalArgumentException if e is negative
 */
public static int pow(final int k, int e)
    throws IllegalArgumentException {

    if (e < 0) {
        throw MathRuntimeException.createIllegalArgumentException(
            "cannot raise an integral value to a negative power ({0}^{1})",
            k, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:MathUtils.java


示例17: pow

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * Raise a long to an int power.
 *
 * @param k number to raise
 * @param e exponent (must be positive or null)
 * @return k<sup>e</sup>
 * @throws IllegalArgumentException if e is negative
 */
public static long pow(final long k, int e)
        throws IllegalArgumentException {

    if (e < 0) {
        throw MathRuntimeException.createIllegalArgumentException(
                "cannot raise an integral value to a negative power ({0}^{1})",
                k, e);
    }

    long result = 1l;
    long k2p = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;

}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:31,代码来源:MathUtils.java


示例18: copySubMatrix

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/** {@inheritDoc} */
public void copySubMatrix(int[] selectedRows, int[] selectedColumns, T[][] destination)
    throws MatrixIndexException, IllegalArgumentException {

    // safety checks
    checkSubMatrixIndex(selectedRows, selectedColumns);
    if ((destination.length < selectedRows.length) ||
        (destination[0].length < selectedColumns.length)) {
        throw MathRuntimeException.createIllegalArgumentException(
                "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
                destination.length, destination[0].length,
                selectedRows.length, selectedColumns.length);
    }

    // copy entries
    for (int i = 0; i < selectedRows.length; i++) {
        final T[] destinationI = destination[i];
        for (int j = 0; j < selectedColumns.length; j++) {
            destinationI[j] = getEntry(selectedRows[i], selectedColumns[j]);
        }
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:AbstractFieldMatrix.java


示例19: solve

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/** Solve the linear equation A &times; X = B in least square sense.
 * <p>The m&times;n matrix A may not be square, the solution X is
 * such that ||A &times; X - B|| is minimal.</p>
 * @param b right-hand side of the equation A &times; X = B
 * @return a vector X that minimizes the two norm of A &times; X - B
 * @exception IllegalArgumentException if matrices dimensions don't match
 * @exception InvalidMatrixException if decomposed matrix is singular
 */
public double[] solve(final double[] b)
    throws IllegalArgumentException, InvalidMatrixException {

    if (b.length != singularValues.length) {
        throw MathRuntimeException.createIllegalArgumentException(
                "vector length mismatch: got {0} but expected {1}",
                b.length, singularValues.length);
    }

    final double[] w = uT.operate(b);
    for (int i = 0; i < singularValues.length; ++i) {
        final double si = singularValues[i];
        if (si == 0) {
            throw new SingularMatrixException();
        }
        w[i] /= si;
    }
    return v.operate(w);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:SingularValueDecompositionImpl.java


示例20: setWindowSize

import org.apache.commons.math.MathRuntimeException; //导入依赖的package包/类
/**
 * WindowSize controls the number of values which contribute
 * to the reported statistics.  For example, if
 * windowSize is set to 3 and the values {1,2,3,4,5}
 * have been added <strong> in that order</strong>
 * then the <i>available values</i> are {3,4,5} and all
 * reported statistics will be based on these values
 * @param windowSize sets the size of the window.
 */
public void setWindowSize(int windowSize) {
    if (windowSize < 1) {
        if (windowSize != INFINITE_WINDOW) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "window size must be positive ({0})", windowSize);
        }
    }

    this.windowSize = windowSize;

    // We need to check to see if we need to discard elements
    // from the front of the array.  If the windowSize is less than
    // the current number of elements.
    if (windowSize != INFINITE_WINDOW && windowSize < eDA.getNumElements()) {
        eDA.discardFrontElements(eDA.getNumElements() - windowSize);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:DescriptiveStatistics.java



注:本文中的org.apache.commons.math.MathRuntimeException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectMap类代码示例发布时间:2022-05-23
下一篇:
Java ICompactionScanner类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap