List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
From source file:saffranexperiment.Main.java
/** * Calculates the mean r<sup>2</sup> and RMSE value for each participant type * by taking into account the r<sup>2</sup> and RMSE values for each of the * participant type's repeats./* w w w .j av a 2 s . c o m*/ * * @param participantTypeRsquareAndRmseForEachRepeat A 3D {@link * java.util.Arrays Array} whose structure should be as follows: * * <ul> * <li>First dimension: participant types</li> * <li>Second dimension: repeats</li> * <li> * Third dimension: r<sup>2</sup> and RMSE as elements of the {@link * java.util.Arrays Array} in this order * </li> * </ul> * * For example, participantTypeRsquareAndRmseForEachRepeat[3][6][0] should * return the r<sup>2</sup> for the 7th repeat for participant type 4. * * @return A 2D {@link java.util.Arrays Array} whose structure should be as * follows: * * <ul> * <li>First dimension: participant types</li> * <li> * Second dimension: average r<sup>2</sup> and RMSE as elements of the * {@link java.util.Arrays Array} in this order * </li> * </ul> * * For example, invoking [3][0] on the returned {@link java.util.Arrays Array} * will return the average r<sup>2</sup> for participant type 4. */ private static double[][] calculateMeanRsquareAndRmseForEachParticipantType( double[][][] participantTypeRsquareAndRmseForEachRepeat) { double[][] meanRsquareAndRmseForEachParticipantType = new double[_totalParticipantTypes][2]; for (int participantType = 0; participantType < _totalParticipantTypes; participantType++) { DescriptiveStatistics rsquaresForParticipantType = new DescriptiveStatistics(); DescriptiveStatistics rmsesForParticipantType = new DescriptiveStatistics(); for (int repeat = 0; repeat < _totalRepeats; repeat++) { rsquaresForParticipantType .addValue(participantTypeRsquareAndRmseForEachRepeat[participantType][repeat][0]); rmsesForParticipantType .addValue(participantTypeRsquareAndRmseForEachRepeat[participantType][repeat][1]); } meanRsquareAndRmseForEachParticipantType[participantType][0] = rsquaresForParticipantType.getMean(); meanRsquareAndRmseForEachParticipantType[participantType][1] = rmsesForParticipantType.getMean(); } return meanRsquareAndRmseForEachParticipantType; }
From source file:sax.data.transform.SaxRepresentationImpl.java
@Override public void doStatistics() { final DescriptiveStatistics stats = new DescriptiveStatistics(); final List<TimeSeriesEntry> entries = series.getSeries(); for (TimeSeriesEntry entry : entries) { double value = entry.getValue(); stats.addValue(value); }/* w ww .j a v a 2 s .c o m*/ this.mean = stats.getMean(); this.standardDeviation = stats.getStandardDeviation(); System.out.printf("Mean: %s, sd: %s\n", mean, standardDeviation); }
From source file:streaming.core.WindowOperation.java
@Override public Object[][] process(Object[] event) { long day = (Long) event[0]; String word = (String) event[1]; long freqs = (Long) event[2]; TreeMap<Long, Long> sortedFreq = map.get(word); if (sortedFreq == null) { sortedFreq = new TreeMap<Long, Long>(); map.put(word, sortedFreq);//from ww w. ja va 2 s . c o m } Long t = sortedFreq.get(day); if (t != null) { freqs = freqs + t; } sortedFreq.put(day, freqs); Iterator<Entry<Long, Long>> iterator = sortedFreq.headMap(1 + day - numberOfDays).entrySet().iterator(); while (iterator.hasNext()) { iterator.next(); iterator.remove(); } DescriptiveStatistics stats = new DescriptiveStatistics(); long dayIndex = 1 + day - numberOfDays; for (Entry<Long, Long> e : sortedFreq.entrySet()) { while (e.getKey() > dayIndex) { dayIndex++; stats.addValue(0); } stats.addValue(e.getValue()); } if (sortedFreq.size() > numberOfDays) { System.out.println(day + " size=" + sortedFreq.size() + " " + sortedFreq); } double mean = stats.getMean(); double meadian = stats.getPercentile(50); mean = (mean == 0) ? 1 : mean; meadian = (meadian == 0) ? 1 : meadian; double stddev = stats.getStandardDeviation(); stddev = (stddev == 0) ? 1 : stddev; double cov = stddev / mean; //double swna = Math.log(freqs)*freqs/stats.getMean(); double swna1 = Math.log(meadian) * Math.abs(freqs - meadian) / stddev; if (Double.isNaN(swna1)) { System.out.println(); } double swna2 = Math.abs(freqs - meadian) / stddev; double swna3 = freqs / (meadian * cov); Gaussian gaussian = new Gaussian(100, 50); double swna4 = (0.1 + 100 * gaussian.value(meadian)) * freqs / (meadian * cov); int percentageAvialableValues = Math.round(100 * sortedFreq.size() / numberOfDays); //System.out.println("#"+ word + " " + freqs + " "+ stats.getMean() + Arrays.toString(stats.getValues())); return new Object[][] { { day, word, swna1, freqs, stats.getMean(), meadian, stddev, swna2, swna3, swna4, cov, percentageAvialableValues } }; // if(freqs > 3 && swna> 5){ // return new Object[][]{{day, word, swna}}; // }else{ // return null; // } }
From source file:tools.descartes.bungee.utils.DiffUtil.java
public static <T> DescriptiveStatistics createDescriptiveStatistics(List<T> objects) { // Get a DescriptiveStatistics instance DescriptiveStatistics statistics = new DescriptiveStatistics(); // Add the data from the array for (T object : objects) { if (object instanceof Long) { statistics.addValue((Long) object); } else if (object instanceof Double) { statistics.addValue((Double) object); } else if (object instanceof AbstractResponse) { statistics.addValue(((AbstractResponse) object).getResponseTime()); }//from w w w . j a v a 2 s. com } return statistics; }
From source file:tools.descartes.bungee.utils.DiffUtil.java
public static <T> StatsPercentile statisticsForDiffs(List<T> objects, double percent) { // Get a DescriptiveStatistics instance DescriptiveStatistics statistics = new DescriptiveStatistics(); // Add the data from the array for (T object : objects) { if (object instanceof Long) { statistics.addValue((Long) object); } else if (object instanceof Double) { statistics.addValue((Double) object); } else if (object instanceof AbstractResponse) { statistics.addValue(((AbstractResponse) object).getResponseTime()); }//from w ww . j a v a 2s . co m } StatsPercentile stats = new StatsPercentile(); // Compute some statistics stats.mean = statistics.getMean(); stats.std = statistics.getStandardDeviation(); stats.max = Math.max(statistics.getMax(), -statistics.getMin()); stats.percent = percent; stats.percentile = statistics.getPercentile(percent); return stats; }
From source file:uk.ac.cam.cl.dtg.teaching.programmingtest.java.FittedCurve.java
/** * Attempt to fit this curve.// w w w.j av a2s . c o m */ public void fit() { List<Point> mapped = mapValues(xs, ys); DescriptiveStatistics s = new DescriptiveStatistics(); for (int i = 0; i < 20; ++i) { double r = fit(mapped, 0.5); s.addValue(r); } rsq = s.getMean(); }
From source file:uk.ac.diamond.scisoft.analysis.diffraction.PowderRingsUtils.java
/** * Find major axes by looking along thick line given by relative coordinates to centre for * maximum intensity values/* ww w. j a va 2 s.c o m*/ * @param mon * @param axes * @param image * @param mask * @param roi * @param offset minimum position of peaks * @param width of line * @param centre * @param dx * @param dy */ private static void findMajorAxes(IMonitor mon, TreeSet<Double> axes, Dataset image, Dataset mask, EllipticalROI roi, double offset, double width, double[] centre, double dx, double dy) { RectangularROI rroi = new RectangularROI(); rroi.setPoint(centre); rroi.setAngle(Math.atan2(dy, dx)); rroi.setLengths(Math.hypot(dx, dy), width); rroi.translate(0, -0.5); rroi.setClippingCompensation(true); Dataset profile = ROIProfile.maxInBox(image, mask, rroi)[0]; List<IdentifiedPeak> peaks = Generic1DFitter .findPeaks(DatasetFactory.createRange(profile.getSize(), Dataset.INT), profile, PEAK_SMOOTHING); if (mon != null) mon.worked(profile.getSize()); System.err.printf("\n"); DescriptiveStatistics stats = new DescriptiveStatistics(); int[] pb = new int[1]; int[] pe = new int[1]; for (IdentifiedPeak p : peaks) { if (p.getPos() < offset) { continue; } pb[0] = (int) p.getMinXVal(); pe[0] = (int) p.getMaxXVal(); p.setArea((Double) profile.getSlice(pb, pe, null).sum()); stats.addValue(p.getArea()); System.err.printf("P %f A %f W %f H %f\n", p.getPos(), p.getArea(), p.getFWHM(), p.getHeight()); } double area = stats.getMean() + 0.4 * (stats.getPercentile(75) - stats.getPercentile(25)); logger.debug("Area: {}", stats); logger.debug("Minimum threshold: {}", area); double majorFactor = roi.getSemiAxis(0) / roi.getDistance(rroi.getAngle()); double maxFWHM = MAX_FWHM_FACTOR * width; for (IdentifiedPeak p : peaks) { double l = p.getPos(); if (l < offset) { continue; } // System.err.println(p); // filter on area and FWHM if (p.getFWHM() > maxFWHM) { continue; } if (p.getArea() < area) { break; } axes.add(l * majorFactor); } if (mon != null) mon.worked(peaks.size()); }
From source file:uk.ac.soton.itinnovation.ecc.service.utils.ExplorerDemoData.java
public EccINTRATSummary getINTRATDistDataDiscrete(UUID attrID, ArrayList<Date> stamps) { EccINTRATSummary result = null;/*from ww w . ja v a 2 s . c o m*/ // Safety if (attrID != null && stamps != null) { EccAttributeInfo info = qosAttributesByID.get(attrID); EccINTRATSeries srcSeries = qosSeries.get(attrID); if (info != null && srcSeries != null) { // Copy source series data with just those timestamps ArrayList<EccMeasurement> targMeasures = new ArrayList<>(); for (EccMeasurement srcM : srcSeries.getValues()) for (Date targDate : stamps) if (srcM.getTimestamp().equals(targDate)) targMeasures.add(new EccMeasurement(srcM)); // If we've got any data, create a summary if (!targMeasures.isEmpty()) { DescriptiveStatistics ds = new DescriptiveStatistics(); for (EccMeasurement m : targMeasures) ds.addValue(Double.parseDouble(m.getValue())); result = new EccINTRATSummary(info, ds.getMin(), ds.getMean(), ds.getMax()); } } } return result; }
From source file:uk.ac.soton.itinnovation.ecc.service.utils.ExplorerDemoData.java
public EccINTRATSummary getQosSummary(UUID attrID) { EccINTRATSummary result = null;/*ww w . j a v a 2 s. c om*/ if (attrID != null) { // Find QoS series and calculate summary data EccINTRATSeries series = qosSeries.get(attrID); if (series != null) { DescriptiveStatistics ds = new DescriptiveStatistics(); for (EccMeasurement m : series.getValues()) ds.addValue(Double.parseDouble(m.getValue())); result = new EccINTRATSummary(qosAttributesByID.get(attrID), ds.getMin(), ds.getMean(), ds.getMax()); } } return result; }
From source file:uk.ac.soton.itinnovation.ecc.service.utils.MetricCalculator.java
public static Properties calcINTRATSummary(MeasurementSet ms) throws Exception { Properties result = new Properties(); try {//from ww w .jav a 2s .c om if (validateINTRATMeasurementSet(ms)) { DescriptiveStatistics ds = new DescriptiveStatistics(); for (Measurement m : ms.getMeasurements()) ds.addValue(Double.parseDouble(m.getValue())); result.put("floor", ds.getMin()); result.put("mean", ds.getMean()); result.put("ceiling", ds.getMax()); } } catch (Exception ex) { throw ex; } return result; }