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

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

Introduction

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

Prototype

public NoDataException() 

Source Link

Document

Construct the exception.

Usage

From source file:au.gov.ga.conn4d.utils.BicubicSplineInterpolator.java

public BicubicSplineInterpolatingFunction interpolate(final double[] xval, final double[] yval,
        final double[][] fval) throws NoDataException, DimensionMismatchException,
        NonMonotonicSequenceException, NumberIsTooSmallException {
    if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
        throw new NoDataException();
    }/* w ww  .j a v a2 s . c  o m*/
    if (xval.length != fval.length) {
        throw new DimensionMismatchException(xval.length, fval.length);
    }

    MathArrays.checkOrder(xval);
    MathArrays.checkOrder(yval);

    final int xLen = xval.length;
    final int yLen = yval.length;

    // Samples (first index is y-coordinate, i.e. subarray variable is x)
    // 0 <= i < xval.length
    // 0 <= j < yval.length
    // fX[j][i] = f(xval[i], yval[j])
    final double[][] fX = new double[yLen][xLen];
    for (int i = 0; i < xLen; i++) {
        if (fval[i].length != yLen) {
            throw new DimensionMismatchException(fval[i].length, yLen);
        }

        for (int j = 0; j < yLen; j++) {
            fX[j][i] = fval[i][j];
        }
    }

    final SplineInterpolator spInterpolator = new SplineInterpolator();

    // For each line y[j] (0 <= j < yLen), construct a 1D spline with
    // respect to variable x
    final PolynomialSplineFunction[] ySplineX = new PolynomialSplineFunction[yLen];
    for (int j = 0; j < yLen; j++) {
        ySplineX[j] = spInterpolator.interpolate(xval, fX[j]);
    }

    // For each line x[i] (0 <= i < xLen), construct a 1D spline with
    // respect to variable y generated by array fY_1[i]
    final PolynomialSplineFunction[] xSplineY = new PolynomialSplineFunction[xLen];
    for (int i = 0; i < xLen; i++) {
        xSplineY[i] = spInterpolator.interpolate(yval, fval[i]);
    }

    // Partial derivatives with respect to x at the grid knots
    final double[][] dFdX = new double[xLen][yLen];
    for (int j = 0; j < yLen; j++) {
        final UnivariateFunction f = ySplineX[j].derivative();
        for (int i = 0; i < xLen; i++) {
            dFdX[i][j] = f.value(xval[i]);
        }
    }

    // Partial derivatives with respect to y at the grid knots
    final double[][] dFdY = new double[xLen][yLen];
    for (int i = 0; i < xLen; i++) {
        final UnivariateFunction f = xSplineY[i].derivative();
        for (int j = 0; j < yLen; j++) {
            dFdY[i][j] = f.value(yval[j]);
        }
    }

    // Cross partial derivatives
    final double[][] d2FdXdY = new double[xLen][yLen];
    for (int i = 0; i < xLen; i++) {
        final int nI = nextIndex(i, xLen);
        final int pI = previousIndex(i);
        for (int j = 0; j < yLen; j++) {
            final int nJ = nextIndex(j, yLen);
            final int pJ = previousIndex(j);
            d2FdXdY[i][j] = (fval[nI][nJ] - fval[nI][pJ] - fval[pI][nJ] + fval[pI][pJ])
                    / ((xval[nI] - xval[pI]) * (yval[nJ] - yval[pJ]));
        }
    }

    // Create the interpolating splines
    return new BicubicSplineInterpolatingFunction(xval, yval, fval, dFdX, dFdY, d2FdXdY);
}

From source file:au.gov.ga.conn4d.utils.BicubicSplineInterpolatingFunction.java

