当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.checkOrder方法代码示例

本文整理汇总了Java中org.apache.commons.math.util.MathUtils.checkOrder方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.checkOrder方法的具体用法?Java MathUtils.checkOrder怎么用?Java MathUtils.checkOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math.util.MathUtils的用法示例。


在下文中一共展示了MathUtils.checkOrder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: StepFunction

import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
 * Builds a step function from a list of abscissae and the corresponding
 * ordinates.
 *
 * @param x Abscissae.
 * @param y Ordinates.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if the {@code x} array is not sorted in strictly increasing order.
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
public StepFunction(double[] x,
                    double[] y) {
    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
    if (y.length != x.length) {
        throw new DimensionMismatchException(y.length, x.length);
    }
    MathUtils.checkOrder(x);

    abscissa = MathUtils.copyOf(x);
    ordinate = MathUtils.copyOf(y);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:StepFunction.java

示例2: PolynomialSplineFunction

import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
 * Construct a polynomial spline function with the given segment delimiters
 * and interpolating polynomials.
 * The constructor copies both arrays and assigns the copies to the knots
 * and polynomials properties, respectively.
 *
 * @param knots Spline segment interval delimiters.
 * @param polynomials Polynomial functions that make up the spline.
 * @throws NullArgumentException if either of the input arrays is {@code null}.
 * @throws NumberIsTooSmallException if knots has length less than 2.
 * @throws DimensionMismatchException if {@code polynomials.length != knots.length - 1}.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException if
 * the {@code knots} array is not strictly increasing.
 *
 */
public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[]) {
    if (knots == null ||
        polynomials == null) {
        throw new NullArgumentException();
    }
    if (knots.length < 2) {
        throw new NumberIsTooSmallException(LocalizedFormats.NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION,
                                            2, knots.length, false);
    }
    if (knots.length - 1 != polynomials.length) {
        throw new DimensionMismatchException(polynomials.length, knots.length);
    }
    MathUtils.checkOrder(knots);

    this.n = knots.length -1;
    this.knots = new double[n + 1];
    System.arraycopy(knots, 0, this.knots, 0, n + 1);
    this.polynomials = new PolynomialFunction[n];
    System.arraycopy(polynomials, 0, this.polynomials, 0, n);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:PolynomialSplineFunction.java

示例3: interpolate

import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
 * Computes a linear interpolating function for the data set.
 * @param x the arguments for the interpolation points
 * @param y the values for the interpolation points
 * @return a function which interpolates the data set
 * @throws DimensionMismatchException if {@code x} and {@code y}
 * have different sizes.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strict increasing order.
 * @throws NumberIsTooSmallException if the size of {@code x} is smaller
 * than 2.
 */
public PolynomialSplineFunction interpolate(double x[], double y[]) {
    if (x.length != y.length) {
        throw new DimensionMismatchException(x.length, y.length);
    }

    if (x.length < 2) {
        throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS,
                                            x.length, 2, true);
    }

    // Number of intervals.  The number of data points is n + 1.
    int n = x.length - 1;

    MathUtils.checkOrder(x);

    // Slope of the lines between the datapoints.
    final double m[] = new double[n];
    for (int i = 0; i < n; i++) {
        m[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]);
    }

    PolynomialFunction polynomials[] = new PolynomialFunction[n];
    final double coefficients[] = new double[2];
    for (int i = 0; i < n; i++) {
        coefficients[0] = y[i];
        coefficients[1] = m[i];
        polynomials[i] = new PolynomialFunction(coefficients);
    }

    return new PolynomialSplineFunction(x, polynomials);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:44,代码来源:LinearInterpolator.java

示例4: BicubicSplineInterpolatingFunction

import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
 * @param x Sample values of the x-coordinate, in increasing order.
 * @param y Sample values of the y-coordinate, in increasing order.
 * @param f Values of the function on every grid point.
 * @param dFdX Values of the partial derivative of function with respect
 * to x on every grid point.
 * @param dFdY Values of the partial derivative of function with respect
 * to y on every grid point.
 * @param d2FdXdY Values of the cross partial derivative of function on
 * every grid point.
 * @throws DimensionMismatchException if the various arrays do not contain
 * the expected number of elements.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} or {@code y} are not strictly increasing.
 * @throws NoDataException if any of the arrays has zero length.
 */
