List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics SummaryStatistics
public SummaryStatistics()
From source file:io.galeb.router.tests.hostselectors.AbstractHashHostSelectorTest.java
void doRandomTest(double errorPercentMax, double limitOfNotHitsPercent, int numPopulation) { final HttpServerExchange exchange = new HttpServerExchange(null); final Host[] newHosts = numPopulation < hosts.length ? Arrays.copyOf(hosts, numPopulation) : hosts; final Map<Integer, String> remains = IntStream.rangeClosed(0, newHosts.length - 1).boxed() .collect(Collectors.toMap(x -> x, x -> "")); for (int retry = 1; retry <= NUM_RETRIES; retry++) { final SummaryStatistics statisticsOfResults = new SummaryStatistics(); final Map<Integer, Integer> mapOfResults = new HashMap<>(); new Random().ints(numPopulation).map(Math::abs).forEach(x -> { changeExchange(exchange, x); int result = getResult(exchange, newHosts); Integer lastCount = mapOfResults.get(result); remains.remove(result);// ww w . j a va2s . co m mapOfResults.put(result, lastCount != null ? ++lastCount : 0); }); mapOfResults.entrySet().stream().mapToDouble(Map.Entry::getValue) .forEach(statisticsOfResults::addValue); double errorPercent = (statisticsOfResults.getStandardDeviation() / numPopulation) * 100; assertThat(errorPercent, lessThan(errorPercentMax)); } final List<Integer> listOfNotHit = remains.entrySet().stream().map(Map.Entry::getKey).collect(toList()); assertThat(listOfNotHit.size(), lessThanOrEqualTo((int) (newHosts.length * (limitOfNotHitsPercent / 100)))); }
From source file:io.fabric8.example.stddev.http.StdDevProcessorTest.java
@Test public void testProcess() throws Exception { RandomGenerator rg = new JDKRandomGenerator(); double[] array = new double[10]; ObjectMapper objectMapper = new ObjectMapper(); for (int i = 0; i < array.length; i++) { array[i] = rg.nextDouble();// w ww. ja v a2s . c o m } String body = objectMapper.writeValueAsString(array); SummaryStatistics summaryStatistics = new SummaryStatistics(); List<Double> list = new ObjectMapper().readValue(body, List.class); for (Double value : list) { summaryStatistics.addValue(value); } String stdDev = Double.toString(summaryStatistics.getStandardDeviation()); resultEndpoint.expectedBodiesReceived(stdDev); template.sendBody(body); resultEndpoint.assertIsSatisfied(); }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.Timing.java
/** * Stops the timer with the specified name. * /*from ww w . j a v a2s . c o m*/ * @param name the name of the timer to stop */ public static void stopTimer(String name) { long stopTime = System.nanoTime(); Long startTime = openTimers.remove(name); if (startTime == null) { throw new IllegalArgumentException("timer does not exist"); } SummaryStatistics statistics = data.get(name); if (statistics == null) { statistics = new SummaryStatistics(); data.put(name, statistics); } statistics.addValue(stopTime - startTime); }
From source file:io.fabric8.example.variance.http.VarianceProcessorTest.java
@Test public void testProcess() throws Exception { RandomGenerator rg = new JDKRandomGenerator(); double[] array = new double[10]; ObjectMapper objectMapper = new ObjectMapper(); for (int i = 0; i < array.length; i++) { array[i] = rg.nextDouble();/* ww w . j a va 2s . co m*/ } String body = objectMapper.writeValueAsString(array); String expectedBody = "0.0"; SummaryStatistics summaryStatistics = new SummaryStatistics(); List<Double> list = new ObjectMapper().readValue(body, List.class); for (Double value : list) { summaryStatistics.addValue(value); } String variance = Double.toString(summaryStatistics.getVariance()); resultEndpoint.expectedBodiesReceived(variance); template.sendBody(body); resultEndpoint.assertIsSatisfied(); }
From source file:net.sourceforge.jabm.report.SummaryStatisticsReportVariables.java
@Override public void compute(SimEvent event) { super.compute(event); reportVariables.compute(event);/* w ww.j av a 2s .com*/ Map<Object, Number> bindings = reportVariables.getVariableBindings(); for (Object variable : bindings.keySet()) { SummaryStatistics stats = summaryVariableBindings.get(variable); if (stats == null) { stats = new SummaryStatistics(); summaryVariableBindings.put(variable, stats); } stats.addValue(bindings.get(variable).doubleValue()); } }
From source file:net.sourceforge.jabm.util.SummaryStats.java
public void initialise() { stats = new SummaryStatistics(); }
From source file:io.fabric8.example.stddev.msg.StdDevProcessor.java
@Override public void process(Exchange exchange) throws Exception { System.err.println("STD DEV GOT EXCHANGE " + exchange); String message = exchange.getIn().getBody(String.class); ObjectMapper objectMapper = new ObjectMapper(); TypeFactory typeFactory = objectMapper.getTypeFactory(); List<Double> values = objectMapper.readValue(message, typeFactory.constructCollectionType(List.class, Double.class)); SummaryStatistics summaryStatistics = new SummaryStatistics(); List<Double> list = new ObjectMapper().readValue(message, List.class); for (Double value : list) { summaryStatistics.addValue(value); }// w ww . j av a 2s. c om String stdDev = Double.toString(summaryStatistics.getStandardDeviation()); ActiveMQDestination replyTo = exchange.getIn().getHeader("JMSReplyTo", ActiveMQDestination.class); final String messageId = exchange.getIn().getHeader("JMSMessageID", String.class); if (replyTo != null) { Exchange copy = new DefaultExchange(exchange); copy.setPattern(ExchangePattern.InOnly); copy.getIn().setHeader(Variables.CORRELATION_HEADER, messageId); copy.getIn().setBody(stdDev); producerTemplate.send("jms:queue:" + replyTo.getPhysicalName(), copy); } }
From source file:io.fabric8.example.variance.msg.VarianceProcessor.java
@Override public void process(Exchange exchange) throws Exception { System.err.println("VARIANCE GOT EXCHANGE " + exchange); String message = exchange.getIn().getBody(String.class); ObjectMapper objectMapper = new ObjectMapper(); TypeFactory typeFactory = objectMapper.getTypeFactory(); List<Double> values = objectMapper.readValue(message, typeFactory.constructCollectionType(List.class, Double.class)); SummaryStatistics summaryStatistics = new SummaryStatistics(); List<Double> list = new ObjectMapper().readValue(message, List.class); for (Double value : list) { summaryStatistics.addValue(value); }/*from w ww .ja va2s.c om*/ String variance = Double.toString(summaryStatistics.getVariance()); ActiveMQDestination replyTo = exchange.getIn().getHeader("JMSReplyTo", ActiveMQDestination.class); final String messageId = exchange.getIn().getHeader("JMSMessageID", String.class); if (replyTo != null) { Exchange copy = new DefaultExchange(exchange); copy.setPattern(ExchangePattern.InOnly); copy.getIn().setHeader(Variables.CORRELATION_HEADER, messageId); copy.getIn().setBody(variance); producerTemplate.send("jms:queue:" + replyTo.getPhysicalName(), copy); System.err.println("REPLIED TO " + "jms:queue:" + replyTo.getPhysicalName()); } else { System.err.println("REPLOY NOT SET for exchange: " + exchange.getIn().getHeaders()); } }
From source file:io.druid.query.aggregation.datasketches.tuple.ArrayOfDoublesSketchToMeansPostAggregator.java
@Override public double[] compute(final Map<String, Object> combinedAggregators) { final ArrayOfDoublesSketch sketch = (ArrayOfDoublesSketch) getField().compute(combinedAggregators); final SummaryStatistics[] stats = new SummaryStatistics[sketch.getNumValues()]; Arrays.setAll(stats, i -> new SummaryStatistics()); final ArrayOfDoublesSketchIterator it = sketch.iterator(); while (it.next()) { final double[] values = it.getValues(); for (int i = 0; i < values.length; i++) { stats[i].addValue(values[i]); }/*from ww w . ja v a 2s . c o m*/ } final double[] means = new double[sketch.getNumValues()]; Arrays.setAll(means, i -> stats[i].getMean()); return means; }
From source file:io.druid.query.aggregation.datasketches.tuple.ArrayOfDoublesSketchToVariancesPostAggregator.java
@Override public double[] compute(final Map<String, Object> combinedAggregators) { final ArrayOfDoublesSketch sketch = (ArrayOfDoublesSketch) getField().compute(combinedAggregators); final SummaryStatistics[] stats = new SummaryStatistics[sketch.getNumValues()]; Arrays.setAll(stats, i -> new SummaryStatistics()); final ArrayOfDoublesSketchIterator it = sketch.iterator(); while (it.next()) { final double[] values = it.getValues(); for (int i = 0; i < values.length; i++) { stats[i].addValue(values[i]); }/* w w w . j a v a2s . c o m*/ } final double[] variances = new double[sketch.getNumValues()]; Arrays.setAll(variances, i -> stats[i].getVariance()); return variances; }