/**
 * @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.//from   w w  w . j av a  2s .  com
 * @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 NonMonotonicSequenceException 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, NoDataException, NonMonotonicSequenceException {
    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);
    }

    MathArrays.checkOrder(x);
    MathArrays.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));
        }
    }
}

From source file:au.gov.ga.conn4d.utils.TricubicSplineInterpolator.java

public TricubicSplineInterpolatingFunction interpolate(final double[] zval, final double[] yval,
        final double[] xval, final float[][][] fval)
        throws NoDataException, DimensionMismatchException, NonMonotonicSequenceException {
    if (zval.length == 0 || yval.length == 0 || xval.length == 0 || fval.length == 0) {
        throw new NoDataException();
    }//ww w .java2 s  .  c  om
    if (zval.length != fval.length) {
        throw new DimensionMismatchException(zval.length, fval.length);
    }

    MathArrays.checkOrder(yval);
    MathArrays.checkOrder(xval);

    final int zLen = zval.length;
    final int yLen = yval.length;
    final int xLen = xval.length;

    final double[] zzval;
    float[][][] ffval = new float[zLen][][];

    if (zval[0] > zval[zLen - 1]) {
        zzval = VectorMath.selectionSort(zval);
        for (int i = 0; i < zLen; i++) {
            ffval[i] = fval[zLen - 1 - i];
        }
    } else {
        zzval = zval;
        ffval = fval;
    }

    // Samples, re-ordered as (z, x, y) and (y, z, x) tuplets
    // fvalXY[k][i][j] = f(xval[i], yval[j], zval[k])
    // fvalZX[j][k][i] = f(xval[i], yval[j], zval[k])
    final double[][][] fvalXY = new double[xLen][zLen][yLen];
    final double[][][] fvalZX = new double[yLen][xLen][zLen];
    for (int i = 0; i < zLen; i++) {
        if (ffval[i].length != yLen) {
            throw new DimensionMismatchException(ffval[i].length, yLen);
        }

        for (int j = 0; j < yLen; j++) {
            if (ffval[i][j].length != xLen) {
                throw new DimensionMismatchException(ffval[i][j].length, xLen);
            }

            for (int k = 0; k < xLen; k++) {
                final double v = ffval[i][j][k];
                fvalXY[k][i][j] = v;
                fvalZX[j][k][i] = v;
            }
        }
    }

    final BicubicSplineInterpolator bsi = new BicubicSplineInterpolator();

    // For each line x[i] (0 <= i < xLen), construct a 2D spline in y and z
    final BicubicSplineInterpolatingFunction[] xSplineYZ = new BicubicSplineInterpolatingFunction[zLen];
    for (int i = 0; i < zLen; i++) {
        xSplineYZ[i] = bsi.interpolate(yval, xval, ffval[i]);
    }

    // For each line y[j] (0 <= j < yLen), construct a 2D spline in z and x
    final BicubicSplineInterpolatingFunction[] ySplineZX = new BicubicSplineInterpolatingFunction[yLen];
    for (int j = 0; j < yLen; j++) {
        ySplineZX[j] = bsi.interpolate(xval, zzval, fvalZX[j]);
    }

    // For each line z[k] (0 <= k < zLen), construct a 2D spline in x and y
    final BicubicSplineInterpolatingFunction[] zSplineXY = new BicubicSplineInterpolatingFunction[xLen];
    for (int k = 0; k < xLen; k++) {
        zSplineXY[k] = bsi.interpolate(zzval, yval, fvalXY[k]);
    }

    // Partial derivatives wrt x and wrt y
    final double[][][] dFdX = new double[zLen][yLen][xLen];
    final double[][][] dFdY = new double[zLen][yLen][xLen];
    final double[][][] d2FdXdY = new double[zLen][yLen][xLen];
    for (int k = 0; k < xLen; k++) {
        final BicubicSplineInterpolatingFunction f = zSplineXY[k];
        for (int i = 0; i < zLen; i++) {
            final double x = zzval[i];
            for (int j = 0; j < yLen; j++) {
                final double y = yval[j];
                dFdX[i][j][k] = f.partialDerivativeX(x, y);
                dFdY[i][j][k] = f.partialDerivativeY(x, y);
                d2FdXdY[i][j][k] = f.partialDerivativeXY(x, y);
            }
        }
    }

    // Partial derivatives wrt y and wrt z
    final double[][][] dFdZ = new double[zLen][yLen][xLen];
    final double[][][] d2FdYdZ = new double[zLen][yLen][xLen];
    for (int i = 0; i < zLen; i++) {
        final BicubicSplineInterpolatingFunction f = xSplineYZ[i];
        for (int j = 0; j < yLen; j++) {
            final double y = yval[j];
            for (int k = 0; k < xLen; k++) {
                final double z = xval[k];
                dFdZ[i][j][k] = f.partialDerivativeY(y, z);
                d2FdYdZ[i][j][k] = f.partialDerivativeXY(y, z);
            }
        }
    }

    // Partial derivatives wrt x and wrt z
    final double[][][] d2FdZdX = new double[zLen][yLen][xLen];
    for (int j = 0; j < yLen; j++) {
        final BicubicSplineInterpolatingFunction f = ySplineZX[j];
        for (int k = 0; k < xLen; k++) {
            final double z = xval[k];
            for (int i = 0; i < zLen; i++) {
                final double x = zzval[i];
                d2FdZdX[i][j][k] = f.partialDerivativeXY(z, x);
            }
        }
    }

    // Third partial cross-derivatives
    final double[][][] d3FdXdYdZ = new double[zLen][yLen][xLen];
    for (int i = 0; i < zLen; i++) {
        final int nI = nextIndex(i, zLen);
        final int pI = previousIndex(i);
        for (int j = 0; j < yLen; j++) {
            final int nJ = nextIndex(j, yLen);
            final int pJ = previousIndex(j);
            for (int k = 0; k < xLen; k++) {
                final int nK = nextIndex(k, xLen);
                final int pK = previousIndex(k);

                // XXX Not sure about this formula
                d3FdXdYdZ[i][j][k] = (ffval[nI][nJ][nK] - ffval[nI][pJ][nK] - ffval[pI][nJ][nK]
                        + ffval[pI][pJ][nK] - ffval[nI][nJ][pK] + ffval[nI][pJ][pK] + ffval[pI][nJ][pK]
                        - ffval[pI][pJ][pK])
                        / ((zzval[nI] - zzval[pI]) * (yval[nJ] - yval[pJ]) * (xval[nK] - xval[pK]));
            }
        }
    }

    // Create the interpolating splines
    return new TricubicSplineInterpolatingFunction(zzval, yval, xval, ffval, dFdX, dFdY, dFdZ, d2FdXdY, d2FdZdX,
            d2FdYdZ, d3FdXdYdZ);
}

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

/**
 * Compute a weighted loess fit on the data at the original abscissae.
 *
 * @param xval Arguments for the interpolation points.
 * @param yval Values for the interpolation points.
 * @param weights point weights: coefficients by which the robustness weight
 * of a point is multiplied./*  w w  w  . j a  v a2 s . c o  m*/
 * @return the values of the loess fit at corresponding original abscissae.
 * @throws NonMonotonicSequenceException if {@code xval} not sorted in
 * strictly increasing order.
 * @throws DimensionMismatchException if {@code xval} and {@code yval} have
 * different sizes.
 * @throws NoDataException if {@code xval} or {@code yval} has zero size.
 * @throws NotFiniteNumberException if any of the arguments and values are
 not finite real numbers.
 * @throws NumberIsTooSmallException if the bandwidth is too small to
 * accomodate the size of the input data (i.e. the bandwidth must be
 * larger than 2/n).
 * @since 2.1
 */