public BicubicSplineInterpolatingFunction(double[] x,
                                          double[] y,
                                          double[][] f,
                                          double[][] dFdX,
                                          double[][] dFdY,
                                          double[][] d2FdXdY)
    throws DimensionMismatchException {
    final int xLen = x.length;
    final int yLen = y.length;

    if (xLen == 0 || yLen == 0 || f.length == 0 || f[0].length == 0) {
        throw new NoDataException();
    }
    if (xLen != f.length) {
        throw new DimensionMismatchException(xLen, f.length);
    }
    if (xLen != dFdX.length) {
        throw new DimensionMismatchException(xLen, dFdX.length);
    }
    if (xLen != dFdY.length) {
        throw new DimensionMismatchException(xLen, dFdY.length);
    }
    if (xLen != d2FdXdY.length) {
        throw new DimensionMismatchException(xLen, d2FdXdY.length);
    }

    MathUtils.checkOrder(x);
    MathUtils.checkOrder(y);

    xval = x.clone();
    yval = y.clone();

    final int lastI = xLen - 1;
    final int lastJ = yLen - 1;
    splines = new BicubicSplineFunction[lastI][lastJ];

    for (int i = 0; i < lastI; i++) {
        if (f[i].length != yLen) {
            throw new DimensionMismatchException(f[i].length, yLen);
        }
        if (dFdX[i].length != yLen) {
            throw new DimensionMismatchException(dFdX[i].length, yLen);
        }
        if (dFdY[i].length != yLen) {
            throw new DimensionMismatchException(dFdY[i].length, yLen);
        }
        if (d2FdXdY[i].length != yLen) {
            throw new DimensionMismatchException(d2FdXdY[i].length, yLen);
        }
        final int ip1 = i + 1;
        for (int j = 0; j < lastJ; j++) {
            final int jp1 = j + 1;
            final double[] beta = new double[] {
                f[i][j], f[ip1][j], f[i][jp1], f[ip1][jp1],
                dFdX[i][j], dFdX[ip1][j], dFdX[i][jp1], dFdX[ip1][jp1],
                dFdY[i][j], dFdY[ip1][j], dFdY[i][jp1], dFdY[ip1][jp1],
                d2FdXdY[i][j], d2FdXdY[ip1][j], d2FdXdY[i][jp1], d2FdXdY[ip1][jp1]
            };

            splines[i][j] = new BicubicSplineFunction(computeSplineCoefficients(beta));
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:80,代码来源:BicubicSplineInterpolatingFunction.java

示例5: interpolate

import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
 * Computes an interpolating function for the data set.
 * @param x the arguments for the interpolation points
 * @param y the values for the interpolation points
 * @return a function which interpolates the data set
 * @throws DimensionMismatchException if {@code x} and {@code y}
 * have different sizes.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strict increasing order.
 * @throws NumberIsTooSmallException if the size of {@code x} is smaller
 * than 3.
 */
public PolynomialSplineFunction interpolate(double x[], double y[]) {
    if (x.length != y.length) {
        throw new DimensionMismatchException(x.length, y.length);
    }

    if (x.length < 3) {
        throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS,
                                            x.length, 3, true);
    }

    // Number of intervals.  The number of data points is n + 1.
    int n = x.length - 1;

    MathUtils.checkOrder(x);

    // Differences between knot points
    double h[] = new double[n];
    for (int i = 0; i < n; i++) {
        h[i] = x[i + 1] - x[i];
    }

    double mu[] = new double[n];
    double z[] = new double[n + 1];
    mu[0] = 0d;
    z[0] = 0d;
    double g = 0;
    for (int i = 1; i < n; i++) {
        g = 2d * (x[i+1]  - x[i - 1]) - h[i - 1] * mu[i -1];
        mu[i] = h[i] / g;
        z[i] = (3d * (y[i + 1] * h[i - 1] - y[i] * (x[i + 1] - x[i - 1])+ y[i - 1] * h[i]) /
                (h[i - 1] * h[i]) - h[i - 1] * z[i - 1]) / g;
    }

    // cubic spline coefficients --  b is linear, c quadratic, d is cubic (original y's are constants)
    double b[] = new double[n];
    double c[] = new double[n + 1];
    double d[] = new double[n];

    z[n] = 0d;
    c[n] = 0d;

    for (int j = n -1; j >=0; j--) {
        c[j] = z[j] - mu[j] * c[j + 1];
        b[j] = (y[j + 1] - y[j]) / h[j] - h[j] * (c[j + 1] + 2d * c[j]) / 3d;
        d[j] = (c[j + 1] - c[j]) / (3d * h[j]);
    }

    PolynomialFunction polynomials[] = new PolynomialFunction[n];
    double coefficients[] = new double[4];
    for (int i = 0; i < n; i++) {
        coefficients[0] = y[i];
        coefficients[1] = b[i];
        coefficients[2] = c[i];
        coefficients[3] = d[i];
        polynomials[i] = new PolynomialFunction(coefficients);
    }

    return new PolynomialSplineFunction(x, polynomials);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:72,代码来源:SplineInterpolator.java

示例6: BicubicSplineInterpolatingFunction

import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
 * @param x Sample values of the x-coordinate, in increasing order.
 * @param y Sample values of the y-coordinate, in increasing order.
 * @param f Values of the function on every grid point.
 * @param dFdX Values of the partial derivative of function with respect
 * to x on every grid point.
 * @param dFdY Values of the partial derivative of function with respect
 * to y on every grid point.
 * @param d2FdXdY Values of the cross partial derivative of function on
 * every grid point.
 * @throws DimensionMismatchException if the various arrays do not contain
 * the expected number of elements.
 * @throws IllegalArgumentException if {@code x} or {@code y} are not strictly
 * increasing.
 */
public BicubicSplineInterpolatingFunction(double[] x,
                                          double[] y,
                                          double[][] f,
                                          double[][] dFdX,
                                          double[][] dFdY,
                                          double[][] d2FdXdY)
    throws DimensionMismatchException {
    final int xLen = x.length;
    final int yLen = y.length;

    if (xLen == 0 || yLen == 0 || f.length == 0 || f[0].length == 0) {
        throw MathRuntimeException.createIllegalArgumentException("no data");
    }
    if (xLen != f.length) {
        throw new DimensionMismatchException(xLen, f.length);
    }
    if (xLen != dFdX.length) {
        throw new DimensionMismatchException(xLen, dFdX.length);
    }
    if (xLen != dFdY.length) {
        throw new DimensionMismatchException(xLen, dFdY.length);
    }
    if (xLen != d2FdXdY.length) {
        throw new DimensionMismatchException(xLen, d2FdXdY.length);
    }

    MathUtils.checkOrder(x, 1, true);
    MathUtils.checkOrder(y, 1, true);

    xval = x.clone();
    yval = y.clone();

    final int lastI = xLen - 1;
    final int lastJ = yLen - 1;
    splines = new BicubicSplineFunction[lastI][lastJ];

    for (int i = 0; i < lastI; i++) {
        if (f[i].length != yLen) {
            throw new DimensionMismatchException(f[i].length, yLen);
        }
        if (dFdX[i].length != yLen) {
            throw new DimensionMismatchException(dFdX[i].length, yLen);
        }
        if (dFdY[i].length != yLen) {
            throw new DimensionMismatchException(dFdY[i].length, yLen);
        }
        if (d2FdXdY[i].length != yLen) {
            throw new DimensionMismatchException(d2FdXdY[i].length, yLen);
        }
        final int ip1 = i + 1;
        for (int j = 0; j < lastJ; j++) {
            final int jp1 = j + 1;
            final double[] beta = new double[] {
                f[i][j], f[ip1][j], f[i][jp1], f[ip1][jp1],
                dFdX[i][j], dFdX[ip1][j], dFdX[i][jp1], dFdX[ip1][jp1],
                dFdY[i][j], dFdY[ip1][j], dFdY[i][jp1], dFdY[ip1][jp1],
                d2FdXdY[i][j], d2FdXdY[ip1][j], d2FdXdY[i][jp1], d2FdXdY[ip1][jp1]
            };

            splines[i][j] = new BicubicSplineFunction(computeSplineCoefficients(beta));
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:79,代码来源:BicubicSplineInterpolatingFunction.java

示例7: verifyInterpolationArray

import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
 * Check that the interpolation arrays are valid.
 * The arrays features checked by this method are that both arrays have the
 * same length and this length is at least 2.
 *
 * @param x Interpolating points array.
 * @param y Interpolating values array.
 * @param abort Whether to throw an exception if {@code x} is not sorted.
 * @throws DimensionMismatchException if the array lengths are different.
 * @throws NumberIsTooSmallException if the number of points is less than 2.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strictly increasing order and {@code abort}
 * is {@code true}.
 * @return {@code false} if the {@code x} is not sorted in increasing order,
 * {@code true} otherwise.
 * @see #evaluate(double[], double[], double)
 * @see #computeCoefficients()
 */
public static boolean verifyInterpolationArray(double x[], double y[], boolean abort) {
    if (x.length != y.length) {
        throw new DimensionMismatchException(x.length, y.length);
    }
    if (x.length < 2) {
        throw new NumberIsTooSmallException(LocalizedFormats.WRONG_NUMBER_OF_POINTS, 2, x.length, true);
    }

    return MathUtils.checkOrder(x, MathUtils.OrderDirection.INCREASING, true, abort);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:PolynomialFunctionLagrangeForm.java


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