List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getMean
public double getMean()
From source file:com.github.jessemull.microflexbigdecimal.stat.MeanTest.java
/** * Tests well calculation./* ww w . ja v a2 s .co m*/ */ @Test public void testWell() { for (Plate plate : array) { for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getMean(); BigDecimal returned = mean.well(well, mc); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.iorga.webappwatcher.analyzer.ws.statistics.DailyStatisticsWS.java
@GET @Path("/compute") public StreamingOutput compute() throws ClassNotFoundException, IOException { final List<DayStatistic> computeDayStatistics = durationPerPrincipalStats.computeDayStatistics(); return new StreamingOutput() { @Override/* w w w .j a v a 2s. c om*/ public void write(final OutputStream output) throws IOException, WebApplicationException { final JsonGenerator generator = OBJECT_MAPPER.getJsonFactory().createJsonGenerator(output, JsonEncoding.UTF8); generator.writeStartArray(); for (final DayStatistic dayStatistic : computeDayStatistics) { generator.writeStartObject(); generator.writeFieldName("startDate"); OBJECT_MAPPER.writeValue(generator, dayStatistic.getStartDate()); generator.writeFieldName("endDate"); OBJECT_MAPPER.writeValue(generator, dayStatistic.getEndDate()); generator.writeArrayFieldStart("statistics"); // write each statistic for (final String statisticType : new String[] { "distinctUsers", "numberOfRequests", "durationsFor1clickSum", "durationsFor1clickMean", "durationsFor1clickMedian", "durationsFor1click90c", "durationsFor1clickMin", "durationsFor1clickMax" }) { // generator.writeFieldName(statisticType); generator.writeStartObject(); generator.writeStringField("type", statisticType); // get the statistics from the dayStatistic DescriptiveStatistics descriptiveStatistics; try { descriptiveStatistics = (DescriptiveStatistics) dayStatistic.getClass() .getMethod("get" + StringUtils.capitalize(statisticType)).invoke(dayStatistic); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IOException( "Problem while invoking getter for statisticType " + statisticType, e); } generator.writeNumberField("min", descriptiveStatistics.getMin()); generator.writeNumberField("max", descriptiveStatistics.getMax()); generator.writeNumberField("mean", descriptiveStatistics.getMean()); generator.writeNumberField("median", descriptiveStatistics.getPercentile(50)); generator.writeEndObject(); } generator.writeEndArray(); generator.writeFieldName("distinctPrincipalsSize"); OBJECT_MAPPER.writeValue(generator, dayStatistic.getPrincipals().size()); generator.writeEndObject(); } generator.writeEndArray(); generator.flush(); // required else all the stream is not sent } }; }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.MeanBigDecimalTest.java
/** * Tests well calculation.//from w w w. jav a 2 s .co m */ @Test public void testWell() { for (PlateBigDecimal plate : array) { for (WellBigDecimal well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getMean(); BigDecimal returned = mean.well(well, mc); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflexbigdecimal.stat.MeanTest.java
/** * Tests the plate statistics method.// w w w .j av a 2 s .c o m */ @Test public void testPlate() { for (Plate plate : array) { Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>(); Map<Well, BigDecimal> returnedMap = mean.plate(plate, mc); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getMean(); BigDecimal result = new BigDecimal(resultDouble); 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:cc.kave.commons.pointsto.evaluation.events.MRREvaluation.java
private double calcMRR(ICallsRecommender<Query> recommender, Map<ICompletionEvent, List<Usage>> eventQueries) { DescriptiveStatistics reciprocalRank = new DescriptiveStatistics(); for (Map.Entry<ICompletionEvent, List<Usage>> eventEntry : eventQueries.entrySet()) { ICompletionEvent event = eventEntry.getKey(); IProposal expectedProposal = event.getLastSelectedProposal(); ICoReMethodName expectedMethod = CoReNameConverter .convert((cc.kave.commons.model.naming.codeelements.IMethodName) expectedProposal.getName()); for (Usage query : eventEntry.getValue()) { double rr = measure.calculate(recommender, Query.createAsCopyFrom(query), ImmutableSet.of(expectedMethod)); reciprocalRank.addValue(rr); }// w w w . j av a2 s. c o m } return reciprocalRank.getMean(); }
From source file:com.github.jessemull.microflexbigdecimal.stat.MeanTest.java
/** * Tests set calculation./*w w w . j av a 2 s . c om*/ */ @Test public void testSet() { for (Plate plate : array) { Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>(); Map<Well, BigDecimal> returnedMap = mean.set(plate.dataSet(), mc); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getMean(); BigDecimal result = new BigDecimal(resultDouble); 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.github.jessemull.microflex.stat.statbigdecimal.MeanBigDecimalTest.java
/** * Tests the plate statistics method./*from ww w . j a va 2 s . c o m*/ */ @Test public void testPlate() { for (PlateBigDecimal plate : array) { Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>(); Map<WellBigDecimal, BigDecimal> returnedMap = mean.plate(plate, mc); for (WellBigDecimal well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getMean(); BigDecimal result = new BigDecimal(resultDouble); resultMap.put(well, result); } for (WellBigDecimal 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.github.jessemull.microflex.stat.statbigdecimal.MeanBigDecimalTest.java
/** * Tests set calculation./* w w w . j av a2s .c o m*/ */ @Test public void testSet() { for (PlateBigDecimal plate : array) { Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>(); Map<WellBigDecimal, BigDecimal> returnedMap = mean.set(plate.dataSet(), mc); for (WellBigDecimal well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getMean(); BigDecimal result = new BigDecimal(resultDouble); resultMap.put(well, result); } for (WellBigDecimal 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.github.jessemull.microflexdouble.stat.MeanWeightsTest.java
/** * Tests the aggregated plate statistics method using a collection. *//* w w w . j av a2s . com*/ @Test public void testAggregatedPlateCollection() { List<Plate> collection = Arrays.asList(array); Map<Plate, Double> aggregatedReturnedMap = mean.platesAggregated(collection, weights); Map<Plate, Double> aggregatedResultMap = new TreeMap<Plate, Double>(); for (Plate plate : collection) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (Well well : plate) { List<BigDecimal> input = well.toBigDecimal(); for (int i = 0; i < input.size(); i++) { resultList.add(input.get(i).multiply(new BigDecimal(weights[i]))); } } double[] inputAggregated = new double[resultList.size()]; for (int i = 0; i < resultList.size(); i++) { inputAggregated[i] = resultList.get(i).doubleValue(); } DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated); double aggregatedResult = statAggregated.getMean(); aggregatedResultMap.put(plate, aggregatedResult); } for (Plate plate : collection) { double result = Precision.round(aggregatedResultMap.get(plate), precision); double returned = Precision.round(aggregatedReturnedMap.get(plate), precision); assertTrue(result == returned); } }
From source file:com.github.jessemull.microflexdouble.stat.MeanWeightsTest.java
/** * Tests the aggregated plate statistics method using an array. *///w w w .jav a2 s. c o m @Test public void testAggregatedPlateArray() { Map<Plate, Double> aggregatedReturnedMap = mean.platesAggregated(array, weights); Map<Plate, Double> aggregatedResultMap = new TreeMap<Plate, Double>(); for (Plate plate : array) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (Well well : plate) { List<BigDecimal> input = well.toBigDecimal(); for (int i = 0; i < input.size(); i++) { resultList.add(input.get(i).multiply(new BigDecimal(weights[i]))); } } double[] inputAggregated = new double[resultList.size()]; for (int i = 0; i < resultList.size(); i++) { inputAggregated[i] = resultList.get(i).doubleValue(); } DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated); double aggregatedResult = statAggregated.getMean(); aggregatedResultMap.put(plate, aggregatedResult); } for (Plate plate : array) { double result = Precision.round(aggregatedResultMap.get(plate), precision); double returned = Precision.round(aggregatedReturnedMap.get(plate), precision); assertTrue(result == returned); } }