org.apache.commons.math3.stat.descriptive.DescriptiveStatistics Java Examples
The following examples show how to use
org.apache.commons.math3.stat.descriptive.DescriptiveStatistics.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PhiAccrualFailureDetector.java From onos with Apache License 2.0 | 6 votes |
/** * Compute phi for the specified node id. * @param nodeId node id * @return phi value */ public double phi(NodeId nodeId) { checkNotNull(nodeId, "NodeId must not be null"); if (!states.containsKey(nodeId)) { return bootstrapPhiValue; } History nodeState = states.get(nodeId); synchronized (nodeState) { long latestHeartbeat = nodeState.latestHeartbeatTime(); DescriptiveStatistics samples = nodeState.samples(); if (latestHeartbeat == -1 || samples.getN() < minSamples) { return 0.0; } return computePhi(samples, latestHeartbeat, System.currentTimeMillis()); } }
Example #2
Source File: ListUnivariateImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ @Override public double[] getValues() { int length = list.size(); // If the window size is not INFINITE_WINDOW AND // the current list is larger that the window size, we need to // take into account only the last n elements of the list // as definied by windowSize final int wSize = getWindowSize(); if (wSize != DescriptiveStatistics.INFINITE_WINDOW && wSize < list.size()) { length = list.size() - FastMath.max(0, list.size() - wSize); } // Create an array to hold all values double[] copiedArray = new double[length]; for (int i = 0; i < copiedArray.length; i++) { copiedArray[i] = getElement(i); } return copiedArray; }
Example #3
Source File: ListUnivariateImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ @Override public double[] getValues() { int length = list.size(); // If the window size is not INFINITE_WINDOW AND // the current list is larger that the window size, we need to // take into account only the last n elements of the list // as definied by windowSize final int wSize = getWindowSize(); if (wSize != DescriptiveStatistics.INFINITE_WINDOW && wSize < list.size()) { length = list.size() - FastMath.max(0, list.size() - wSize); } // Create an array to hold all values double[] copiedArray = new double[length]; for (int i = 0; i < copiedArray.length; i++) { copiedArray[i] = getElement(i); } return copiedArray; }
Example #4
Source File: AngrySquiggleHighlighter.java From MSPaintIDE with MIT License | 6 votes |
private int getBaseline(List<ImageLetter> imageLetters, int fontSize) throws IOException { var centerPopulator = this.startupLogic.getCenterPopulator(); centerPopulator.generateCenters(fontSize); var descriptiveStatistics = new DescriptiveStatistics(); var sizes = imageLetters .stream() .map(imageLetter -> (double) imageLetter.getHeight() + imageLetter.getY()) .peek(descriptiveStatistics::addValue) .collect(Collectors.toCollection(DoubleArrayList::new)); var lowerBound = descriptiveStatistics.getPercentile(40); var upperBound = descriptiveStatistics.getPercentile(60); sizes.removeIf((Predicate<Double>) value -> value > upperBound || value < lowerBound); return (int) sizes.stream().mapToDouble(Double::valueOf).average().orElse(0); }
Example #5
Source File: ExecuteOutlierErrors.java From BART with MIT License | 6 votes |
private String printStat(DescriptiveStatistics stats) { double mean = stats.getMean(); double std = stats.getStandardDeviation(); double median = stats.getPercentile(50); double q1 = stats.getPercentile(25); double q3 = stats.getPercentile(75); double iqr = q3 - q1; double trimmedMean = (q1 + q3 + 2 * median) / 4; double skewness = stats.getSkewness(); StringBuilder sb = new StringBuilder(); sb.append(" *** Distribution Analysis ***").append("\n") .append("\tMean= ").append(mean).append("\n") .append("\tStd= ").append(std).append("\n") .append("\tMedian= ").append(median).append("\n") .append("\tQ1= ").append(q1).append("\tQ3=").append(q3).append("\tIQR=").append(iqr).append("\n") .append("\tTrimmed Mean= ").append(trimmedMean).append("\n") .append("\tSkewness= ").append(skewness).append("\n"); return sb.toString(); }
Example #6
Source File: OWLSimReferenceBasedStatistics.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected DescriptiveStatistics computeDescriptiveStatistics(Set<OWLClass> attributes) throws UnknownOWLClassException { DescriptiveStatistics statsPerAttSet = new DescriptiveStatistics(); OWLDataFactory g = sourceOntology.getOWLOntologyManager().getOWLDataFactory(); for (OWLClass c : attributes) { Double ic; try { ic = owlsim.getInformationContentForAttribute(c); if (ic == null) { if (g.getOWLClass(c.getIRI()) != null) { ic = owlsim.getSummaryStatistics().max.getMax(); } else { throw new UnknownOWLClassException(c); } } if (ic.isInfinite() || ic.isNaN()) { ic = owlsim.getSummaryStatistics().max.getMax(); } statsPerAttSet.addValue(ic); } catch (UnknownOWLClassException e) { LOG.info("Unknown class "+c.toStringID()+" submitted for summary stats. Removed from calculation."); continue; } } return statsPerAttSet; }
Example #7
Source File: StatUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Run with 77 random values, assuming that the outcome has a mean of 0 and a standard deviation of 1 with a * precision of 1E-10. */ @Test public void testNormalize2() { // create an sample with 77 values int length = 77; double sample[] = new double[length]; for (int i = 0; i < length; i++) { sample[i] = Math.random(); } // normalize this sample double standardizedSample[] = StatUtils.normalize(sample); DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < length; i++) { stats.addValue(standardizedSample[i]); } // the calculations do have a limited precision double distance = 1E-10; // check the mean an standard deviation Assert.assertEquals(0.0, stats.getMean(), distance); Assert.assertEquals(1.0, stats.getStandardDeviation(), distance); }
Example #8
Source File: Batch.java From uima-uimafit with Apache License 2.0 | 6 votes |
@Override public String toString() { DescriptiveStatistics stats = new DescriptiveStatistics(); StringBuilder sb = new StringBuilder(); sb.append("[").append(String.format("%7d/%7d", magnitude, measurements.size())).append(": "); int failures = 0; for (Measurement m : measurements) { if (m.failed()) { failures++; } else { stats.addValue(m.getDuration()); } } sb.append(String.format("min: %4.0f ", stats.getMin())); sb.append(String.format("max: %4.0f ", stats.getMax())); sb.append(String.format("median: %4.0f ", stats.getPercentile(50))); sb.append(String.format("fail: %4d ", failures)); sb.append("]"); return sb.toString(); }
Example #9
Source File: AbstractTestQueries.java From presto with Apache License 2.0 | 6 votes |
@Test public void testTableSampleBernoulli() { DescriptiveStatistics stats = new DescriptiveStatistics(); int total = computeExpected("SELECT orderkey FROM orders", ImmutableList.of(BIGINT)).getMaterializedRows().size(); for (int i = 0; i < 100; i++) { List<MaterializedRow> values = computeActual("SELECT orderkey FROM orders TABLESAMPLE BERNOULLI (50)").getMaterializedRows(); assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows"); stats.addValue(values.size() * 1.0 / total); } double mean = stats.getGeometricMean(); assertTrue(mean > 0.45 && mean < 0.55, format("Expected mean sampling rate to be ~0.5, but was %s", mean)); }
Example #10
Source File: OCRManager.java From MSPaintIDE with MIT License | 6 votes |
public double getFontSize(ScannedImage scannedImage) { var descriptiveStatistics = new DescriptiveStatistics(); var sizes = scannedImage .getGrid() .values() .stream() .flatMap(List::stream) .filter(imageLetter -> imageLetter.getLetter() != ' ') .map(getActions()::getFontSize) .filter(OptionalDouble::isPresent) .map(OptionalDouble::getAsDouble) .peek(descriptiveStatistics::addValue) .collect(Collectors.toCollection(DoubleArrayList::new)); var lowerBound = descriptiveStatistics.getPercentile(20); var upperBound = descriptiveStatistics.getPercentile(80); sizes.removeIf((Predicate<Double>) value -> value > upperBound || value < lowerBound); return sizes.stream().mapToDouble(Double::valueOf).average().orElse(0D); }
Example #11
Source File: CertifiedDataTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test DescriptiveStatistics - implementations that store full array of * values and execute multi-pass algorithms */ @Test public void testDescriptiveStatistics() throws Exception { DescriptiveStatistics u = new DescriptiveStatistics(); loadStats("data/PiDigits.txt", u); Assert.assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14); loadStats("data/Mavro.txt", u); Assert.assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Mavro: mean", mean, u.getMean(), 1E-14); loadStats("data/Michelso.txt", u); Assert.assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Michelso: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc1.txt", u); Assert.assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc2.txt", u); Assert.assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14); }
Example #12
Source File: DoubleMomentStatisticsTest.java From jenetics with Apache License 2.0 | 6 votes |
@Test(dataProvider = "parallelSampleCounts") public void parallelSummary(final Integer sampleCounts, final Double epsilon) { final List<Double> numbers = numbers(sampleCounts); final DescriptiveStatistics expected = new DescriptiveStatistics(); numbers.forEach(expected::addValue); final DoubleMomentStatistics summary = numbers.parallelStream() .collect(toDoubleMomentStatistics(Double::doubleValue)); Assert.assertEquals(summary.count(), numbers.size()); assertEqualsDouble(min(summary.min()), expected.getMin(), 0.0); assertEqualsDouble(max(summary.max()), expected.getMax(), 0.0); assertEqualsDouble(summary.sum(), expected.getSum(), epsilon); assertEqualsDouble(summary.mean(), expected.getMean(), epsilon); assertEqualsDouble(summary.variance(), expected.getVariance(), epsilon); assertEqualsDouble(summary.skewness(), expected.getSkewness(), epsilon); assertEqualsDouble(summary.kurtosis(), expected.getKurtosis(), epsilon); }
Example #13
Source File: StlDecomposition.java From stl-java with Apache License 2.0 | 6 votes |
/** * Computes robustness weights using bisquare weight function. * * @param remainder * The remainder, series - trend - seasonal. * @return * A new array containing the robustness weights. */ private double[] robustnessWeights(double[] remainder) { // Compute "h" = 6 median(|R_v|) double[] absRemainder = new double[remainder.length]; for (int i = 0; i < remainder.length; i++) { absRemainder[i] = Math.abs(remainder[i]); } DescriptiveStatistics stats = new DescriptiveStatistics(absRemainder); double outlierThreshold = 6 * stats.getPercentile(50); // Compute robustness weights double[] robustness = new double[remainder.length]; for (int i = 0; i < remainder.length; i++) { robustness[i] = biSquareWeight(absRemainder[i] / outlierThreshold); } return robustness; }
Example #14
Source File: StatUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Run with 77 random values, assuming that the outcome has a mean of 0 and a standard deviation of 1 with a * precision of 1E-10. */ @Test public void testNormalize2() { // create an sample with 77 values int length = 77; double sample[] = new double[length]; for (int i = 0; i < length; i++) { sample[i] = Math.random(); } // normalize this sample double standardizedSample[] = StatUtils.normalize(sample); DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < length; i++) { stats.addValue(standardizedSample[i]); } // the calculations do have a limited precision double distance = 1E-10; // check the mean an standard deviation Assert.assertEquals(0.0, stats.getMean(), distance); Assert.assertEquals(1.0, stats.getStandardDeviation(), distance); }
Example #15
Source File: StatUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Run with 77 random values, assuming that the outcome has a mean of 0 and a standard deviation of 1 with a * precision of 1E-10. */ @Test public void testNormalize2() { // create an sample with 77 values int length = 77; double sample[] = new double[length]; for (int i = 0; i < length; i++) { sample[i] = Math.random(); } // normalize this sample double standardizedSample[] = StatUtils.normalize(sample); DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < length; i++) { stats.addValue(standardizedSample[i]); } // the calculations do have a limited precision double distance = 1E-10; // check the mean an standard deviation Assert.assertEquals(0.0, stats.getMean(), distance); Assert.assertEquals(1.0, stats.getStandardDeviation(), distance); }
Example #16
Source File: StatUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1. * * @param sample Sample to normalize. * @return normalized (standardized) sample. * @since 2.2 */ public static double[] normalize(final double[] sample) { DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the series to stats for (int i = 0; i < sample.length; i++) { stats.addValue(sample[i]); } // Compute mean and standard deviation double mean = stats.getMean(); double standardDeviation = stats.getStandardDeviation(); // initialize the standardizedSample, which has the same length as the sample double[] standardizedSample = new double[sample.length]; for (int i = 0; i < sample.length; i++) { // z = (x- mean)/standardDeviation standardizedSample[i] = (sample[i] - mean) / standardDeviation; } return standardizedSample; }
Example #17
Source File: ListUnivariateImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ @Override public double[] getValues() { int length = list.size(); // If the window size is not INFINITE_WINDOW AND // the current list is larger that the window size, we need to // take into account only the last n elements of the list // as definied by windowSize final int wSize = getWindowSize(); if (wSize != DescriptiveStatistics.INFINITE_WINDOW && wSize < list.size()) { length = list.size() - FastMath.max(0, list.size() - wSize); } // Create an array to hold all values double[] copiedArray = new double[length]; for (int i = 0; i < copiedArray.length; i++) { copiedArray[i] = getElement(i); } return copiedArray; }
Example #18
Source File: CertifiedDataTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test DescriptiveStatistics - implementations that store full array of * values and execute multi-pass algorithms */ @Test public void testDescriptiveStatistics() throws Exception { DescriptiveStatistics u = new DescriptiveStatistics(); loadStats("data/PiDigits.txt", u); Assert.assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14); loadStats("data/Mavro.txt", u); Assert.assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Mavro: mean", mean, u.getMean(), 1E-14); loadStats("data/Michelso.txt", u); Assert.assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Michelso: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc1.txt", u); Assert.assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc2.txt", u); Assert.assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14); }
Example #19
Source File: ReductionOptimizer.java From AILibs with GNU Affero General Public License v3.0 | 6 votes |
private int getLossForClassifier(final MCTreeNode tree, final Instances data) { this.completeTree(tree); synchronized (this) { /* now eval the tree */ try { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < 2; i++) { List<IWekaInstances> split = (WekaUtil.getStratifiedSplit(new WekaInstances(data), this.seed + i, .6f)); tree.buildClassifier(split.get(0).getList()); Evaluation eval = new Evaluation(data); eval.evaluateModel(tree, split.get(1).getList()); stats.addValue(eval.pctIncorrect()); } return (int) Math.round((stats.getMean() * 100)); } catch (Exception e) { this.logger.error(LoggerUtil.getExceptionInfo(e)); return Integer.MAX_VALUE; } } }
Example #20
Source File: StatUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1. * * @param sample Sample to normalize. * @return normalized (standardized) sample. * @since 2.2 */ public static double[] normalize(final double[] sample) { DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the series to stats for (int i = 0; i < sample.length; i++) { stats.addValue(sample[i]); } // Compute mean and standard deviation double mean = stats.getMean(); double standardDeviation = stats.getStandardDeviation(); // initialize the standardizedSample, which has the same length as the sample double[] standardizedSample = new double[sample.length]; for (int i = 0; i < sample.length; i++) { // z = (x- mean)/standardDeviation standardizedSample[i] = (sample[i] - mean) / standardDeviation; } return standardizedSample; }
Example #21
Source File: ListUnivariateImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ @Override public double getElement(int index) { double value = Double.NaN; int calcIndex = index; final int wSize = getWindowSize(); if (wSize != DescriptiveStatistics.INFINITE_WINDOW && wSize < list.size()) { calcIndex = (list.size() - wSize) + index; } try { value = transformer.transform(list.get(calcIndex)); } catch (MathIllegalArgumentException e) { e.printStackTrace(); } return value; }
Example #22
Source File: LongMomentStatisticsTest.java From jenetics with Apache License 2.0 | 6 votes |
@Test(dataProvider = "parallelSampleCounts") public void parallelSummary(final Integer sampleCounts, final Double epsilon) { final List<Long> numbers = numbers(sampleCounts); final DescriptiveStatistics expected = new DescriptiveStatistics(); numbers.forEach(expected::addValue); final LongMomentStatistics summary = numbers.stream() .collect(toLongMomentStatistics(Long::longValue)); Assert.assertEquals(summary.count(), numbers.size()); assertEqualsDouble(min(summary.min()), expected.getMin(), 0.0); assertEqualsDouble(max(summary.max()), expected.getMax(), 0.0); assertEqualsDouble(summary.sum(), expected.getSum(), epsilon); assertEqualsDouble(summary.mean(), expected.getMean(), epsilon); assertEqualsDouble(summary.variance(), expected.getVariance(), epsilon); assertEqualsDouble(summary.skewness(), expected.getSkewness(), epsilon); assertEqualsDouble(summary.kurtosis(), expected.getKurtosis(), epsilon); }
Example #23
Source File: CertifiedDataTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test DescriptiveStatistics - implementations that store full array of * values and execute multi-pass algorithms */ @Test public void testDescriptiveStatistics() throws Exception { DescriptiveStatistics u = new DescriptiveStatistics(); loadStats("data/PiDigits.txt", u); Assert.assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14); loadStats("data/Mavro.txt", u); Assert.assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Mavro: mean", mean, u.getMean(), 1E-14); loadStats("data/Michelso.txt", u); Assert.assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Michelso: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc1.txt", u); Assert.assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc2.txt", u); Assert.assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14); }
Example #24
Source File: Spectrum.java From cineast with MIT License | 6 votes |
/** * Find local maxima in the spectrum and returns the indices of those maxima as integer * array. * * @param threshold Threshold for search. Values bellow that threshold won't be considered. * @return Array containing indices (zero-based) of local maxima. */ public List<Pair<Float, Double>> findLocalMaxima(double threshold, boolean significant) { List<Pair<Float,Double>> peaks = new ArrayList<>(); for (int i=1;i<this.spectrum.length-1;i++) { if (this.spectrum[i] < threshold) { continue; } if (spectrum[i] > Math.max(spectrum[i+1], spectrum[i-1])) { peaks.add(this.get(i)); } } if (significant) { DescriptiveStatistics statistics = new DescriptiveStatistics(); for (Pair<Float, Double> peak : peaks) { statistics.addValue(peak.second); } final double mean = statistics.getMean(); final double stddev = statistics.getStandardDeviation(); peaks.removeIf(p -> p.second < (mean + stddev * 2)); } return peaks; }
Example #25
Source File: CertifiedDataTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test DescriptiveStatistics - implementations that store full array of * values and execute multi-pass algorithms */ @Test public void testDescriptiveStatistics() throws Exception { DescriptiveStatistics u = new DescriptiveStatistics(); loadStats("data/PiDigits.txt", u); Assert.assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14); loadStats("data/Mavro.txt", u); Assert.assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Mavro: mean", mean, u.getMean(), 1E-14); loadStats("data/Michelso.txt", u); Assert.assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("Michelso: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc1.txt", u); Assert.assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14); loadStats("data/NumAcc2.txt", u); Assert.assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14); Assert.assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14); }
Example #26
Source File: DescribeEvaluator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Object doWork(Object value) throws IOException { if(!(value instanceof List<?>)){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting a numeric list but found %s", toExpression(constructingFactory), value.getClass().getSimpleName())); } // we know each value is a BigDecimal or a list of BigDecimals DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(); ((List<?>)value).stream().mapToDouble(innerValue -> ((Number)innerValue).doubleValue()).forEach(innerValue -> descriptiveStatistics.addValue(innerValue)); Tuple tuple = new Tuple(); tuple.put("max", descriptiveStatistics.getMax()); tuple.put("mean", descriptiveStatistics.getMean()); tuple.put("min", descriptiveStatistics.getMin()); tuple.put("stdev", descriptiveStatistics.getStandardDeviation()); tuple.put("sum", descriptiveStatistics.getSum()); tuple.put("N", descriptiveStatistics.getN()); tuple.put("var", descriptiveStatistics.getVariance()); tuple.put("kurtosis", descriptiveStatistics.getKurtosis()); tuple.put("skewness", descriptiveStatistics.getSkewness()); tuple.put("popVar", descriptiveStatistics.getPopulationVariance()); tuple.put("geometricMean", descriptiveStatistics.getGeometricMean()); tuple.put("sumsq", descriptiveStatistics.getSumsq()); return tuple; }
Example #27
Source File: OnlineStatisticsProviderTest.java From metron with Apache License 2.0 | 5 votes |
public static void validateStatisticsProvider( StatisticsProvider statsProvider , SummaryStatistics summaryStats , DescriptiveStatistics stats ) { //N assertEquals(statsProvider.getCount(), stats.getN()); //sum assertEquals(statsProvider.getSum(), stats.getSum(), 1e-3); //sum of squares assertEquals(statsProvider.getSumSquares(), stats.getSumsq(), 1e-3); //sum of squares assertEquals(statsProvider.getSumLogs(), summaryStats.getSumOfLogs(), 1e-3); //Mean assertEquals(statsProvider.getMean(), stats.getMean(), 1e-3); //Quadratic Mean assertEquals(statsProvider.getQuadraticMean(), summaryStats.getQuadraticMean(), 1e-3); //SD assertEquals(statsProvider.getStandardDeviation(), stats.getStandardDeviation(), 1e-3); //Variance assertEquals(statsProvider.getVariance(), stats.getVariance(), 1e-3); //Min assertEquals(statsProvider.getMin(), stats.getMin(), 1e-3); //Max assertEquals(statsProvider.getMax(), stats.getMax(), 1e-3); //Kurtosis assertEquals(stats.getKurtosis(), statsProvider.getKurtosis(), 1e-3); //Skewness assertEquals(stats.getSkewness(), statsProvider.getSkewness(), 1e-3); for(double d = 10.0;d < 100.0;d+=10) { // This is a sketch, so we're a bit more forgiving here in our choice of \epsilon. assertEquals( statsProvider.getPercentile(d), stats.getPercentile(d), 1e-2, "Percentile mismatch for " + d + "th %ile"); } }
Example #28
Source File: MovingMedianEvaluator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Object doWork(Object first, Object second) throws IOException{ if(null == first){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory))); } if(null == second){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory))); } if(!(first instanceof List<?>)){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for the first value, expecting a List",toExpression(constructingFactory), first.getClass().getSimpleName())); } if(!(second instanceof Number)){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for the second value, expecting a Number",toExpression(constructingFactory), first.getClass().getSimpleName())); } List<?> values = (List<?>)first; int window = ((Number)second).intValue(); List<Number> moving = new ArrayList<>(); DescriptiveStatistics slider = new DescriptiveStatistics(window); Percentile percentile = new Percentile(); for(Object value : values){ slider.addValue(((Number)value).doubleValue()); if(slider.getN() >= window){ double median = percentile.evaluate(slider.getValues(), 50); moving.add(median); } } return moving; }
Example #29
Source File: BasicPerformanceTest.java From jbox2d with BSD 2-Clause "Simplified" License | 5 votes |
public BasicPerformanceTest(int numTests, int iters, int frames) { this.numTests = numTests; this.iters = iters; this.frames = frames; stats = new DescriptiveStatistics[numTests]; for (int i = 0; i < numTests; i++) { stats[i] = new DescriptiveStatistics(iters * frames + 1); testOrder.add(i); } }
Example #30
Source File: RPCA.java From Surus with Apache License 2.0 | 5 votes |
private double standardDeviation(double[][] x) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < x.length; i ++) for (int j = 0; j < x[i].length; j++) stats.addValue(x[i][j]); return stats.getStandardDeviation(); }