public final double[] smooth(final double[] xval, final double[] yval, final double[] weights)
        throws NonMonotonicSequenceException, DimensionMismatchException, NoDataException,
        NotFiniteNumberException, NumberIsTooSmallException {
    if (xval.length != yval.length) {
        throw new DimensionMismatchException(xval.length, yval.length);
    }

    final int n = xval.length;

    if (n == 0) {
        throw new NoDataException();
    }

    checkAllFiniteReal(xval);
    checkAllFiniteReal(yval);
    checkAllFiniteReal(weights);

    MathArrays.checkOrder(xval, MathArrays.OrderDirection.INCREASING, false);

    if (n == 1) {
        return new double[] { yval[0] };
    }

    if (n == 2) {
        return new double[] { yval[0], yval[1] };
    }

    int bandwidthInPoints = (int) (bandwidth * n);

    if (bandwidthInPoints < 2) {
        throw new NumberIsTooSmallException(LocalizedFormats.BANDWIDTH, bandwidthInPoints, 2, true);
    }

    final double[] res = new double[n];

    final double[] residuals = new double[n];
    final double[] sortedResiduals = new double[n];

    final double[] robustnessWeights = new double[n];

    // Do an initial fit and 'robustnessIters' robustness iterations.
    // This is equivalent to doing 'robustnessIters+1' robustness iterations
    // starting with all robustness weights set to 1.
    Arrays.fill(robustnessWeights, 1);

    for (int iter = 0; iter <= robustnessIters; ++iter) {
        final int[] bandwidthInterval = { 0, bandwidthInPoints - 1 };
        // At each x, compute a local weighted linear regression
        for (int i = 0; i < n; ++i) {
            final double x = xval[i];

            // Find out the interval of source points on which
            // a regression is to be made.
            if (i > 0) {
                updateBandwidthInterval(xval, weights, i, bandwidthInterval);
            }

            final int ileft = bandwidthInterval[0];
            final int iright = bandwidthInterval[1];

            // Compute the point of the bandwidth interval that is
            // farthest from x
            final int edge;
            if (xval[i] - xval[ileft] > xval[iright] - xval[i]) {
                edge = ileft;
            } else {
                edge = iright;
            }

            // Compute a least-squares linear fit weighted by
            // the product of robustness weights and the tricube
            // weight function.
            // See http://en.wikipedia.org/wiki/Linear_regression
            // (section "Univariate linear case")
            // and http://en.wikipedia.org/wiki/Weighted_least_squares
            // (section "Weighted least squares")
            double sumWeights = 0;
            double sumX = 0;
            double sumXSquared = 0;
            double sumY = 0;
            double sumXY = 0;
            double denom = FastMath.abs(1.0 / (xval[edge] - x));
            for (int k = ileft; k <= iright; ++k) {
                final double xk = xval[k];
                final double yk = yval[k];
                final double dist = (k < i) ? x - xk : xk - x;
                final double w = tricube(dist * denom) * robustnessWeights[k] * weights[k];
                final double xkw = xk * w;
                sumWeights += w;
                sumX += xkw;
                sumXSquared += xk * xkw;
                sumY += yk * w;
                sumXY += yk * xkw;
            }

            final double meanX = sumX / sumWeights;
            final double meanY = sumY / sumWeights;
            final double meanXY = sumXY / sumWeights;
            final double meanXSquared = sumXSquared / sumWeights;

            final double beta;
            if (FastMath.sqrt(FastMath.abs(meanXSquared - meanX * meanX)) < accuracy) {
                beta = 0;
            } else {
                beta = (meanXY - meanX * meanY) / (meanXSquared - meanX * meanX);
            }

            final double alpha = meanY - beta * meanX;

            res[i] = beta * x + alpha;
            residuals[i] = FastMath.abs(yval[i] - res[i]);
        }

        // No need to recompute the robustness weights at the last
        // iteration, they won't be needed anymore
        if (iter == robustnessIters) {
            break;
        }

        // Recompute the robustness weights.

        // Find the median residual.
        // An arraycopy and a sort are completely tractable here,
        // because the preceding loop is a lot more expensive
        System.arraycopy(residuals, 0, sortedResiduals, 0, n);
        Arrays.sort(sortedResiduals);
        final double medianResidual = sortedResiduals[n / 2];

        if (FastMath.abs(medianResidual) < accuracy) {
            break;
        }

        for (int i = 0; i < n; ++i) {
            final double arg = residuals[i] / (6 * medianResidual);
            if (arg >= 1) {
                robustnessWeights[i] = 0;
            } else {
                final double w = 1 - arg * arg;
                robustnessWeights[i] = w * w;
            }
        }
    }

    return res;
}

