Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE
The following examples show how to use
org.apache.commons.math3.exception.util.LocalizedFormats#INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PSquarePercentile.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a marker array using initial five elements and a quantile * * @param initialFive list of initial five elements * @param p the pth quantile * @return Marker array */ private static Marker[] createMarkerArray( final List<Double> initialFive, final double p) { final int countObserved = initialFive == null ? -1 : initialFive.size(); if (countObserved < PSQUARE_CONSTANT) { throw new InsufficientDataException( LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, countObserved, PSQUARE_CONSTANT); } Collections.sort(initialFive); return new Marker[] { new Marker(),// Null Marker new Marker(initialFive.get(0), 1, 0, 1), new Marker(initialFive.get(1), 1 + 2 * p, p / 2, 2), new Marker(initialFive.get(2), 1 + 4 * p, p, 3), new Marker(initialFive.get(3), 3 + 2 * p, (1 + p) / 2, 4), new Marker(initialFive.get(4), 5, 1, 5) }; }
Example 2
Source File: Covariance.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 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; }
Example 3
Source File: HarmonicCurveFitter.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(Collection<WeightedObservedPoint> observations) { if (observations.size() < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.size(), 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations).toArray(new WeightedObservedPoint[0]); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 4
Source File: PSquarePercentile.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a marker array using initial five elements and a quantile * * @param initialFive list of initial five elements * @param p the pth quantile * @return Marker array */ private static Marker[] createMarkerArray( final List<Double> initialFive, final double p) { final int countObserved = initialFive == null ? -1 : initialFive.size(); if (countObserved < PSQUARE_CONSTANT) { throw new InsufficientDataException( LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, countObserved, PSQUARE_CONSTANT); } Collections.sort(initialFive); return new Marker[] { new Marker(),// Null Marker new Marker(initialFive.get(0), 1, 0, 1), new Marker(initialFive.get(1), 1 + 2 * p, p / 2, 2), new Marker(initialFive.get(2), 1 + 4 * p, p, 3), new Marker(initialFive.get(3), 3 + 2 * p, (1 + p) / 2, 4), new Marker(initialFive.get(4), 5, 1, 5) }; }
Example 5
Source File: Covariance.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 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; }
Example 6
Source File: Covariance.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 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; }
Example 7
Source File: HarmonicCurveFitter.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(Collection<WeightedObservedPoint> observations) { if (observations.size() < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.size(), 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations).toArray(new WeightedObservedPoint[0]); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 8
Source File: Math_25_HarmonicFitter_t.java From coming with MIT License | 5 votes |
/** * Simple constructor. * @param observations sampled observations * @throws NumberIsTooSmallException if the sample is too short or if * the first guess cannot be computed. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } this.observations = observations.clone(); }
Example 9
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 10
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 11
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 12
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * @param observations sampled observations * @throws NumberIsTooSmallException if the sample is too short or if * the first guess cannot be computed. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } this.observations = observations.clone(); }
Example 13
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 14
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 15
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 16
Source File: KolmogorovSmirnovTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Verifies that {@code array} has length at least 2. * * @param array array to test * @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); } }
Example 17
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example 18
Source File: HarmonicFitter_s.java From coming with MIT License | 5 votes |
/** * Simple constructor. * @param observations sampled observations * @throws NumberIsTooSmallException if the sample is too short or if * the first guess cannot be computed. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } this.observations = observations.clone(); }
Example 19
Source File: KolmogorovSmirnovTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Verifies that {@code array} has length at least 2. * * @param array array to test * @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); } }
Example 20
Source File: AbstractMultipleLinearRegression.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Loads model x and y sample data from a flat input array, overriding any previous sample. * </p> * <p>Assumes that rows are concatenated with y values first in each row. For example, an input * <code>data</code> array containing the sequence of values (1, 2, 3, 4, 5, 6, 7, 8, 9) with * <code>nobs = 3</code> and <code>nvars = 2</code> creates a regression dataset with two * independent variables, as below: * <pre> * y x[0] x[1] * -------------- * 1 2 3 * 4 5 6 * 7 8 9 * </pre> * </p> * <p>Note that there is no need to add an initial unitary column (column of 1's) when * specifying a model including an intercept term. If {@link #isNoIntercept()} is <code>true</code>, * the X matrix will be created without an initial column of "1"s; otherwise this column will * be added. * </p> * <p>Throws IllegalArgumentException if any of the following preconditions fail: * <ul><li><code>data</code> cannot be null</li> * <li><code>data.length = nobs * (nvars + 1)</li> * <li><code>nobs > nvars</code></li></ul> * </p> * * @param data input data array * @param nobs number of observations (rows) * @param nvars number of independent variables (columns, not counting y) * @throws NullArgumentException if the data array is null * @throws DimensionMismatchException if the length of the data array is not equal * to <code>nobs * (nvars + 1)</code> * @throws InsufficientDataException if <code>nobs</code> is less than * <code>nvars + 1</code> */ public void newSampleData(double[] data, int nobs, int nvars) { if (data == null) { throw new NullArgumentException(); } if (data.length != nobs * (nvars + 1)) { throw new DimensionMismatchException(data.length, nobs * (nvars + 1)); } if (nobs <= nvars) { throw new InsufficientDataException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, nobs, nvars + 1); } double[] y = new double[nobs]; final int cols = noIntercept ? nvars: nvars + 1; double[][] x = new double[nobs][cols]; int pointer = 0; for (int i = 0; i < nobs; i++) { y[i] = data[pointer++]; if (!noIntercept) { x[i][0] = 1.0d; } for (int j = noIntercept ? 0 : 1; j < cols; j++) { x[i][j] = data[pointer++]; } } this.xMatrix = new Array2DRowRealMatrix(x); this.yVector = new ArrayRealVector(y); }