List of usage examples for org.apache.commons.math.stat.descriptive.moment Variance Variance
public Variance()
isBiasCorrected
property. From source file:com.discursive.jccook.math.StatExample.java
public static void main(String[] args) { double[] values = new double[] { 2.3, 5.4, 6.2, 7.3, 23.3 }; System.out.println("min: " + StatUtils.min(values)); System.out.println("max: " + StatUtils.max(values)); System.out.println("mean: " + StatUtils.mean(values)); System.out.println("product: " + StatUtils.product(values)); System.out.println("sum: " + StatUtils.sum(values)); System.out.println("variance: " + StatUtils.variance(values)); // Measures from previous example Min min = new Min(); System.out.println("min: " + min.evaluate(values)); Max max = new Max(); System.out.println("max: " + max.evaluate(values)); Mean mean = new Mean(); System.out.println("mean: " + mean.evaluate(values)); Product product = new Product(); System.out.println("product: " + product.evaluate(values)); Sum sum = new Sum(); System.out.println("sum: " + sum.evaluate(values)); Variance variance = new Variance(); System.out.println("variance: " + variance.evaluate(values)); // New measures Percentile percentile = new Percentile(); System.out.println("80 percentile value: " + percentile.evaluate(values, 80.0)); GeometricMean geoMean = new GeometricMean(); System.out.println("geometric mean: " + geoMean.evaluate(values)); StandardDeviation stdDev = new StandardDeviation(); System.out.println("standard dev: " + stdDev.evaluate(values)); Skewness skewness = new Skewness(); System.out.println("skewness: " + skewness.evaluate(values)); Kurtosis kurtosis = new Kurtosis(); System.out.println("kurtosis: " + kurtosis.evaluate(values)); }
From source file:com.metaos.pricer.volatility.RecentlyRealizedVolatility.java
/** * Creates calculator./* w w w . j a v a 2 s .com*/ * @param clicks number of clicks (referenced to timer) to evaluate prices. * @param timer timer to consider prices. * @param when time of reference (last moment to consider volatility). */ public RecentlyRealizedVolatility(final long clicks, final Timer timer, final Calendar when) { this.clicks = clicks; this.timer = timer; this.when = when; this.variance = new Variance(); }
From source file:laboGrid.graphs.replication.ReplicationGraphHeuristicGenerator.java
protected static void balanceMatrix(int[][] edges, int[] peerSize, double stopCriterion) { double[] normIn = new double[peerSize.length]; for (int i = 0; i < peerSize.length; ++i) { for (int j = 0; j < peerSize.length; ++j) { normIn[j] += edges[i][j];//from w w w .j a va2s .c o m } } for (int j = 0; j < peerSize.length; ++j) { normIn[j] /= peerSize[j]; } Variance v = new Variance(); double var1 = v.evaluate(normIn); System.out.println("Initial variance on DA incoming edges is " + var1); double var2 = 0; int k = 0; int maxJ = 1, minJ = 1; boolean updateVar1 = false; while ((var1 - var2) >= stopCriterion) { // First line (to ignore element (0,0)) double maxNorm = normIn[1], minNorm = normIn[1]; maxJ = 1; minJ = 1; for (int j = 1; j < peerSize.length; ++j) { if (normIn[j] > maxNorm) { maxJ = j; maxNorm = normIn[j]; } if (normIn[j] < minNorm) { minJ = j; minNorm = normIn[j]; } } if (minJ != maxJ) { balanceRow(0, edges, peerSize, minJ, maxJ, normIn); } // Other lines for (int i = 1; i < peerSize.length; ++i) { maxNorm = normIn[0]; minNorm = normIn[0]; maxJ = 0; minJ = 0; for (int j = 0; j < peerSize.length; ++j) { if (normIn[j] > maxNorm && i != j) { maxJ = j; maxNorm = normIn[j]; } if (normIn[j] < minNorm && i != j) { minJ = j; minNorm = normIn[j]; } } if (minJ != maxJ) { balanceRow(i, edges, peerSize, minJ, maxJ, normIn); } } double tmpVar = v.evaluate(normIn); if (updateVar1) var1 = var2; else updateVar1 = true; var2 = tmpVar; System.out.println( "After pass " + k + ", variance on DA incoming edges is " + var2 + " (vs. " + var1 + ")"); ++k; } }
From source file:edu.utexas.cs.tactex.servercustomers.factoredcustomer.LearningUtilityOptimizer.java
private double computeAggregateVariance(CapacityProfile profile, double[] otherCapacities) { double[] aggCapacities = new double[CapacityProfile.NUM_TIMESLOTS]; for (int i = 0; i < CapacityProfile.NUM_TIMESLOTS; ++i) { aggCapacities[i] = profile.getCapacity(i) + otherCapacities[i]; }/*from www.j ava2s . c o m*/ return new Variance().evaluate(aggCapacities); }
From source file:dr.evomodel.epidemiology.casetocase.CaseToCaseTreeLikelihood.java
public static Double[] getSummaryStatistics(Double[] variable) { double[] primitiveVariable = new double[variable.length]; for (int i = 0; i < variable.length; i++) { primitiveVariable[i] = variable[i]; }/*from w ww. j a v a 2s .c om*/ Double[] out = new Double[4]; out[0] = (new Mean()).evaluate(primitiveVariable); out[1] = (new Median()).evaluate(primitiveVariable); out[2] = (new Variance()).evaluate(primitiveVariable); out[3] = Math.sqrt(out[2]); return out; }
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 */// w w w .jav a2 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// ww w . j a va 2 s. com */ 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); }
From source file:org.gwaspi.statistics.ChiSqrBoundaryCalculator.java
protected static void calculateChisqrBoundaryByVariance() throws IOException, MathException { FileWriter repFW = new FileWriter(boundaryPath); BufferedWriter repBW = new BufferedWriter(repFW); NetcdfFile ncfile = NetcdfFile.open(netCDFFile); List<Dimension> dims = ncfile.getDimensions(); Dimension sizeDim = dims.get(0); Dimension simsDim = dims.get(1); String varName = "distributions"; Variable distributions = ncfile.findVariable(varName); try {/* ww w.j a v a 2 s.com*/ for (int i = 0; i < pointsNb; i++) { // distributions(i:i:1, 0:simsNb:1) ArrayDouble.D2 rdDoubleArrayD2 = (ArrayDouble.D2) distributions .read(i + ":" + i + ":1, 0:" + (simsDim.getLength() - 1) + ":1"); ArrayDouble.D1 rdDoubleArrayD1 = (D1) rdDoubleArrayD2.reduce(); double sampleSize = rdDoubleArrayD2.getSize(); double currentTot = 0; double[] allValues = new double[(int) sampleSize]; for (int j = 0; j < sampleSize; j++) { allValues[j] = rdDoubleArrayD1.get(j); currentTot += rdDoubleArrayD1.get(j); } Variance variance = new Variance(); double varianceValue = variance.evaluate(allValues); double currentAvg = currentTot / simNb; double low95 = currentAvg - varianceValue; double top95 = currentAvg + varianceValue; StringBuilder sb = new StringBuilder(); sb.append(top95); sb.append(","); sb.append(currentAvg); sb.append(","); sb.append(low95); repBW.append(sb + "\n"); } } catch (IOException ex) { log.error("Cannot read data", ex); } catch (InvalidRangeException ex) { log.error("Cannot read data", ex); } repBW.close(); repFW.close(); log.info("Confidence boundary created for {} points", N); }