From source file:com.itemanalysis.psychometrics.irt.estimation.JointMaximumLikelihoodEstimation.java

/**
 * Summarizes data into frequency counts. It keeps track of extreme persons (i.e. examinees that
 * earn the minimum or maximum possible test score) and extreme items (i.e. items answered correctly by
 * everyone or no one). Extreme items and persons are flagged. Frequency counts represent the valid
 * counts (i.e. frequencies for non-extreme persons and items). This method is recursive. It continues
 * as long as new extreme items or persons are detected. Otherwise, it stops.
 *
 * @param adjustment and adjustmnet factor applied to the ItemResponseSummary. This adjustment is needed
 *                   for estimation of extreme persons and items.
 *//*ww  w.  j  a  v a 2  s .  c o m*/
public void summarizeData(double adjustment) throws NoDataException {
    int extremePersonCount = 0;
    int extremeItemCount = 0;
    int droppedItemCount = 0;
    clearScores();

    //summarize each item individually
    for (int i = 0; i < nPeople; i++) {
        for (int j = 0; j < nItems; j++) {
            if (data[i][j] != -1) {
                if (droppedStatus[j] == 0 && extremeItem[j] == 0) {
                    //person scores should use only the nonextreme items
                    sumScore[i] += data[i][j];
                    minPossibleTestScore[i] += irm[j].getMinScoreWeight();
                    maxPossibleTestScore[i] += irm[j].getMaxScoreWeight();
                }
                if (extremePerson[i] == 0) {
                    //item scores should use only the nonextreme examinees
                    itemSummary[j].increment(data[i][j]);
                }

            }

        }

        //check for extreme person
        if (sumScore[i] == minPossibleTestScore[i]) {
            extremePerson[i] = -1;
            extremePersonCount++;
        } else if (sumScore[i] == maxPossibleTestScore[i]) {
            extremePerson[i] = 1;
            extremePersonCount++;
        } else {
            extremePerson[i] += 0;
        }
    }

    //Combine items in the same rating scale group group.
    //Must be done after frequencies are tabulated for each item.
    String groupId = "";
    RaschRatingScaleGroup raschRatingScaleGroup = null;
    for (int j = 0; j < nItems; j++) {
        if (irm[j].getNcat() > 2) {
            groupId = irm[j].getGroupId();
            raschRatingScaleGroup = rsg.get(groupId);
            if (raschRatingScaleGroup == null) {
                raschRatingScaleGroup = new RaschRatingScaleGroup(groupId, irm[j].getNcat());
                rsg.put(groupId, raschRatingScaleGroup);
            }
            raschRatingScaleGroup.addItem(irm[j], itemSummary[j], j);
        }
    }

    //check for extreme items
    for (int j = 0; j < nItems; j++) {
        if (itemSummary[j].isExtremeMaximum()) {
            extremeItem[j] = 1;
            extremeItemCount++;
        } else if (itemSummary[j].isExtremeMinimum()) {
            extremeItem[j] = -1;
            extremeItemCount++;
        } else {
            extremeItem[j] += 0;
        }

        //check for extreme category
        if (irm[j].getNcat() > 2) {
            RaschRatingScaleGroup tempGroup = rsg.get(irm[j].getGroupId());
            tempGroup.checkForDroppping();
            droppedStatus[j] = tempGroup.dropStatus();
            if (droppedStatus[j] != 0)
                droppedItemCount++;
        }

    } //end loop over items

    double priorCount = extremeCount;
    extremeCount = extremeItemCount + extremePersonCount;

    int priorDropCount = droppedCount;
    droppedCount = droppedItemCount;

    if (droppedItemCount != priorDropCount
            || (extremeCount != priorCount && extremeItemCount <= nItems && extremePersonCount <= nPeople)) {

        summarizeData(adjustment);

    }

    if (extremeItemCount == nItems || extremePersonCount == nPeople) {
        //no data remaining, throw an exception
        throw new NoDataException();
    }

}

