/** {@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; }
/** * 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 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(); }
/** * Constructs a StandardDeviation. Sets the underlying {@link Variance} * instance's <code>isBiasCorrected</code> property to true. */ public StandardDeviation() { variance = new Variance(); }
Variance variance = new Variance(); variance.incrementAll(values, begin, length); double mean = variance.moment.m1; double stdDev = FastMath.sqrt(variance.getResult());
/** * 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); }
/** * {@inheritDoc} */ @Override public double getResult() { return FastMath.sqrt(variance.getResult()); }
/** * {@inheritDoc} */ @Override public void increment(final double d) { variance.increment(d); }
/** * Copy constructor, creates a new {@code Variance} identical * to the {@code original} * * @param original the {@code Variance} instance to copy * @throws NullArgumentException if original is null */ public Variance(Variance original) throws NullArgumentException { copy(original, this); }
/** * @param isBiasCorrected The isBiasCorrected to set. */ public void setBiasCorrected(boolean isBiasCorrected) { variance.setBiasCorrected(isBiasCorrected); }
/** * {@inheritDoc} */ @Override public void clear() { variance.clear(); }
/** * Constructs a StandardDeviation from an external second moment. * * @param m2 the external moment */ public StandardDeviation(final SecondMoment m2) { variance = new Variance(m2); }
Variance variance = new Variance(); variance.incrementAll(values, begin, length); double mean = variance.moment.m1; double stdDev = Math.sqrt(variance.getResult());
/** * 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); }
/** * Observed variance of the estimate. * * @return observed variance. */ public double observedVariance(){ return var.getResult(); }
/** * {@inheritDoc} */ @Override public void increment(final double d) { variance.increment(d); }