/** * Constructs a StandardDeviation. Sets the underlying {@link Variance} * instance's <code>isBiasCorrected</code> property to true. */ public StandardDeviation() { variance = new Variance(); }
/** * Constructs a StandardDeviation from an external second moment. * * @param m2 the external moment */ public StandardDeviation(final SecondMoment m2) { variance = new Variance(m2); }
/** * Contructs a StandardDeviation with the specified value for the * <code>isBiasCorrected</code> property. If this property is set to * <code>true</code>, the {@link Variance} used in computing results will * use the bias-corrected, or "sample" formula. See {@link Variance} for * details. * * @param isBiasCorrected whether or not the variance computation will use * the bias-corrected formula */ public StandardDeviation(boolean isBiasCorrected) { variance = new Variance(isBiasCorrected); }
/** * Contructs a StandardDeviation with the specified value for the * <code>isBiasCorrected</code> property and the supplied external moment. * If <code>isBiasCorrected</code> is set to <code>true</code>, the * {@link Variance} used in computing results will use the bias-corrected, * or "sample" formula. See {@link Variance} for details. * * @param isBiasCorrected whether or not the variance computation will use * the bias-corrected formula * @param m2 the external moment */ public StandardDeviation(boolean isBiasCorrected, SecondMoment m2) { variance = new Variance(isBiasCorrected, m2); }
/** * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance"> * population variance</a> of the available values. * * @return The population variance, Double.NaN if no values have been added, * or 0.0 for a single value set. */ public double getPopulationVariance() { return apply(new Variance(false)); }
/** * {@inheritDoc} */ @Override public Variance copy() { Variance result = new Variance(); // No try-catch or advertised exception because parameters are guaranteed non-null copy(this, result); return result; }
/** * 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 <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 <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); }
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); }
/** * 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); }
@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); }
/** * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance"> * population variance</a> of the values that have been added. * * <p>Double.NaN is returned if no values have been added.</p> * * @return the population variance */ public double getPopulationVariance() { Variance populationVariance = new Variance(secondMoment); populationVariance.setBiasCorrected(false); return populationVariance.getResult(); }
/** * 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; }
/** {@inheritDoc} */ @Override public double score(final List<? extends Cluster<T>> clusters) { double varianceSum = 0.0; for (final Cluster<T> cluster : clusters) { if (!cluster.getPoints().isEmpty()) { final Clusterable center = centroidOf(cluster); // compute the distance variance of the current cluster final Variance stat = new Variance(); for (final T point : cluster.getPoints()) { stat.increment(distance(point, center)); } varianceSum += stat.getResult(); } } return varianceSum; }
final Variance stat = new Variance(); for (final T point : cluster.getPoints()) { stat.increment(distance(point, center));
/** * 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; }