From source file:au.gov.ga.conn4d.utils.TricubicSplineInterpolatingFunction.java

/**
 * @param x Sample values of the x-coordinate, in increasing order.
 * @param y Sample values of the y-coordinate, in increasing order.
 * @param z 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 dFdZ Values of the partial derivative of function with respect to z on every grid point.
 * @param d2FdXdY Values of the cross partial derivative of function on every grid point.
 * @param d2FdXdZ Values of the cross partial derivative of function on every grid point.
 * @param d2FdYdZ Values of the cross partial derivative of function on every grid point.
 * @param d3FdXdYdZ Values of the cross partial derivative of function on every grid point.
 * @throws NoDataException if any of the arrays has zero length.
 * @throws DimensionMismatchException if the various arrays do not contain the expected number of elements.
 * @throws NonMonotonicSequenceException if {@code x}, {@code y} or {@code z} are not strictly increasing.
 *//*from w  ww  .  jav a2 s  . c o m*/
public TricubicSplineInterpolatingFunction(double[] x, double[] y, double[] z, double[][][] f,
        double[][][] dFdX, double[][][] dFdY, double[][][] dFdZ, double[][][] d2FdXdY, double[][][] d2FdXdZ,
        double[][][] d2FdYdZ, double[][][] d3FdXdYdZ)
        throws NoDataException, DimensionMismatchException, NonMonotonicSequenceException {
    final int xLen = x.length;
    final int yLen = y.length;
    final int zLen = z.length;

    if (xLen == 0 || yLen == 0 || z.length == 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 != dFdZ.length) {
        throw new DimensionMismatchException(xLen, dFdZ.length);
    }
    if (xLen != d2FdXdY.length) {
        throw new DimensionMismatchException(xLen, d2FdXdY.length);
    }
    if (xLen != d2FdXdZ.length) {
        throw new DimensionMismatchException(xLen, d2FdXdZ.length);
    }
    if (xLen != d2FdYdZ.length) {
        throw new DimensionMismatchException(xLen, d2FdYdZ.length);
    }
    if (xLen != d3FdXdYdZ.length) {
        throw new DimensionMismatchException(xLen, d3FdXdYdZ.length);
    }

    MathArrays.checkOrder(x);
    MathArrays.checkOrder(y);
    MathArrays.checkOrder(z);

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

    final int lastI = xLen - 1;
    final int lastJ = yLen - 1;
    final int lastK = zLen - 1;
    splines = new TricubicSplineFunction[lastI][lastJ][lastK];

    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 (dFdZ[i].length != yLen) {
            throw new DimensionMismatchException(dFdZ[i].length, yLen);
        }
        if (d2FdXdY[i].length != yLen) {
            throw new DimensionMismatchException(d2FdXdY[i].length, yLen);
        }
        if (d2FdXdZ[i].length != yLen) {
            throw new DimensionMismatchException(d2FdXdZ[i].length, yLen);
        }
        if (d2FdYdZ[i].length != yLen) {
            throw new DimensionMismatchException(d2FdYdZ[i].length, yLen);
        }
        if (d3FdXdYdZ[i].length != yLen) {
            throw new DimensionMismatchException(d3FdXdYdZ[i].length, yLen);
        }

        final int ip1 = i + 1;
        for (int j = 0; j < lastJ; j++) {
            if (f[i][j].length != zLen) {
                throw new DimensionMismatchException(f[i][j].length, zLen);
            }
            if (dFdX[i][j].length != zLen) {
                throw new DimensionMismatchException(dFdX[i][j].length, zLen);
            }
            if (dFdY[i][j].length != zLen) {
                throw new DimensionMismatchException(dFdY[i][j].length, zLen);
            }
            if (dFdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(dFdZ[i][j].length, zLen);
            }
            if (d2FdXdY[i][j].length != zLen) {
                throw new DimensionMismatchException(d2FdXdY[i][j].length, zLen);
            }
            if (d2FdXdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(d2FdXdZ[i][j].length, zLen);
            }
            if (d2FdYdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(d2FdYdZ[i][j].length, zLen);
            }
            if (d3FdXdYdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(d3FdXdYdZ[i][j].length, zLen);
            }

            final int jp1 = j + 1;
            for (int k = 0; k < lastK; k++) {
                final int kp1 = k + 1;

                final double[] beta = new double[] { f[i][j][k], f[ip1][j][k], f[i][jp1][k], f[ip1][jp1][k],
                        f[i][j][kp1], f[ip1][j][kp1], f[i][jp1][kp1], f[ip1][jp1][kp1],

                        dFdX[i][j][k], dFdX[ip1][j][k], dFdX[i][jp1][k], dFdX[ip1][jp1][k], dFdX[i][j][kp1],
                        dFdX[ip1][j][kp1], dFdX[i][jp1][kp1], dFdX[ip1][jp1][kp1],

                        dFdY[i][j][k], dFdY[ip1][j][k], dFdY[i][jp1][k], dFdY[ip1][jp1][k], dFdY[i][j][kp1],
                        dFdY[ip1][j][kp1], dFdY[i][jp1][kp1], dFdY[ip1][jp1][kp1],

                        dFdZ[i][j][k], dFdZ[ip1][j][k], dFdZ[i][jp1][k], dFdZ[ip1][jp1][k], dFdZ[i][j][kp1],
                        dFdZ[ip1][j][kp1], dFdZ[i][jp1][kp1], dFdZ[ip1][jp1][kp1],

                        d2FdXdY[i][j][k], d2FdXdY[ip1][j][k], d2FdXdY[i][jp1][k], d2FdXdY[ip1][jp1][k],
                        d2FdXdY[i][j][kp1], d2FdXdY[ip1][j][kp1], d2FdXdY[i][jp1][kp1], d2FdXdY[ip1][jp1][kp1],

                        d2FdXdZ[i][j][k], d2FdXdZ[ip1][j][k], d2FdXdZ[i][jp1][k], d2FdXdZ[ip1][jp1][k],
                        d2FdXdZ[i][j][kp1], d2FdXdZ[ip1][j][kp1], d2FdXdZ[i][jp1][kp1], d2FdXdZ[ip1][jp1][kp1],

                        d2FdYdZ[i][j][k], d2FdYdZ[ip1][j][k], d2FdYdZ[i][jp1][k], d2FdYdZ[ip1][jp1][k],
                        d2FdYdZ[i][j][kp1], d2FdYdZ[ip1][j][kp1], d2FdYdZ[i][jp1][kp1], d2FdYdZ[ip1][jp1][kp1],

                        d3FdXdYdZ[i][j][k], d3FdXdYdZ[ip1][j][k], d3FdXdYdZ[i][jp1][k], d3FdXdYdZ[ip1][jp1][k],
                        d3FdXdYdZ[i][j][kp1], d3FdXdYdZ[ip1][j][kp1], d3FdXdYdZ[i][jp1][kp1],
                        d3FdXdYdZ[ip1][jp1][kp1], };

                splines[i][j][k] = new TricubicSplineFunction(computeSplineCoefficients(beta));
            }
        }
    }
}

