List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getSkewness
public double getSkewness()
From source file:org.jenetics.stat.LongMomentStatisticsTest.java
@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.getCount(), numbers.size()); assertEqualsDouble(min(summary.getMin()), expected.getMin(), 0.0); assertEqualsDouble(max(summary.getMax()), expected.getMax(), 0.0); assertEqualsDouble(summary.getSum(), expected.getSum(), epsilon); assertEqualsDouble(summary.getMean(), expected.getMean(), epsilon); assertEqualsDouble(summary.getVariance(), expected.getVariance(), epsilon); assertEqualsDouble(summary.getSkewness(), expected.getSkewness(), epsilon); assertEqualsDouble(summary.getKurtosis(), expected.getKurtosis(), epsilon); }
From source file:org.moeaframework.core.PRNGTest.java
/** * Asserts that the statistical distribution satisfies the properties of a * real-valued uniform distribution between {@code min} and {@code max}. * /*w w w.j ava 2 s . c om*/ * @param min the minimum bounds of the uniform distribution * @param max the maximum bounds of the uniform distribution * @param statistics the captures statistics of a sampled distribution */ private void testUniformDistribution(double min, double max, DescriptiveStatistics statistics) { Assert.assertEquals((min + max) / 2.0, statistics.getMean(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(Math.pow(max - min, 2.0) / 12.0, statistics.getVariance(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(0.0, statistics.getSkewness(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(-6.0 / 5.0, statistics.getKurtosis(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(min, statistics.getMin(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(max, statistics.getMax(), TestThresholds.STATISTICS_EPS); }
From source file:org.moeaframework.core.PRNGTest.java
/** * Asserts that the statistical distribution satisfies the properties of an * integer-valued uniform distribution between {@code min} and {@code max}. * // w w w. j a v a 2s. co m * @param min the minimum bounds of the uniform distribution * @param max the maximum bounds of the uniform distribution * @param statistics the captures statistics of a sampled distribution */ private void testUniformDistribution(int min, int max, DescriptiveStatistics statistics) { int n = max - min + 1; int nn = n * n; Assert.assertEquals((min + max) / 2.0, statistics.getMean(), TestThresholds.STATISTICS_EPS); Assert.assertEquals((nn - 1) / 12.0, statistics.getVariance(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(0.0, statistics.getSkewness(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(-(6.0 * (nn + 1)) / (5.0 * (nn - 1)), statistics.getKurtosis(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(min, statistics.getMin(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(max, statistics.getMax(), TestThresholds.STATISTICS_EPS); }
From source file:org.moeaframework.core.PRNGTest.java
/** * Asserts that the statistical distribution satisfies the properties of a * Gaussian distribution with the specified mean and standard deviation. * //from w w w . jav a2 s. c o m * @param mu the mean value of the distribution * @param sigma the standard deviation of the distribution * @param statistics the captures statistics of a sampled distribution */ private void testGaussianDistribution(double mu, double sigma, DescriptiveStatistics statistics) { Assert.assertEquals(mu, statistics.getMean(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(sigma * sigma, statistics.getVariance(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(0.0, statistics.getSkewness(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(0.0, statistics.getKurtosis(), TestThresholds.STATISTICS_EPS); }
From source file:org.moeaframework.TestUtils.java
/** * Asserts that the statistical distribution satisfies the properties of an * integer-valued uniform distribution between {@code min} and {@code max}. * // w w w .j av a 2 s . co m * @param min the minimum bounds of the uniform distribution * @param max the maximum bounds of the uniform distribution * @param statistics the captures statistics of a sampled distribution */ public static void assertUniformDistribution(int min, int max, DescriptiveStatistics statistics) { int n = max - min + 1; int nn = n * n; assertEquals((min + max) / 2.0, statistics.getMean()); assertEquals((nn - 1) / 12.0, statistics.getVariance()); assertEquals(0.0, statistics.getSkewness()); assertEquals(-(6.0 * (nn + 1)) / (5.0 * (nn - 1)), statistics.getKurtosis()); assertEquals(min, statistics.getMin()); assertEquals(max, statistics.getMax()); }
From source file:org.moeaframework.util.sequence.SequenceTest.java
/** * Asserts that the collected statistics appear to be from a uniform * distribution.//from w w w . ja v a 2 s . c o m * * @param min the minimum value * @param max the maximum value * @param statistics the collected statistics */ public void testUniformDistribution(double min, double max, DescriptiveStatistics statistics) { Assert.assertEquals((min + max) / 2.0, statistics.getMean(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(Math.pow(max - min, 2.0) / 12.0, statistics.getVariance(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(0.0, statistics.getSkewness(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(-6.0 / 5.0, statistics.getKurtosis(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(min, statistics.getMin(), TestThresholds.STATISTICS_EPS); Assert.assertEquals(max, statistics.getMax(), TestThresholds.STATISTICS_EPS); }
From source file:org.obiba.opal.web.magma.Dtos.java
@SuppressWarnings({ "OverlyLongMethod", "PMD.NcssMethodCount" }) public static Math.ContinuousSummaryDto.Builder asDto(ContinuousVariableSummary summary) { DescriptiveStatistics descriptiveStats = summary.getDescriptiveStats(); Math.DescriptiveStatsDto.Builder descriptiveBuilder = Math.DescriptiveStatsDto.newBuilder() .setN(descriptiveStats.getN()).addAllPercentiles(summary.getPercentiles()); if (isNumeric(descriptiveStats.getMin())) descriptiveBuilder.setMin(descriptiveStats.getMin()); if (isNumeric(descriptiveStats.getMax())) descriptiveBuilder.setMax(descriptiveStats.getMax()); if (isNumeric(descriptiveStats.getMean())) descriptiveBuilder.setMean(descriptiveStats.getMean()); if (isNumeric(descriptiveStats.getSum())) descriptiveBuilder.setSum(descriptiveStats.getSum()); if (isNumeric(descriptiveStats.getSumsq())) descriptiveBuilder.setSumsq(descriptiveStats.getSumsq()); if (isNumeric(descriptiveStats.getStandardDeviation())) { descriptiveBuilder.setStdDev(descriptiveStats.getStandardDeviation()); }/*from w ww . j ava 2 s. com*/ if (isNumeric(descriptiveStats.getVariance())) descriptiveBuilder.setVariance(descriptiveStats.getVariance()); if (isNumeric(descriptiveStats.getSkewness())) descriptiveBuilder.setSkewness(descriptiveStats.getSkewness()); if (isNumeric(descriptiveStats.getGeometricMean())) { descriptiveBuilder.setGeometricMean(descriptiveStats.getGeometricMean()); } if (isNumeric(descriptiveStats.getKurtosis())) descriptiveBuilder.setKurtosis(descriptiveStats.getKurtosis()); double median = descriptiveStats.apply(new Median()); if (isNumeric(median)) descriptiveBuilder.setMedian(median); if (isNumeric(descriptiveStats.getVariance())) descriptiveBuilder.setVariance(descriptiveStats.getVariance()); Math.ContinuousSummaryDto.Builder continuousBuilder = Math.ContinuousSummaryDto.newBuilder() .addAllDistributionPercentiles(summary.getDistributionPercentiles()); for (IntervalFrequency.Interval interval : summary.getIntervalFrequencies()) { Math.IntervalFrequencyDto.Builder freqBuilder = Math.IntervalFrequencyDto.newBuilder() .setFreq(interval.getFreq()); if (isNumeric(interval.getLower())) freqBuilder.setLower(interval.getLower()); if (isNumeric(interval.getUpper())) freqBuilder.setUpper(interval.getUpper()); if (isNumeric(interval.getDensity())) freqBuilder.setDensity(interval.getDensity()); if (isNumeric(interval.getDensityPct())) freqBuilder.setDensityPct(interval.getDensityPct()); continuousBuilder.addIntervalFrequency(freqBuilder); } for (ContinuousVariableSummary.Frequency frequency : summary.getFrequencies()) { Math.FrequencyDto.Builder freqBuilder = Math.FrequencyDto.newBuilder() // .setValue(frequency.getValue()) // .setFreq(frequency.getFreq())// .setMissing(frequency.isMissing()); if (isNumeric(frequency.getPct())) freqBuilder.setPct(frequency.getPct()); continuousBuilder.addFrequencies(freqBuilder); } return continuousBuilder.setSummary(descriptiveBuilder); }
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// w w w .java 2 s . co m * @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 ww w. j a v a2s .c o m*/ 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 w w .j av a 2 s . c o m*/ //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); } }