Example usage for org.apache.commons.math3.exception.util LocalizedFormats INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE

List of usage examples for org.apache.commons.math3.exception.util LocalizedFormats INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE

Introduction

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

Prototype

LocalizedFormats INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE

To view the source code for org.apache.commons.math3.exception.util LocalizedFormats INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE.

Click Source Link

Usage

From source file:cz.cuni.mff.spl.evaluator.statistics.KolmogorovSmirnovTestFlag.java

/**
 * Verifies that {@code array} has length at least 2.
 *
 * @param array array to test/*from  w  ww . java2 s.c o m*/
 * @throws NullArgumentException if array is null
 * @throws InsufficientDataException if array is too short
 */
private void checkArray(double[] array) {
    if (array == null) {
        throw new NullArgumentException(LocalizedFormats.NULL_NOT_ALLOWED);
    }
    if (array.length < 2) {
        throw new InsufficientDataException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE,
                array.length, 2);
    }
}

From source file:Rotationforest.Covariance.java

/**
 * 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//from ww w .  j  ava 2s .  c o  m
 * @param yArray second data array
 * @param biasCorrected if true, returned value will be bias-corrected
 * @return returns the covariance for the two arrays
 * @throws  MathIllegalArgumentException if the arrays lengths do not match or
 * there is insufficient data
 */
public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected)
        throws MathIllegalArgumentException {
    Mean mean = new Mean();
    double result = 0d;
    int length = xArray.length;
    if (length != yArray.length) {
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length,
                yArray.length);
    } else if (length < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, 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;
}