From source file:au.gov.ga.conn4d.utils.TricubicSplineInterpolatingFunction.java

/**
 * @param x Sample values of the x-coordinate, in increasing order.
 * @param y Sample values of the y-coordinate, in increasing order.
 * @param z 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 dFdZ Values of the partial derivative of function with respect to z on every grid point.
 * @param d2FdXdY Values of the cross partial derivative of function on every grid point.
 * @param d2FdXdZ Values of the cross partial derivative of function on every grid point.
 * @param d2FdYdZ Values of the cross partial derivative of function on every grid point.
 * @param d3FdXdYdZ Values of the cross partial derivative of function on every grid point.
 * @throws NoDataException if any of the arrays has zero length.
 * @throws DimensionMismatchException if the various arrays do not contain the expected number of elements.
 * @throws NonMonotonicSequenceException if {@code x}, {@code y} or {@code z} are not strictly increasing.
 *//*  ww  w .j a  v  a2s. c  o m*/
public TricubicSplineInterpolatingFunction(double[] x, double[] y, double[] z, float[][][] f, double[][][] dFdX,
        double[][][] dFdY, double[][][] dFdZ, double[][][] d2FdXdY, double[][][] d2FdXdZ, double[][][] d2FdYdZ,
        double[][][] d3FdXdYdZ)
        throws NoDataException, DimensionMismatchException, NonMonotonicSequenceException {
    final int xLen = x.length;
    final int yLen = y.length;
    final int zLen = z.length;

    if (xLen == 0 || yLen == 0 || z.length == 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 != dFdZ.length) {
        throw new DimensionMismatchException(xLen, dFdZ.length);
    }
    if (xLen != d2FdXdY.length) {
        throw new DimensionMismatchException(xLen, d2FdXdY.length);
    }
    if (xLen != d2FdXdZ.length) {
        throw new DimensionMismatchException(xLen, d2FdXdZ.length);
    }
    if (xLen != d2FdYdZ.length) {
        throw new DimensionMismatchException(xLen, d2FdYdZ.length);
    }
    if (xLen != d3FdXdYdZ.length) {
        throw new DimensionMismatchException(xLen, d3FdXdYdZ.length);
    }

    MathArrays.checkOrder(x);
    MathArrays.checkOrder(y);
    MathArrays.checkOrder(z);

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

    final int lastI = xLen - 1;
    final int lastJ = yLen - 1;
    final int lastK = zLen - 1;
    splines = new TricubicSplineFunction[lastI][lastJ][lastK];

    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 (dFdZ[i].length != yLen) {
            throw new DimensionMismatchException(dFdZ[i].length, yLen);
        }
        if (d2FdXdY[i].length != yLen) {
            throw new DimensionMismatchException(d2FdXdY[i].length, yLen);
        }
        if (d2FdXdZ[i].length != yLen) {
            throw new DimensionMismatchException(d2FdXdZ[i].length, yLen);
        }
        if (d2FdYdZ[i].length != yLen) {
            throw new DimensionMismatchException(d2FdYdZ[i].length, yLen);
        }
        if (d3FdXdYdZ[i].length != yLen) {
            throw new DimensionMismatchException(d3FdXdYdZ[i].length, yLen);
        }

        final int ip1 = i + 1;
        for (int j = 0; j < lastJ; j++) {
            if (f[i][j].length != zLen) {
                throw new DimensionMismatchException(f[i][j].length, zLen);
            }
            if (dFdX[i][j].length != zLen) {
                throw new DimensionMismatchException(dFdX[i][j].length, zLen);
            }
            if (dFdY[i][j].length != zLen) {
                throw new DimensionMismatchException(dFdY[i][j].length, zLen);
            }
            if (dFdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(dFdZ[i][j].length, zLen);
            }
            if (d2FdXdY[i][j].length != zLen) {
                throw new DimensionMismatchException(d2FdXdY[i][j].length, zLen);
            }
            if (d2FdXdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(d2FdXdZ[i][j].length, zLen);
            }
            if (d2FdYdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(d2FdYdZ[i][j].length, zLen);
            }
            if (d3FdXdYdZ[i][j].length != zLen) {
                throw new DimensionMismatchException(d3FdXdYdZ[i][j].length, zLen);
            }

            final int jp1 = j + 1;
            for (int k = 0; k < lastK; k++) {
                final int kp1 = k + 1;

                final double[] beta = new double[] { f[i][j][k], f[ip1][j][k], f[i][jp1][k], f[ip1][jp1][k],
                        f[i][j][kp1], f[ip1][j][kp1], f[i][jp1][kp1], f[ip1][jp1][kp1],

                        dFdX[i][j][k], dFdX[ip1][j][k], dFdX[i][jp1][k], dFdX[ip1][jp1][k], dFdX[i][j][kp1],
                        dFdX[ip1][j][kp1], dFdX[i][jp1][kp1], dFdX[ip1][jp1][kp1],

                        dFdY[i][j][k], dFdY[ip1][j][k], dFdY[i][jp1][k], dFdY[ip1][jp1][k], dFdY[i][j][kp1],
                        dFdY[ip1][j][kp1], dFdY[i][jp1][kp1], dFdY[ip1][jp1][kp1],

                        dFdZ[i][j][k], dFdZ[ip1][j][k], dFdZ[i][jp1][k], dFdZ[ip1][jp1][k], dFdZ[i][j][kp1],
                        dFdZ[ip1][j][kp1], dFdZ[i][jp1][kp1], dFdZ[ip1][jp1][kp1],

                        d2FdXdY[i][j][k], d2FdXdY[ip1][j][k], d2FdXdY[i][jp1][k], d2FdXdY[ip1][jp1][k],
                        d2FdXdY[i][j][kp1], d2FdXdY[ip1][j][kp1], d2FdXdY[i][jp1][kp1], d2FdXdY[ip1][jp1][kp1],

                        d2FdXdZ[i][j][k], d2FdXdZ[ip1][j][k], d2FdXdZ[i][jp1][k], d2FdXdZ[ip1][jp1][k],
                        d2FdXdZ[i][j][kp1], d2FdXdZ[ip1][j][kp1], d2FdXdZ[i][jp1][kp1], d2FdXdZ[ip1][jp1][kp1],

                        d2FdYdZ[i][j][k], d2FdYdZ[ip1][j][k], d2FdYdZ[i][jp1][k], d2FdYdZ[ip1][jp1][k],
                        d2FdYdZ[i][j][kp1], d2FdYdZ[ip1][j][kp1], d2FdYdZ[i][jp1][kp1], d2FdYdZ[ip1][jp1][kp1],

                        d3FdXdYdZ[i][j][k], d3FdXdYdZ[ip1][j][k], d3FdXdYdZ[i][jp1][k], d3FdXdYdZ[ip1][jp1][k],
                        d3FdXdYdZ[i][j][kp1], d3FdXdYdZ[ip1][j][kp1], d3FdXdYdZ[i][jp1][kp1],
                        d3FdXdYdZ[ip1][jp1][kp1], };

                splines[i][j][k] = new TricubicSplineFunction(computeSplineCoefficients(beta));
            }
        }
    }
}

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

