List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getMean
public double getMean()
From source file:uk.ac.cam.cl.dtg.teaching.programmingtest.java.FittedCurve.java
/** * Attempt to fit this curve.// w w w .j a v a 2s . c om */ 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/*from www . java2 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 w ww . j a va 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;// w w w .j av a 2s. 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 www . ja v a 2 s .c o m 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; }
From source file:util.Statistics.java
public Statistics(List<Integer> list) { scores = intsToDoubles(list);// w ww . java 2s .c om DescriptiveStatistics dStats = new DescriptiveStatistics(scores); summaryStatistics.put("min", dStats.getMin()); // Minimum summaryStatistics.put("q1", dStats.getPercentile(25)); // Lower Quartile (Q1) summaryStatistics.put("q2", dStats.getPercentile(50)); // Middle Quartile (Median - Q2) summaryStatistics.put("q3", dStats.getPercentile(75)); // High Quartile (Q3) summaryStatistics.put("max", dStats.getMax()); // Maxiumum summaryStatistics.put("mean", dStats.getMean()); // Mean summaryStatistics.put("sd", dStats.getStandardDeviation()); // Standard Deviation EmpiricalDistribution distribution = new EmpiricalDistribution(NUM_BINS); distribution.load(scores); List<SummaryStatistics> binStats = distribution.getBinStats(); double[] upperBounds = distribution.getUpperBounds(); Double lastUpperBound = upperBounds[0]; bins.add(new Pair<Pair<Double, Double>, Long>( new Pair<Double, Double>(summaryStatistics.get("min"), lastUpperBound), binStats.get(0).getN())); for (int i = 1; i < binStats.size(); i++) { bins.add(new Pair<Pair<Double, Double>, Long>(new Pair<Double, Double>(lastUpperBound, upperBounds[i]), binStats.get(i).getN())); lastUpperBound = upperBounds[i]; } if (list.size() > 5 && dStats.getStandardDeviation() > 0) // Only remove outliers if relatively normal { double mean = dStats.getMean(); double stDev = dStats.getStandardDeviation(); NormalDistribution normalDistribution = new NormalDistribution(mean, stDev); Iterator<Integer> listIterator = list.iterator(); double significanceLevel = .50 / list.size(); // Chauvenet's Criterion for Outliers while (listIterator.hasNext()) { int num = listIterator.next(); double pValue = normalDistribution.cumulativeProbability(num); if (pValue < significanceLevel) { outliers.add(num); listIterator.remove(); } } if (list.size() != dStats.getN()) // If and only if outliers have been removed { double[] significantData = intsToDoubles(list); dStats = new DescriptiveStatistics(significantData); summaryStatistics.put("min", dStats.getMin()); summaryStatistics.put("max", dStats.getMax()); summaryStatistics.put("mean", dStats.getMean()); summaryStatistics.put("sd", dStats.getStandardDeviation()); } } }
From source file:weka.classifiers.timeseries.eval.TSEvaluation.java
public double CalcOutlierTreshold(DescriptiveStatistics MAPEstats) throws Exception { double tresh = 0; mape = MAPEstats.getMean();//result[i]; std = MAPEstats.getStandardDeviation(); median = MAPEstats.getPercentile(50); upperPercentile = MAPEstats.getPercentile(85); if (readTreshsFromFile == false) { if (mape < 1) { if (std < 5) { tresh = upperPercentile + 3 * std + mape + median; ;//from w w w .jav a 2 s . com } else if ((std >= 5) && (std < 10)) { tresh = upperPercentile + 1.5 * std + mape + median; } else if ((std >= 10)) { tresh = upperPercentile + 1 * std + mape + median; } } else if ((mape >= 1) && (mape < 2)) { if (std < 5) { tresh = upperPercentile + 3 * std + mape + median; ; } else if ((std >= 5) && (std < 10)) { tresh = upperPercentile + 2.5 * std + mape + median; } else if ((std >= 10)) { tresh = upperPercentile + 1 * std + mape + median; } } else if ((mape >= 2) && (mape < 5)) { if (std < 5) { tresh = 2 * upperPercentile + std + mape + 1.25 * median; ; } else if ((std >= 5) && (std < 10)) { tresh = 1 * upperPercentile + std + mape + 2.75 * median; } else if ((std >= 10)) { tresh = 0.5 * upperPercentile + std + mape + median; } } else if ((mape >= 5) && (mape < 10)) { if (std < 5) { tresh = 1.5 * upperPercentile + std + mape + 1.25 * median; } else if ((std >= 5) && (std < 7.5)) { tresh = 0.85 * upperPercentile + std + mape + 2.5 * median; } else if ((std >= 7.5) && (std < 10)) { tresh = 0.85 * upperPercentile + std + mape + 2.5 * median; } else if ((std >= 10)) { tresh = 0.85 * upperPercentile + std + mape + 2 * median; } } else if ((mape >= 10) && (mape < 15)) { if (std < 5) { tresh = 0.75 * upperPercentile + std + mape + 2 * median; } else if ((std >= 5) && (std < 10)) { tresh = 0.5 * upperPercentile + std + mape + 1.65 * median; } else if ((std >= 10) && (std < 15)) { tresh = 2 * upperPercentile + std + mape + 2.5 * median; } else if ((std >= 15) && (std < 20)) { tresh = 2 * upperPercentile + std + mape + 2 * median; } else if ((std >= 20)) { tresh = 0.5 * upperPercentile + std + mape + 2 * median; } } else if ((mape >= 15) && (mape < 20)) { if (std < 10) { tresh = 1 * upperPercentile + std + mape + 2 * median; } else if ((std >= 10) && (std < 15)) { tresh = 1 * upperPercentile + std + mape + 3 * median; } else if ((std >= 15) && (std < 20)) { tresh = 0.5 * upperPercentile + std + mape + 2 * median; } else if ((std >= 20)) { tresh = 1 * upperPercentile + std + mape + 2 * median; } } else if ((mape >= 20) && (mape < 30)) { if (std < 10) { tresh = 1 * upperPercentile + std + mape + 2 * median; } else if ((std >= 10) && (std < 20)) { tresh = 1.25 * upperPercentile + std + mape + 2 * median; } else if ((std >= 20)) { tresh = 1 * upperPercentile + std + mape + 2 * median; } //if (tresh>(3.5*mape)) // tresh=3.5*mape; } else { if (std < 10) { tresh = 1 * upperPercentile + std + mape + median; } else if ((std >= 10) && (std < 20)) { tresh = 1 * upperPercentile + std + mape + median; } else if ((std >= 20)) { tresh = 0.5 * upperPercentile + std + mape + median; } //if (tresh>(3*mape)) // tresh=3*mape; } } else { tresh = treshold; } return tresh; /* if (upperPercentile>25) factor=3; else if ((upperPercentile>15)&&(upperPercentile>25)) factor=2; else{ factor=1.5; } if (mape<15){ if ((mape<4)&&(median<=2)&&(std>7)){ tresh= 4*factor*upperPercentile+2*std+mape+median;//+ } else if ((median<4.0)&&(std<=7)){ tresh= factor*upperPercentile+std+mape+median;//+ } else if ((mape<10)&&(std>12)){ tresh= factor*upperPercentile+mape+std; } else if ((mape<10)){ tresh= upperPercentile+std+2*median;//factor*upperPercentile;//+2*median } else { tresh =factor*upperPercentile+mape;//2.5*(std+mape);//+median if (std>=10) tresh=tresh+std; } if (tresh<1) tresh=2*tresh; } else{ tresh =upperPercentile+2*(mape+median)+(std/2); if (tresh>(3.5*mape)) tresh=3.5*mape; } */ // return tresh; }