List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getN
public long getN()
From source file:org.onosproject.store.cluster.impl.PhiAccrualFailureDetector.java
/** * Compute phi for the specified node id. * @param nodeId node id//from ww w.j a va 2s . c om * @return phi value */ public double phi(NodeId nodeId) { checkNotNull(nodeId, "NodeId must not be null"); if (!states.containsKey(nodeId)) { return BOOTSTRAP_PHI_VALUE; } History nodeState = states.get(nodeId); synchronized (nodeState) { long latestHeartbeat = nodeState.latestHeartbeatTime(); DescriptiveStatistics samples = nodeState.samples(); if (latestHeartbeat == -1 || samples.getN() < MIN_SAMPLES) { return 0.0; } return computePhi(samples, latestHeartbeat, System.currentTimeMillis()); } }
From source file:org.onosproject.store.cluster.impl.PhiAccrualFailureDetector.java
private double computePhi(DescriptiveStatistics samples, long tLast, long tNow) { long size = samples.getN(); long t = tNow - tLast; return (size > 0) ? PHI_FACTOR * t / samples.getMean() : BOOTSTRAP_PHI_VALUE; }
From source file:org.wildfly.swarm.proc.CSVCollector.java
public void onFinish(String id) { List<Object> record = new ArrayList<>(); record.add(id);// w w w. j a v a2 s .c o m record.add(Paths.get(id).getFileName()); for (Measure m : Measure.values()) { if (!results.containsKey(m)) { throw new RuntimeException("Measurement is missing " + m); } DescriptiveStatistics stats = results.get(m); record.add(stats.getN()); record.add(stats.getMin()); record.add(stats.getMax()); record.add(stats.getMean()); record.add(stats.getStandardDeviation()); record.add(stats.getPercentile(50)); record.add(stats.getPercentile(75)); } try { csvOutput.printRecord(record); csvOutput.flush(); } catch (IOException e) { throw new RuntimeException("Failed to write data", e); } }
From source file:org.wildfly.swarm.proc.SystemOutCollector.java
public void onFinish(String id) { System.out.println("Results for " + id); for (Measure m : results.keySet()) { DescriptiveStatistics stats = results.get(m); System.out.println(m.name() + " Samples: " + stats.getN()); System.out.println(m.name() + " min: " + stats.getMin()); System.out.println(m.name() + " max: " + stats.getMax()); System.out.println(m.name() + " 75p: " + stats.getPercentile(75)); }// ww w . j a va 2 s . co m }
From source file:org.wso2.carbon.ml.database.internal.MLDatabaseService.java
/** * Create the JSON string with summary statistics for a column. * * @param type Data-type of the column/*from w w w .j a v a 2 s.c om*/ * @param graphFrequencies Bin frequencies of the column * @param missing Number of missing values in the column * @param unique Number of unique values in the column * @param descriptiveStats DescriptiveStats object of the column * @return JSON representation of the summary statistics of the column */ private JSONArray createJson(String type, SortedMap<?, Integer> graphFrequencies, int missing, int unique, DescriptiveStatistics descriptiveStats) throws JSONException { JSONObject json = new JSONObject(); JSONArray freqs = new JSONArray(); Object[] categoryNames = graphFrequencies.keySet().toArray(); // Create an array with intervals/categories and their frequencies. for (int i = 0; i < graphFrequencies.size(); i++) { JSONArray temp = new JSONArray(); temp.put(categoryNames[i].toString()); temp.put(graphFrequencies.get(categoryNames[i])); freqs.put(temp); } // Put the statistics to a json object json.put("unique", unique); json.put("missing", missing); DecimalFormat decimalFormat = new DecimalFormat("#.###"); if (descriptiveStats.getN() != 0) { json.put("mean", decimalFormat.format(descriptiveStats.getMean())); json.put("min", decimalFormat.format(descriptiveStats.getMin())); json.put("max", decimalFormat.format(descriptiveStats.getMax())); json.put("median", decimalFormat.format(descriptiveStats.getPercentile(50))); json.put("std", decimalFormat.format(descriptiveStats.getStandardDeviation())); if (type.equalsIgnoreCase(FeatureType.NUMERICAL)) { json.put("skewness", decimalFormat.format(descriptiveStats.getSkewness())); } } json.put("values", freqs); json.put("bar", true); json.put("key", "Frequency"); JSONArray summaryStatArray = new JSONArray(); summaryStatArray.put(json); return summaryStatArray; }
From source file:org.wso2.carbon.ml.dataset.internal.DatabaseHandler.java
/** * Create the JSON string with summary statistics for a column. * * @param type Data-type of the column * @param graphFrequencies Bin frequencies of the column * @param missing Number of missing values in the column * @param unique Number of unique values in the column * @param descriptiveStats DescriptiveStats object of the column * @return JSON representation of the summary statistics of the column *//*from w w w . j av a 2 s . c om*/ private JSONArray createJson(String type, SortedMap<?, Integer> graphFrequencies, int missing, int unique, DescriptiveStatistics descriptiveStats) { JSONObject json = new JSONObject(); JSONArray freqs = new JSONArray(); Object[] categoryNames = graphFrequencies.keySet().toArray(); // Create an array with intervals/categories and their frequencies. for (int i = 0; i < graphFrequencies.size(); i++) { JSONArray temp = new JSONArray(); temp.put(categoryNames[i].toString()); temp.put(graphFrequencies.get(categoryNames[i])); freqs.put(temp); } // Put the statistics to a json object json.put("unique", unique); json.put("missing", missing); DecimalFormat decimalFormat = new DecimalFormat("#.###"); if (descriptiveStats.getN() != 0) { json.put("mean", decimalFormat.format(descriptiveStats.getMean())); json.put("median", decimalFormat.format(descriptiveStats.getPercentile(50))); json.put("std", decimalFormat.format(descriptiveStats.getStandardDeviation())); if (type.equalsIgnoreCase(FeatureType.NUMERICAL)) { json.put("skewness", decimalFormat.format(descriptiveStats.getSkewness())); } } json.put("values", freqs); json.put("bar", true); json.put("key", "Frequency"); JSONArray summaryStatArray = new JSONArray(); summaryStatArray.put(json); return summaryStatArray; }
From source file:performancestatisticsasset.DistributionSet.java
public void setDistributionSet(String targetGroup, String targetTask, String targetMeasure, RecordList dataSet) {//from w ww . j a v a2 s .c om //Determine the number of trials selected by group and by task int trials = 0; int len = dataSet.records.size(); for (int i = 0; i < len; i++) { if (dataSet.records.get(i).getTrialNumber() > trials) trials = dataSet.records.get(i).getTrialNumber(); } Distribution tempDist; DescriptiveStatistics tempStat; //For each trial of the set do for (int i = 0; i < trials; i++) { tempDist = new Distribution(); tempStat = new DescriptiveStatistics(); //Select data for (int j = 0; j < len; j++) { //If the current record is of the correct trial if ((dataSet.records.get(j).getTrialNumber() == i + 1) && (targetGroup.equals(dataSet.records.get(j).getGroupID())) && (targetTask.equals(dataSet.records.get(j).getTaskID()))) { //Fill distribution switch (targetMeasure) { case "time": tempStat.addValue(dataSet.records.get(j).getTimeToComplete()); break; case "perf": tempStat.addValue(dataSet.records.get(j).getPerformance()); break; } } } //Transfer the computed statistics to tempDist tempDist.max = tempStat.getMax(); tempDist.min = tempStat.getMin(); tempDist.sum = tempStat.getSum(); tempDist.variance = tempStat.getVariance(); tempDist.mean = tempStat.getMean(); tempDist.stdDev = tempStat.getStandardDeviation(); tempDist.skewness = tempStat.getSkewness(); tempDist.kurtosis = tempStat.getKurtosis(); tempDist.n = tempStat.getN(); //Add tempDist to distributionSet distributionSet.add(tempDist); } }
From source file:performancestatisticsasset.DistributionSet.java
public void setDistributionSet(String targetTask, String targetMeasure, RecordList dataSet) { //Determine the number of trials selected by task int trials = 0; int len = dataSet.records.size(); for (int i = 0; i < len; i++) { if (dataSet.records.get(i).getTrialNumber() > trials) trials = dataSet.records.get(i).getTrialNumber(); }// ww w . j a v a 2 s . co m Distribution tempDist; DescriptiveStatistics tempStat; //For each trial of the set do for (int i = 0; i < trials; i++) { tempDist = new Distribution(); tempStat = new DescriptiveStatistics(); //Select data for (int j = 0; j < len; j++) { //If the current record is of the correct trial if ((dataSet.records.get(j).getTrialNumber() == i + 1) && (targetTask.equals(dataSet.records.get(j).getTaskID()))) { //Fill distribution switch (targetMeasure) { case "time": tempStat.addValue(dataSet.records.get(j).getTimeToComplete()); break; case "perf": tempStat.addValue(dataSet.records.get(j).getPerformance()); break; } } } //Transfer the computed statistics to tempDist tempDist.max = tempStat.getMax(); tempDist.min = tempStat.getMin(); tempDist.sum = tempStat.getSum(); tempDist.variance = tempStat.getVariance(); tempDist.mean = tempStat.getMean(); tempDist.stdDev = tempStat.getStandardDeviation(); tempDist.skewness = tempStat.getSkewness(); tempDist.kurtosis = tempStat.getKurtosis(); tempDist.n = tempStat.getN(); //Add tempDist to distributionSet distributionSet.add(tempDist); } }
From source file:sandbox.sfwatergit.peerinfluence.io.TXTWriter.java
public static void writeStatistics(TDoubleObjectHashMap<DescriptiveStatistics> statsMap, String xLab, String file) throws IOException { double[] keys = statsMap.keys(); Arrays.sort(keys);/* w w w.j a v a 2 s .c o m*/ BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(xLab); writer.write(TAB); writer.write("mean"); writer.write(TAB); writer.write("median"); writer.write(TAB); writer.write("min"); writer.write(TAB); writer.write("max"); writer.write(TAB); writer.write("n"); writer.newLine(); for (double key : keys) { DescriptiveStatistics stats = statsMap.get(key); writer.write(String.valueOf(key)); writer.write(TAB); writer.write(String.valueOf(stats.getMean())); writer.write(TAB); writer.write(String.valueOf(stats.getPercentile(50))); writer.write(TAB); writer.write(String.valueOf(stats.getMin())); writer.write(TAB); writer.write(String.valueOf(stats.getMax())); writer.write(TAB); writer.write(String.valueOf(stats.getN())); writer.newLine(); } writer.close(); }
From source file:tools.descartes.bungee.viewer.RunResultView.java
private void update() { if (runResult != null) { sanityCheckValue.setSelection(runResult.passedSanityCheck()); scheduleCheckValue.setSelection(runResult.passedScheduleCheck()); completedCheckValue.setSelection(runResult.isRunCompleted()); successCheckValue.setSelection(runResult.isRunSuccessful()); DescriptiveStatistics timingStats = runResult.getTimingStats(); if (timingStats.getN() > 0) { timingMeanValue.setText(String.format("%.3f", timingStats.getMean())); timingStdValue.setText(String.format("%.3f", timingStats.getStandardDeviation())); } else {/*from w ww . j a v a 2 s . co m*/ timingMeanValue.setText("-"); timingStdValue.setText("-"); } DescriptiveStatistics responseStats = runResult.getResponseTimeStats(); if (responseStats.getN() > 0) { responseTimeMeanValue.setText(String.format("%.3f", responseStats.getMean())); responseTimeStdValue.setText(String.format("%.3f", responseStats.getStandardDeviation())); } else { responseTimeMeanValue.setText("-"); responseTimeStdValue.setText("-"); } } }