/** * Returns the variance of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * * <p>This method returns the bias-corrected sample variance (using {@code n - 1} in * the denominator). Use {@link #populationVariance(double[])} for the non-bias-corrected * population variance.</p> * <p> * See {@link org.apache.commons.math3.stat.descriptive.moment.Variance} for * details on the computing algorithm.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @return the variance of the values or Double.NaN if the array is empty * @throws MathIllegalArgumentException if the array is null */ public static double variance(final double[] values) throws MathIllegalArgumentException { return VARIANCE.evaluate(values); }
/** * Returns the variance of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * * <p>This method returns the bias-corrected sample variance (using {@code n - 1} in * the denominator). Use {@link #populationVariance(double[], int, int)} for the non-bias-corrected * population variance.</p> * <p> * See {@link org.apache.commons.math3.stat.descriptive.moment.Variance} for * details on the computing algorithm.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null or the * array index parameters are not valid.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the variance of the values or Double.NaN if length = 0 * @throws MathIllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double variance(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { return VARIANCE.evaluate(values, begin, length); }
/** * Returns the variance of the entries in the input array, using the * precomputed mean value. Returns <code>Double.NaN</code> if the array * is empty. * <p> * See {@link Variance} for details on the computing algorithm.</p> * <p> * If <code>isBiasCorrected</code> is <code>true</code> the formula used * assumes that the supplied mean value is the arithmetic mean of the * sample data, not a known population parameter. If the mean is a known * population parameter, or if the "population" version of the variance is * desired, set <code>isBiasCorrected</code> to <code>false</code> before * invoking this method.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @param mean the precomputed mean value * @return the variance of the values or Double.NaN if the array is empty * @throws MathIllegalArgumentException if the array is null */ public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException { return evaluate(values, mean, 0, values.length); }
/** * Returns the variance of the entries in the input array, using the * precomputed mean value. Returns <code>Double.NaN</code> if the array * is empty. * * <p>This method returns the bias-corrected sample variance (using {@code n - 1} in * the denominator). Use {@link #populationVariance(double[], double)} for the non-bias-corrected * population variance.</p> * <p> * See {@link org.apache.commons.math3.stat.descriptive.moment.Variance} for * details on the computing algorithm.</p> * <p> * The formula used assumes that the supplied mean value is the arithmetic * mean of the sample data, not a known population parameter. This method * is supplied only to save computation when the mean has already been * computed.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @param mean the precomputed mean value * @return the variance of the values or Double.NaN if the array is empty * @throws MathIllegalArgumentException if the array is null */ public static double variance(final double[] values, final double mean) throws MathIllegalArgumentException { return VARIANCE.evaluate(values, mean); }
/** * Returns the Standard Deviation of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @return the standard deviation of the values or Double.NaN if length = 0 * @throws MathIllegalArgumentException if the array is null */ @Override public double evaluate(final double[] values) throws MathIllegalArgumentException { return FastMath.sqrt(variance.evaluate(values)); }
/** * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance"> * population variance</a> of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * See {@link org.apache.commons.math3.stat.descriptive.moment.Variance} for * details on the formula and computing algorithm.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @return the population variance of the values or Double.NaN if the array is empty * @throws MathIllegalArgumentException if the array is null */ public static double populationVariance(final double[] values) throws MathIllegalArgumentException { return new Variance(false).evaluate(values); }
/** * Returns the variance of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * See {@link Variance} for details on the computing algorithm.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @return the variance of the values or Double.NaN if length = 0 * @throws MathIllegalArgumentException if the array is null */ @Override public double evaluate(final double[] values) throws MathIllegalArgumentException { if (values == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); }
/** * Returns the Standard Deviation of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample. </p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the standard deviation of the values or Double.NaN if length = 0 * @throws MathIllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { return FastMath.sqrt(variance.evaluate(values, begin, length)); }
/** * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance"> * population variance</a> of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * See {@link org.apache.commons.math3.stat.descriptive.moment.Variance} for * details on the computing algorithm.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null or the * array index parameters are not valid.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the population variance of the values or Double.NaN if length = 0 * @throws MathIllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double populationVariance(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { return new Variance(false).evaluate(values, begin, length); }
/** * Returns the Standard Deviation of the entries in the input array, using * the precomputed mean value. Returns * <code>Double.NaN</code> if the designated subarray is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * The formula used assumes that the supplied mean value is the arithmetic * mean of the sample data, not a known population parameter. This method * is supplied only to save computation when the mean has already been * computed.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @param mean the precomputed mean value * @return the standard deviation of the values or Double.NaN if length = 0 * @throws MathIllegalArgumentException if the array is null */ public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException { return FastMath.sqrt(variance.evaluate(values, mean)); }
/** * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance"> * population variance</a> of the entries in the input array, using the * precomputed mean value. Returns <code>Double.NaN</code> if the array * is empty. * <p> * See {@link org.apache.commons.math3.stat.descriptive.moment.Variance} for * details on the computing algorithm.</p> * <p> * The formula used assumes that the supplied mean value is the arithmetic * mean of the sample data, not a known population parameter. This method * is supplied only to save computation when the mean has already been * computed.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>MathIllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @param mean the precomputed mean value * @return the population variance of the values or Double.NaN if the array is empty * @throws MathIllegalArgumentException if the array is null */ public static double populationVariance(final double[] values, final double mean) throws MathIllegalArgumentException { return new Variance(false).evaluate(values, mean); }
/** * Returns the Standard Deviation of the entries in the specified portion of * the input array, using the precomputed mean value. Returns * <code>Double.NaN</code> if the designated subarray is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * The formula used assumes that the supplied mean value is the arithmetic * mean of the sample data, not a known population parameter. This method * is supplied only to save computation when the mean has already been * computed.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @param mean the precomputed mean value * @param begin index of the first array element to include * @param length the number of elements to include * @return the standard deviation of the values or Double.NaN if length = 0 * @throws MathIllegalArgumentException if the array is null or the array index * parameters are not valid */ public double evaluate(final double[] values, final double mean, final int begin, final int length) throws MathIllegalArgumentException { return FastMath.sqrt(variance.evaluate(values, mean, begin, length)); }
return new Variance(false).evaluate(values, mean, begin, length);
@Override public Number getExpectedValue(int start, int length) { if (length == 0) { return null; } double[] values = new double[length]; for (int i = 0; i < length; i++) { values[i] = start + i; } Variance variance = new Variance(false); return variance.evaluate(values); }
@Override public Number getExpectedValue(int start, int length) { if (length < 2) { return null; } double[] values = new double[length]; for (int i = 0; i < length; i++) { values[i] = start + i; } Variance variance = new Variance(); return variance.evaluate(values); }
@Override public Number getExpectedValue(int start, int length) { if (length == 0) { return null; } double[] values = new double[length]; for (int i = 0; i < length; i++) { values[i] = start + i; } Variance variance = new Variance(false); return variance.evaluate(values); }
/** * Calculates the variance of the y values. * * @return Y variance */ protected double calculateYVariance() { return new Variance().evaluate(yVector.toArray()); }
@Override public Number getExpectedValue(int start, int length) { if (length < 2) { return null; } double[] values = new double[length]; for (int i = 0; i < length; i++) { values[i] = start + i; } Variance variance = new Variance(); return variance.evaluate(values); }
/** * The variance of the derived resources. * @return a non-null array where the ith index is the variance of RawAndDerivedResource.ordinal(). */ public double[] variance() { RawAndDerivedResource[] resources = RawAndDerivedResource.values(); double[][] utilization = utilizationMatrix(); double[] variance = new double[resources.length]; for (int resourceIndex = 0; resourceIndex < resources.length; resourceIndex++) { Variance varianceCalculator = new Variance(); variance[resourceIndex] = varianceCalculator.evaluate(utilization[resourceIndex]); } return variance; }
/** * Compute a covariance matrix from a matrix whose columns represent * covariates. * @param matrix input matrix (must have at least one column and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) throws MathIllegalArgumentException { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } return outMatrix; }