List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
From source file:net.adamjak.thomas.graph.application.commons.StatisticsUtils.java
public static DescriptiveStatistics statisticsWithoutExtremes(DescriptiveStatistics inputStatistics, GrubbsLevel grubbsLevel) throws IllegalArgumentException { if (inputStatistics == null || grubbsLevel == null) throw new IllegalArgumentException("Params inputStatistics and grubbsLevel can not be null."); int countInput = inputStatistics.getValues().length; Double avgInput = inputStatistics.getMean(); Double stdInput = inputStatistics.getStandardDeviation(); Double s = stdInput * Math.sqrt((countInput - 1.0) / countInput); Double criticalValue = grubbsLevel.getCriticalValue(countInput); DescriptiveStatistics outputStatistic = new DescriptiveStatistics(); for (double inpVal : inputStatistics.getValues()) { double test = Math.abs(inpVal - avgInput) / s; if (test <= criticalValue) { outputStatistic.addValue(inpVal); }//from w ww .j av a 2 s. c o m } return outputStatistic; }
From source file:nars.truth.Truth.java
/** provides a statistics summary (mean, min, max, variance, etc..) of a particular TruthValue component across a given list of Truthables (sentences, TruthValue's, etc..). null values in the iteration are ignored */ @NotNull//from w w w . j a v a 2 s . c om static DescriptiveStatistics statistics(@NotNull Iterable<? extends Truthed> t, @NotNull TruthComponent component) { DescriptiveStatistics d = new DescriptiveStatistics(); for (Truthed x : t) { Truth v = x.truth(); if (v != null) d.addValue(v.getComponent(component)); } return d; }
From source file:com.caseystella.analytics.distribution.Distribution.java
public static double getMadScore(Iterable<Double> vals, Double val) { DescriptiveStatistics stats = new DescriptiveStatistics(); DescriptiveStatistics medianStats = new DescriptiveStatistics(); for (Double v : vals) { stats.addValue(v); }// ww w. j a v a2s. c o m double median = stats.getPercentile(50); for (Double v : vals) { medianStats.addValue(Math.abs(v - median)); } double mad = medianStats.getPercentile(50); return Math.abs(0.6745 * (val - median) / mad); }
From source file:com.caseystella.analytics.outlier.streaming.mad.ConfusionMatrix.java
public static Map<ConfusionEntry, Long> getConfusionMatrix(Set<Long> expectedOutliers, Set<Long> computedOutliers, long numObservations, long meanDiffBetweenTs, int timeBounds, Map<Long, Outlier> outlierMap, DescriptiveStatistics globalExpectedOutlierScoreStats) { Map<ConfusionEntry, Long> ret = new HashMap<>(); for (ResultType r : ResultType.values()) { for (ResultType s : ResultType.values()) { ret.put(new ConfusionEntry(r, s), 0L); }//from w ww . jav a 2 s .com } int unionSize = 0; DescriptiveStatistics expectedOutlierScoreStats = new DescriptiveStatistics(); for (Long expectedOutlier : expectedOutliers) { Outlier o = outlierMap.get(expectedOutlier); if (o.getScore() != null) { expectedOutlierScoreStats.addValue(o.getScore()); globalExpectedOutlierScoreStats.addValue(o.getScore()); } if (setContains(computedOutliers, expectedOutlier, meanDiffBetweenTs, timeBounds)) { ConfusionEntry entry = new ConfusionEntry(ResultType.OUTLIER, ResultType.OUTLIER); ConfusionEntry.increment(entry, ret); unionSize++; } else { ConfusionEntry entry = new ConfusionEntry(ResultType.NON_OUTLIER, ResultType.OUTLIER); long closest = closest(expectedOutlier, computedOutliers); long delta = Math.abs(expectedOutlier - closest); if (closest != Long.MAX_VALUE) { System.out.println("Missed an outlier (" + expectedOutlier + ") wasn't in computed outliers (" + o + "), closest point is " + closest + " which is " + timeConversion(delta) + "away. - E[delta t] " + timeConversion(meanDiffBetweenTs) + ""); } else { System.out.println("Missed an outlier (" + expectedOutlier + ") wasn't in computed outliers (" + o + "), which is empty. - E[delta t] " + timeConversion(meanDiffBetweenTs) + ""); } ConfusionEntry.increment(entry, ret); unionSize++; } } printStats("Expected Outlier Score Stats", expectedOutlierScoreStats); DescriptiveStatistics computedOutlierScoreStats = new DescriptiveStatistics(); for (Long computedOutlier : computedOutliers) { if (!setContains(expectedOutliers, computedOutlier, meanDiffBetweenTs, timeBounds)) { Outlier o = outlierMap.get(computedOutlier); if (o.getScore() != null) { computedOutlierScoreStats.addValue(o.getScore()); } ConfusionEntry entry = new ConfusionEntry(ResultType.OUTLIER, ResultType.NON_OUTLIER); ConfusionEntry.increment(entry, ret); unionSize++; } } printStats("Computed Outlier Scores", computedOutlierScoreStats); ret.put(new ConfusionEntry(ResultType.NON_OUTLIER, ResultType.NON_OUTLIER), numObservations - unionSize); Assert.assertEquals(numObservations, getTotalNum(ret)); return ret; }
From source file:main.java.metric.Metric.java
public static double getMeanServerData(Cluster cluster) { DescriptiveStatistics server_data = new DescriptiveStatistics(); for (Server server : cluster.getServers()) server_data.addValue(server.getServer_total_data()); return server_data.getMean(); }
From source file:main.java.metric.Metric.java
public static double getCVServerData(Cluster cluster) { DescriptiveStatistics server_data = new DescriptiveStatistics(); for (Server server : cluster.getServers()) server_data.addValue(server.getServer_total_data()); double c_v = server_data.getStandardDeviation() / server_data.getMean(); return c_v;// w w w. j av a 2 s . co m }
From source file:main.java.metric.Metric.java
public static double getMeanServerData(Cluster cluster, Transaction tr) { DescriptiveStatistics server_data = new DescriptiveStatistics(); for (Entry<Integer, HashSet<Integer>> entry : tr.getTr_serverSet().entrySet()) { server_data.addValue(entry.getValue().size()); }/*from ww w. j a v a2s . c o m*/ return server_data.getMean(); }
From source file:main.java.metric.Metric.java
public static double getCVServerData(Cluster cluster, Transaction tr) { DescriptiveStatistics server_data = new DescriptiveStatistics(); for (Entry<Integer, HashSet<Integer>> entry : tr.getTr_serverSet().entrySet()) { server_data.addValue(entry.getValue().size()); }// ww w . j a va 2s .c om double c_v = server_data.getStandardDeviation() / server_data.getMean(); return c_v; }
From source file:main.java.repartition.RBPTA.java
private static double getLbGain(Cluster cluster, SwappingCandidate sc) { DescriptiveStatistics sc_partition_data = new DescriptiveStatistics(); for (Partition p : cluster.getPartitions()) if (sc.p_pair.x == p.getPartition_id() || sc.p_pair.y == p.getPartition_id()) sc_partition_data.addValue(p.getPartition_dataSet().size()); return sc_partition_data.getVariance(); }
From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java
private static void countRecvCallSites(Collection<ICoReTypeName> types, ProjectUsageStore store) throws IOException { DescriptiveStatistics statistics = new DescriptiveStatistics(); for (ICoReTypeName type : types) { if (store.getProjects(type).size() < 10) { continue; }/* w ww . j a va2s . c om*/ int numDistinctRecvCallsite = store.load(type, new PointsToUsageFilter()).stream() .flatMap(usage -> usage.getReceiverCallsites().stream()).map(CallSite::getMethod) .collect(Collectors.toSet()).size(); if (numDistinctRecvCallsite > 0) { statistics.addValue(numDistinctRecvCallsite); System.out.printf(Locale.US, "%s: %d\n", CoReNames.vm2srcQualifiedType(type), numDistinctRecvCallsite); } } System.out.println(); System.out.printf(Locale.US, "mean: %.3f, stddev: %.3f, median: %.1f\n", statistics.getMean(), statistics.getStandardDeviation(), statistics.getPercentile(50)); }