List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics getMean
public double getMean()
From source file:org.recommender101.recommender.extensions.mahout.impl.AbstractFactorizer.java
protected double getAveragePreference() throws TasteException { SummaryStatistics stat = new SummaryStatistics(); for (Rating rating : dataModel.getRatings()) { stat.addValue(rating.rating);/*from w w w . j a va2s . c o m*/ } return stat.getMean(); }
From source file:org.spotter.ext.detection.highmessaging.analyze.Analyzer.java
protected double mean(List<Double> values) { SummaryStatistics stats = new SummaryStatistics(); for (double val : values) { stats.addValue(val); }/* w ww .ja va 2s . com*/ return stats.getMean(); }
From source file:org.spotter.ext.detection.highmessaging.analyze.LinearAnalyzer.java
@Override public AnalyzeResult analyze() { // Values smoothed List<Double> valuesSmoothed = smooth(yValues, smoothingWide); // Values smoothed and normalized relative to the first List<Double> valuesSmoothedNormalized = normalize(valuesSmoothed, valuesSmoothed.get(0)); // Check if linear increasing List<Double> slopes = new ArrayList<Double>(); SummaryStatistics statsSlopesSmoothedNormalized = new SummaryStatistics(); for (int i = 0; i < xValues.size(); i++) { double slope = 1; if (i != 0) { slope = (valuesSmoothedNormalized.get(i) - valuesSmoothedNormalized.get(i - 1)) / (xValues.get(i) - xValues.get(i - 1)); }/*from w ww .j ava2s . c om*/ statsSlopesSmoothedNormalized.addValue(slope); slopes.add(slope); // System.out.println((slope + "").replaceAll("\\.", ",")); } List<Double> slopesSmoothed = smooth(slopes, 2); int outlierCount = 0; double lowerBound = statsSlopesSmoothedNormalized.getMean() - statsSlopesSmoothedNormalized.getStandardDeviation(); lowerBound = 0.5; for (double val : slopesSmoothed) { // System.out.println((val + "").replaceAll("\\.", ",")); if (lowerBound > val) { outlierCount++; } } double pctOutlier = 1D / slopes.size() * outlierCount; // System.out.println(String.format("> Outlier: %d Pct Outlier: %.2f", outlierCount, pctOutlier)); if (pctOutlier > 1D - pctThreshold) { // Too much outside return AnalyzeResult.NEGATIVE; } else { // Alles ok return AnalyzeResult.POSITIVE; } }
From source file:playground.acmarmol.matsim2030.microcensus2010.MZPopulationUtils.java
public static void analyzeActivityTypesAndLengths(Population population) throws ExecutionException { LoadingCache<String, SummaryStatistics> activityDuration = CacheBuilder.newBuilder() .build(CacheLoader.from(new Supplier<SummaryStatistics>() { @Override/*from ww w.ja v a 2 s .co m*/ public SummaryStatistics get() { return new SummaryStatistics(); } })); for (Person p : population.getPersons().values()) { if (p.getPlans().size() == 0) continue; Plan plan = p.getPlans().get(0); List<PlanElement> planElements = plan.getPlanElements(); for (PlanElement pe : planElements) { if (!(pe instanceof Activity)) continue; Activity activity = (Activity) pe; double startTime = activity.getStartTime(); double endTime = activity.getEndTime(); SummaryStatistics typeStats = activityDuration.get(activity.getType()); if (endTime != Time.UNDEFINED_TIME) { if (startTime == Time.UNDEFINED_TIME) startTime = 0; typeStats.addValue(endTime - startTime); } } } ConcurrentMap<String, SummaryStatistics> activityDurationMap = activityDuration.asMap(); { int i = 0; final StringBuffer s = new StringBuffer(); for (final String actType : activityDurationMap.keySet()) { final SummaryStatistics stats = activityDurationMap.get(actType); s.append(String.format("<param name=\"activityType_%d\" value=\"%s\" />\n", i, actType)); s.append(String.format("<param name=\"activityPriority_%d\" value=\"1\" />\n", i)); s.append(String.format("<param name=\"activityTypicalDuration_%d\" value=\"%s\" />\n", i, Time.writeTime(stats.getMean()))); s.append("\n"); i++; } log.info("All activities:\n" + s.toString()); } }
From source file:tech.tablesaw.columns.numbers.Stats.java
private static Stats getStats(NumericColumn<?> values, SummaryStatistics summaryStatistics) { Stats stats = new Stats("Column: " + values.name()); stats.min = summaryStatistics.getMin(); stats.max = summaryStatistics.getMax(); stats.n = summaryStatistics.getN();/*ww w.j a va 2 s.com*/ stats.sum = summaryStatistics.getSum(); stats.variance = summaryStatistics.getVariance(); stats.populationVariance = summaryStatistics.getPopulationVariance(); stats.quadraticMean = summaryStatistics.getQuadraticMean(); stats.geometricMean = summaryStatistics.getGeometricMean(); stats.mean = summaryStatistics.getMean(); stats.standardDeviation = summaryStatistics.getStandardDeviation(); stats.sumOfLogs = summaryStatistics.getSumOfLogs(); stats.sumOfSquares = summaryStatistics.getSumsq(); stats.secondMoment = summaryStatistics.getSecondMoment(); return stats; }
From source file:tools.descartes.bungee.evaluation.ScalabilityReproducibilityEvaluation.java
@Override public void run() { System.out.println("Analysis started..."); List<Double> firstStepResults = new LinkedList<Double>(); Host host = new Host(cloudSettings.getIp(), cloudSettings.getPrivatePort()); analysis.setMaxResources(cloudSettings.getMaxInstances()); int runs = 0; boolean finished = false; while (runs < minRuns || (runs < maxRuns && !finished)) { runs++;/*from w w w. j av a2s .c o m*/ System.out.println("run number: " + runs); IntensityDemandMapping mapping = analysis.analyzeSystem(host, request, slo); double result = mapping.getMaxIntensity(1); firstStepResults.add(result); writeAnalysisResultsToFile(firstStepResults); if (runs > 1) { SummaryStatistics summaryStats = createSummaryStatistics(firstStepResults); double wantedLower = (1 - diffPercent) * summaryStats.getMean(); double wantedUpper = (1 + diffPercent) * summaryStats.getMean(); double width = getConfidenceIntervalWidth(summaryStats, confidence); double lowerConfidence = summaryStats.getMean() - width; double upperConfidence = summaryStats.getMean() + width; finished = lowerConfidence > wantedLower; printStatistics(summaryStats, lowerConfidence, upperConfidence, wantedLower, wantedUpper, finished); writeEvaluationResultsToFile(firstStepResults, summaryStats, lowerConfidence, upperConfidence, wantedLower, wantedUpper, finished); } } }
From source file:tools.descartes.bungee.evaluation.ScalabilityReproducibilityEvaluation.java
private void printStatistics(SummaryStatistics summaryStats, double lowerConfidence, double upperConfidence, double wantedLower, double wantedUpper, boolean finished) { System.out.println("total runs: " + summaryStats.getN()); System.out.println("mean: " + summaryStats.getMean()); System.out.println("stdDev: " + summaryStats.getStandardDeviation()); System.out.println("confidence interval [" + lowerConfidence + "," + upperConfidence + "]"); System.out.println("wanted interval [" + wantedLower + "," + wantedUpper + "]"); System.out.println("success: " + finished); }
From source file:tools.descartes.bungee.evaluation.ScalabilityReproducibilityEvaluation.java
private void writeEvaluationResultsToFile(List<Double> firstStepResults, SummaryStatistics summaryStats, double lowerConfidence, double upperConfidence, double wantedLower, double wantedUpper, boolean finished) { String resultsString = analysisResultCSVString(firstStepResults); PrintWriter writer;// w w w. j a va 2 s .c o m try { writer = new PrintWriter( new File(measurementFolder, cloudSettings.getOffering() + "-evaluationResults.csv"), FileUtility.ENOCDING); writer.println(resultsString); writer.println("runs: " + FileUtility.CSV_SPLIT_BY + summaryStats.getN()); writer.println("mean" + FileUtility.CSV_SPLIT_BY + summaryStats.getMean()); writer.println("stdDev" + FileUtility.CSV_SPLIT_BY + summaryStats.getStandardDeviation()); writer.println(Double.toString(diffPercent * 100) + "%-interval" + FileUtility.CSV_SPLIT_BY + Double.toString(wantedLower) + FileUtility.CSV_SPLIT_BY + Double.toString(wantedUpper)); writer.println(Double.toString(confidence * 100) + "% confidence interval" + FileUtility.CSV_SPLIT_BY + Double.toString(lowerConfidence) + FileUtility.CSV_SPLIT_BY + Double.toString(upperConfidence)); writer.println("confidence interval small enough" + FileUtility.CSV_SPLIT_BY + finished); writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:uk.ac.diamond.scisoft.ncd.calibration.NCDAbsoluteCalibration.java
public void calibrate() { qMin = Math.max(absQ.min().doubleValue(), dataQ.min().doubleValue()); qMax = Math.min(absQ.max().doubleValue(), dataQ.max().doubleValue()); if (!(qMin < qMax)) { throw new IllegalArgumentException( "No calibration data found for the selected scattering vector range"); }/* ww w .j a va 2s .c om*/ int dataQStart = Math.min(dataQ.getSize() - 1, DatasetUtils.findIndexGreaterThanOrEqualTo(dataQ, qMin)); int dataQStop = Math.min(dataQ.getSize() - 1, DatasetUtils.findIndexGreaterThanOrEqualTo(dataQ, qMax)); SummaryStatistics stats = new SummaryStatistics(); for (int i = dataQStart; i <= dataQStop; i++) { double qval = dataQ.getDouble(i); stats.addValue(absInterpolate.value(qval) / dataI.getDouble(i)); } absScale = stats.getMean(); absScaleStdDev = stats.getStandardDeviation(); String msg = StringUtils.join(new String[] { "scale", Double.toString(absScale) }, " : "); System.out.println(msg); System.out.println("NCD Absolute Instensity Scaler"); System.out.println(Double.toString(absScale)); System.out.println("standard deviation:" + Double.toString(absScaleStdDev)); calibratedData(dataI); }
From source file:wsattacker.plugin.dos.dosExtension.mvc.model.AttackModel.java
/** * Prints the result of the network stability Test *///from w w w.j a v a 2s. c om public void generateNetworktestResult() { SummaryStatistics statistics = createNetworkStatistics(); double standarddeviationResult = statistics.getStandardDeviation(); double meanResult = statistics.getMean(); // get Coefficient of variation this.networkTestResult = (standarddeviationResult / meanResult); this.networkTestResult = Math.round(networkTestResult * 100.0) / 100.0; System.out.println("--------------------Ergebnis NETWORK:" + standarddeviationResult + " - " + meanResult + " - " + (standarddeviationResult / meanResult)); // get Result String if (this.networkTestResult < 0.5) { this.networkTestResultString = "stable"; } else if (this.networkTestResult >= 0.5 && this.networkTestResult < 2.0) { this.networkTestResultString = "noisy"; } else { this.networkTestResultString = "unstable"; } this.networkTestFinished = true; fireModelChanged(); }