/**
 * Calculates the <a href="http://en.wikipedia.org/wiki/Convolution">
 * convolution</a> between two sequences.
 * <p/>/*  w w w.j  av a2  s  .  c om*/
 * The solution is obtained via straightforward computation of the
 * convolution sum (and not via FFT). Whenever the computation needs
 * an element that would be located at an index outside the input arrays,
 * the value is assumed to be zero.
 *
 * @param x First sequence.
 *          Typically, this sequence will represent an input signal to a system.
 * @param h Second sequence.
 *          Typically, this sequence will represent the impulse response of the system.
 * @return the convolution of {@code x} and {@code h}.
 * This array's length will be {@code x.length + h.length - 1}.
 * @throws NullArgumentException if either {@code x} or {@code h} is {@code null}.
 * @throws NoDataException       if either {@code x} or {@code h} is empty.
 * @since 3.3
 */
public static double[] convolve(double[] x, double[] h) throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(x);
    MathUtils.checkNotNull(h);

    final int xLen = x.length;
    final int hLen = h.length;

    if (xLen == 0 || hLen == 0) {
        throw new NoDataException();
    }

    // initialize the output array
    final int totalLength = xLen + hLen - 1;
    final double[] y = new double[totalLength];

    // straightforward implementation of the convolution sum
    for (int n = 0; n < totalLength; n++) {
        double yn = 0;
        int k = FastMath.max(0, n + 1 - xLen);
        int j = n - k;
        while (k < hLen && j >= 0) {
            yn += x[j--] * h[k++];
        }
        y[n] = yn;
    }

    return y;
}

From source file:umcg.genetica.math.stats.MannWhitneyUTest2.java

/**
 * Ensures that the provided arrays fulfills the assumptions.
 *
 * @param x first sample/* w  ww.j ava  2  s .  c o  m*/
 * @param y second sample
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
private void ensureDataConformance(final double[] x, final double[] y)
        throws NullArgumentException, NoDataException {

    if (x == null || y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 || y.length == 0) {
        throw new NoDataException();
    }
}