List of usage examples for org.apache.commons.math.stat.descriptive.moment Variance getResult
@Override public double getResult()
From source file:org.basketball.MyKMeansPlusPlusClusterer.java
/** * Get a random point from the {@link Cluster} with the largest distance variance. * * @param clusters the {@link Cluster}s to search * @return a random point from the selected cluster */// ww w. jav a 2 s. co m private T getPointFromLargestVarianceCluster(final Collection<Cluster<T>> clusters) { double maxVariance = Double.NEGATIVE_INFINITY; Cluster<T> selected = null; for (final Cluster<T> cluster : clusters) { if (!cluster.getPoints().isEmpty()) { // compute the distance variance of the current cluster final T center = cluster.getCenter(); final Variance stat = new Variance(); for (final T point : cluster.getPoints()) { stat.increment(point.distanceFrom(center)); } final double variance = stat.getResult(); // select the cluster with the largest variance if (variance > maxVariance) { maxVariance = variance; selected = cluster; } } } // did we find at least one non-empty cluster ? if (selected == null) { throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS); } // extract a random point from the cluster final List<T> selectedPoints = selected.getPoints(); return selectedPoints.remove(random.nextInt(selectedPoints.size())); }
From source file:org.beedraz.semantics_II.MathBugDemonstration.java
/** * @param args/*from w ww .j a v a 2 s. co m*/ */ public static void main(String[] args) { // difference between getResult and evaluate // double[] values = new double[] {1.0, 2.0, Double.POSITIVE_INFINITY}; // Variance var1 = new Variance(); // double value1 = var1.evaluate(values); // Variance var2 = new Variance(); // var2.incrementAll(values); // double value2 = var2.getResult(); // System.out.println(value1); // System.out.println(value2); // difference between getResult and evaluate double[] values = new double[] { 1.0, 2.0, Double.NEGATIVE_INFINITY }; Variance var1 = new Variance(); double value1 = var1.evaluate(values); Variance var2 = new Variance(); var2.incrementAll(values); double value2 = var2.getResult(); var2.evaluate(values); System.out.println(value1); System.out.println(value2); // // evaluate method changes internal representation // double[] values = new double[] {1.0, 2.0, Double.NEGATIVE_INFINITY}; // Variance var1 = new Variance(); // var1.incrementAll(values); // System.out.println(var1.getN()); // System.out.println(var1.getResult()); // double value1 = var1.evaluate(values); // System.out.println(var1.getN()); // System.out.println(var1.getResult()); // System.out.println(value1); }