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

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

Introduction

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

Prototype

LocalizedFormats INSUFFICIENT_DIMENSION

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

Click Source Link

Usage

From source file:org.orekit.propagation.analytical.Ephemeris.java

/** Constructor with tabulated states.
 * @param states tabulates states/*from  w w w . j  a v a  2s.c  o m*/
 * @param interpolationPoints number of points to use in interpolation
 * @exception OrekitException if some states have incompatible additional states
 * @exception MathIllegalArgumentException if the number of states is smaller than
 * the number of points to use in interpolation
 */
public Ephemeris(final List<SpacecraftState> states, final int interpolationPoints)
        throws OrekitException, MathIllegalArgumentException {

    super(DEFAULT_LAW);

    if (states.size() < interpolationPoints) {
        throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION, states.size(),
                interpolationPoints);
    }

    final SpacecraftState s0 = states.get(0);
    minDate = s0.getDate();
    maxDate = states.get(states.size() - 1).getDate();
    frame = s0.getFrame();

    final Set<String> names0 = s0.getAdditionalStates().keySet();
    additional = names0.toArray(new String[names0.size()]);

    // check all states handle the same additional states
    for (final SpacecraftState state : states) {
        s0.ensureCompatibleAdditionalStates(state);
    }

    pvProvider = new LocalPVProvider();

    //User needs to explicitly set attitude provider if they want to use one
    this.setAttitudeProvider(null);

    // set up cache
    cache = new ImmutableTimeStampedCache<SpacecraftState>(interpolationPoints, states);
}

From source file:stats.SpearmansCorrelation.java

/**
 * Computes the Spearman's rank correlation coefficient between the two
 * arrays./* w w w.  ja va 2  s.co m*/
 *
 * @param xArray
 *          first data array
 * @param yArray
 *          second data array
 * @return Returns Spearman's rank correlation coefficient for the two arrays
 * @throws DimensionMismatchException
 *           if the arrays lengths do not match
 * @throws MathIllegalArgumentException
 *           if the array length is less than 2
 */
public Pair<Double, Double> correlation(final double[] xArray, final double[] yArray) {
    if (xArray.length != yArray.length) {
        throw new DimensionMismatchException(xArray.length, yArray.length);
    } else if (xArray.length < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2);
    } else {
        double[] x = xArray;
        double[] y = yArray;
        if (rankingAlgorithm instanceof NaturalRanking
                && NaNStrategy.REMOVED == ((NaturalRanking) rankingAlgorithm).getNanStrategy()) {
            final Set<Integer> nanPositions = new HashSet<Integer>();

            nanPositions.addAll(getNaNPositions(xArray));
            nanPositions.addAll(getNaNPositions(yArray));

            x = removeValues(xArray, nanPositions);
            y = removeValues(yArray, nanPositions);
        }
        double $ = new PearsonsCorrelation().correlation(rankingAlgorithm.rank(x), rankingAlgorithm.rank(y));

        int degreesOfFreedom = x.length - 2;
        double t = $ * Math.sqrt(degreesOfFreedom / (1 - ($ * $)));
        double pValue = 2 * new TDistribution(degreesOfFreedom).cumulativeProbability(-1 * Math.abs(t));
        return new Pair<>($, pValue);
    }
}