List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getPopulationVariance
public double getPopulationVariance()
From source file:com.github.jessemull.microflexbigdecimal.stat.PopulationVarianceWeightsTest.java
/** * Tests set calculation using indices./*from w w w. ja v a 2 s. com*/ */ @Test public void testSetIndices() { for (Plate plate : arrayIndices) { int begin = random.nextInt(plate.first().size() - 4); int end = begin + random.nextInt(3) + 3; Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>(); Map<Well, BigDecimal> returnedMap = variance.set(plate.dataSet(), ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin, mc); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index] = bd.doubleValue() * weightsIndices[index]; index++; } DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end)); double resultDouble = stat.getPopulationVariance(); BigDecimal result = new BigDecimal(resultDouble, mc); resultMap.put(well, result); } for (Well well : plate) { BigDecimal result = resultMap.get(well); BigDecimal returned = returnedMap.get(well); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.loadtesting.core.data.TimeSerieData.java
public TimeSerieData(String name, List<TimeSample> samples, CapturerConfig config) { this.name = name; this.unit = config.getUnit(); this.volume = samples.size(); if (volume > 0) { TimeSample first = samples.get(0); this.unit = first.getTimeUnit(); this.opening = first.getTime(unit); TimeSample last = samples.get(volume - 1); this.closing = last.getTime(unit); this.samples = config.getFilter().filter(samples); DescriptiveStatistics stats = new DescriptiveStatistics(volume); for (TimeSample timeSample : samples) { stats.addValue(timeSample.getTime(unit)); }// w w w . j av a2s . c o m this.high = stats.getMax(); this.low = stats.getMin(); this.median = (high + low) / 2; this.typical = (high + low + closing) / 3; this.weightedClose = (high + low + closing + closing) / 4; this.sma = stats.getMean(); this.variance = stats.getVariance(); this.sd = stats.getStandardDeviation(); this.sum = stats.getSum(); this.sumsq = stats.getSumsq(); this.skewness = stats.getSkewness(); this.kurtosis = stats.getKurtosis(); this.geometricMean = stats.getGeometricMean(); this.populationVariance = stats.getPopulationVariance(); } else { this.samples = samples; } }
From source file:org.apache.solr.client.solrj.io.eval.DescribeEvaluator.java
@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())); }/*from w w w . java2 s . c o m*/ // we know each value is a BigDecimal or a list of BigDecimals DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(); ((List<?>) value).stream().mapToDouble(innerValue -> ((BigDecimal) innerValue).doubleValue()) .forEach(innerValue -> descriptiveStatistics.addValue(innerValue)); Map<String, Number> map = new HashMap<>(); map.put("max", descriptiveStatistics.getMax()); map.put("mean", descriptiveStatistics.getMean()); map.put("min", descriptiveStatistics.getMin()); map.put("stdev", descriptiveStatistics.getStandardDeviation()); map.put("sum", descriptiveStatistics.getSum()); map.put("N", descriptiveStatistics.getN()); map.put("var", descriptiveStatistics.getVariance()); map.put("kurtosis", descriptiveStatistics.getKurtosis()); map.put("skewness", descriptiveStatistics.getSkewness()); map.put("popVar", descriptiveStatistics.getPopulationVariance()); map.put("geometricMean", descriptiveStatistics.getGeometricMean()); map.put("sumsq", descriptiveStatistics.getSumsq()); return new Tuple(map); }
From source file:org.cse.visiri.app.algoevaluation.DistributionEval.java
public void EvaluateDistribution(QueryDistribution dist, String algoname) { Map<String, Integer> allInfo = new TreeMap<String, Integer>(); Map<String, Integer> nodeInfo = new TreeMap<String, Integer>(); Map<String, Double> nodeCosts = new TreeMap<String, Double>(); for (Query q : dist.getQueryAllocation().keySet()) { String node = dist.getQueryAllocation().get(q); if (!allInfo.containsKey(node)) { allInfo.put(node, 0);//from w w w . ja va2 s.c o m } int val = allInfo.get(node); allInfo.put(node, val + 1); if (node.startsWith(NODE_PREFIX)) { if (!nodeInfo.containsKey(node)) { nodeInfo.put(node, 0); nodeCosts.put(node, 0.0); } val = nodeInfo.get(node); nodeInfo.put(node, val + 1); nodeCosts.put(node, nodeCosts.get(node) + q.getCost()); } } DescriptiveStatistics stat = new DescriptiveStatistics(); DescriptiveStatistics costStat = new DescriptiveStatistics(); System.out.println("Query counts : "); for (String node : nodeInfo.keySet()) { System.out.println(node + " : " + allInfo.get(node)); stat.addValue(nodeInfo.get(node)); costStat.addValue(nodeCosts.get(node)); } System.out.println(); double mean = stat.getMean(); double stdDev = Math.sqrt(stat.getPopulationVariance()); double varCoef = stdDev / mean; System.out.println("mean : " + mean); System.out.println("stdDev : " + stdDev); System.out.println("Coefficient of var : " + varCoef); System.out.println("\nCosts :"); mean = costStat.getMean(); stdDev = Math.sqrt(costStat.getPopulationVariance()); varCoef = stdDev / mean; System.out.println("mean : " + mean); System.out.println("stdDev : " + stdDev); System.out.println("Coefficient of var : " + varCoef); //calculate event duplication Map<String, Set<String>> eventMap = new TreeMap<String, Set<String>>(); for (Query q : dist.getQueryAllocation().keySet()) { String targetNode = dist.getQueryAllocation().get(q); for (StreamDefinition def : q.getInputStreamDefinitionsList()) { if (!eventMap.containsKey(def.getStreamId())) { eventMap.put(def.getStreamId(), new HashSet<String>()); } eventMap.get(def.getStreamId()).add(targetNode); } } stat = new DescriptiveStatistics(); for (Set<String> nodes : eventMap.values()) { stat.addValue(nodes.size()); } double avg = stat.getMean(); System.out.println(); System.out.println("Avg. event duplication " + avg); try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("VISIRI_algoeval.txt", true))); out.println(stdDev); out.close(); } catch (IOException e) { e.printStackTrace(); } try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("VISIRI_eventDup.txt", true))); out.println(avg); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.deidentifier.arx.aggregates.StatisticsBuilder.java
/** * Returns summary statistics for all attributes. * //from w w w. j av a 2 s . com * @param listwiseDeletion A flag enabling list-wise deletion * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <T> Map<String, StatisticsSummary<?>> getSummaryStatistics(boolean listwiseDeletion) { // Reset stop flag interrupt.value = false; Map<String, DescriptiveStatistics> statistics = new HashMap<String, DescriptiveStatistics>(); Map<String, StatisticsSummaryOrdinal> ordinal = new HashMap<String, StatisticsSummaryOrdinal>(); Map<String, DataScale> scales = new HashMap<String, DataScale>(); Map<String, GeometricMean> geomean = new HashMap<String, GeometricMean>(); // Detect scales for (int col = 0; col < handle.getNumColumns(); col++) { // Meta String attribute = handle.getAttributeName(col); DataType<?> type = handle.getDataType(attribute); // Scale DataScale scale = type.getDescription().getScale(); // Try to replace nominal scale with ordinal scale based on base data type if (scale == DataScale.NOMINAL && handle.getGeneralization(attribute) != 0) { if (!(handle.getBaseDataType(attribute) instanceof ARXString) && getHierarchy(col, true) != null) { scale = DataScale.ORDINAL; } } // Store scales.put(attribute, scale); statistics.put(attribute, new DescriptiveStatistics()); geomean.put(attribute, new GeometricMean()); ordinal.put(attribute, getSummaryStatisticsOrdinal(handle.getGeneralization(attribute), handle.getDataType(attribute), handle.getBaseDataType(attribute), getHierarchy(col, true))); } // Compute summary statistics for (int row = 0; row < handle.getNumRows(); row++) { // Check, if we should include this row boolean include = true; if (listwiseDeletion) { for (int col = 0; col < handle.getNumColumns(); col++) { if (handle.isOutlier(row) || DataType.isNull(handle.getValue(row, col))) { include = false; break; } } } // Check checkInterrupt(); // If yes, add if (include) { // For each column for (int col = 0; col < handle.getNumColumns(); col++) { // Meta String value = handle.getValue(row, col); String attribute = handle.getAttributeName(col); DataType<?> type = handle.getDataType(attribute); // Analyze if (!DataType.isAny(value) && !DataType.isNull(value)) { ordinal.get(attribute).addValue(value); if (type instanceof DataTypeWithRatioScale) { double doubleValue = ((DataTypeWithRatioScale) type).toDouble(type.parse(value)); statistics.get(attribute).addValue(doubleValue); geomean.get(attribute).increment(doubleValue + 1d); } } } } } // Convert Map<String, StatisticsSummary<?>> result = new HashMap<String, StatisticsSummary<?>>(); for (int col = 0; col < handle.getNumColumns(); col++) { // Check checkInterrupt(); // Depending on scale String attribute = handle.getAttributeName(col); DataScale scale = scales.get(attribute); DataType<T> type = (DataType<T>) handle.getDataType(attribute); ordinal.get(attribute).analyze(); if (scale == DataScale.NOMINAL) { StatisticsSummaryOrdinal stats = ordinal.get(attribute); result.put(attribute, new StatisticsSummary<T>(DataScale.NOMINAL, stats.getNumberOfMeasures(), stats.getMode(), type.parse(stats.getMode()))); } else if (scale == DataScale.ORDINAL) { StatisticsSummaryOrdinal stats = ordinal.get(attribute); result.put(attribute, new StatisticsSummary<T>(DataScale.ORDINAL, stats.getNumberOfMeasures(), stats.getMode(), type.parse(stats.getMode()), stats.getMedian(), type.parse(stats.getMedian()), stats.getMin(), type.parse(stats.getMin()), stats.getMax(), type.parse(stats.getMax()))); } else if (scale == DataScale.INTERVAL) { StatisticsSummaryOrdinal stats = ordinal.get(attribute); DescriptiveStatistics stats2 = statistics.get(attribute); boolean isPeriod = type.getDescription().getWrappedClass() == Date.class; // TODO: Something is wrong with commons math's kurtosis double kurtosis = stats2.getKurtosis(); kurtosis = kurtosis < 0d ? Double.NaN : kurtosis; double range = stats2.getMax() - stats2.getMin(); double stddev = Math.sqrt(stats2.getVariance()); result.put(attribute, new StatisticsSummary<T>(DataScale.INTERVAL, stats.getNumberOfMeasures(), stats.getMode(), type.parse(stats.getMode()), stats.getMedian(), type.parse(stats.getMedian()), stats.getMin(), type.parse(stats.getMin()), stats.getMax(), type.parse(stats.getMax()), toString(type, stats2.getMean(), false, false), toValue(type, stats2.getMean()), stats2.getMean(), toString(type, stats2.getVariance(), isPeriod, true), toValue(type, stats2.getVariance()), stats2.getVariance(), toString(type, stats2.getPopulationVariance(), isPeriod, true), toValue(type, stats2.getPopulationVariance()), stats2.getPopulationVariance(), toString(type, stddev, isPeriod, false), toValue(type, stddev), stddev, toString(type, range, isPeriod, false), toValue(type, range), stats2.getMax() - stats2.getMin(), toString(type, kurtosis, isPeriod, false), toValue(type, kurtosis), kurtosis)); } else if (scale == DataScale.RATIO) { StatisticsSummaryOrdinal stats = ordinal.get(attribute); DescriptiveStatistics stats2 = statistics.get(attribute); GeometricMean geo = geomean.get(attribute); // TODO: Something is wrong with commons math's kurtosis double kurtosis = stats2.getKurtosis(); kurtosis = kurtosis < 0d ? Double.NaN : kurtosis; double range = stats2.getMax() - stats2.getMin(); double stddev = Math.sqrt(stats2.getVariance()); result.put(attribute, new StatisticsSummary<T>(DataScale.RATIO, stats.getNumberOfMeasures(), stats.getMode(), type.parse(stats.getMode()), stats.getMedian(), type.parse(stats.getMedian()), stats.getMin(), type.parse(stats.getMin()), stats.getMax(), type.parse(stats.getMax()), toString(type, stats2.getMean(), false, false), toValue(type, stats2.getMean()), stats2.getMean(), toString(type, stats2.getVariance(), false, false), toValue(type, stats2.getVariance()), stats2.getVariance(), toString(type, stats2.getPopulationVariance(), false, false), toValue(type, stats2.getPopulationVariance()), stats2.getPopulationVariance(), toString(type, stddev, false, false), toValue(type, stddev), stddev, toString(type, range, false, false), toValue(type, range), range, toString(type, kurtosis, false, false), toValue(type, kurtosis), kurtosis, toString(type, geo.getResult() - 1d, false, false), toValue(type, geo.getResult() - 1d), stats2.getGeometricMean())); } } return result; }
From source file:org.lightjason.agentspeak.action.buildin.math.statistic.EStatisticValue.java
/** * returns a statistic value//from w w w . j a va 2 s . com * * @param p_statistic statistic object * @return statistic value */ public final double value(final DescriptiveStatistics p_statistic) { switch (this) { case GEOMETRICMEAN: return p_statistic.getGeometricMean(); case MAX: return p_statistic.getMax(); case MIN: return p_statistic.getMin(); case COUNT: return p_statistic.getN(); case POPULATIONVARIANCE: return p_statistic.getPopulationVariance(); case QUADRATICMEAN: return p_statistic.getQuadraticMean(); case STANDARDDEVIATION: return p_statistic.getStandardDeviation(); case SUM: return p_statistic.getSum(); case SUMSQUARE: return p_statistic.getSumsq(); case VARIANCE: return p_statistic.getVariance(); case MEAN: return p_statistic.getMean(); case KURTIOSIS: return p_statistic.getKurtosis(); default: throw new CIllegalStateException( org.lightjason.agentspeak.common.CCommon.languagestring(this, "unknown", this)); } }
From source file:org.lightjason.agentspeak.action.builtin.math.statistic.EStatisticValue.java
/** * returns a statistic value/*from ww w .j av a2 s . co m*/ * * @param p_statistic statistic object * @return statistic value */ public final double value(@Nonnull final DescriptiveStatistics p_statistic) { switch (this) { case GEOMETRICMEAN: return p_statistic.getGeometricMean(); case MAX: return p_statistic.getMax(); case MIN: return p_statistic.getMin(); case COUNT: return p_statistic.getN(); case POPULATIONVARIANCE: return p_statistic.getPopulationVariance(); case QUADRATICMEAN: return p_statistic.getQuadraticMean(); case STANDARDDEVIATION: return p_statistic.getStandardDeviation(); case SUM: return p_statistic.getSum(); case SUMSQUARE: return p_statistic.getSumsq(); case VARIANCE: return p_statistic.getVariance(); case MEAN: return p_statistic.getMean(); case KURTIOSIS: return p_statistic.getKurtosis(); default: throw new CIllegalStateException( org.lightjason.agentspeak.common.CCommon.languagestring(this, "unknown", this)); } }