List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics getVariance
public double getVariance()
From source file:net.recommenders.rival.evaluation.statistics.EffectSize.java
/** * * Estimation of effect size based on the distribution of score differences * (from paired samples)./*from ww w. j ava 2 s.c o m*/ * * @param <V> type of the keys of each map. * @param baselineMetricPerDimension map for the baseline method, one value * for each user (dimension) * @param testMetricPerDimension map for the test method, one value for each * user (dimension) * @return the effect size. */ public static <V> double getEffectSizePairedT(final Map<V, Double> baselineMetricPerDimension, final Map<V, Double> testMetricPerDimension) { Set<V> overlap = new HashSet<V>(baselineMetricPerDimension.keySet()); overlap.retainAll(testMetricPerDimension.keySet()); SummaryStatistics differences = new SummaryStatistics(); for (V key : overlap) { double diff = testMetricPerDimension.get(key) - baselineMetricPerDimension.get(key); differences.addValue(diff); } return getEffectSizePairedT(differences.getMean(), Math.sqrt(differences.getVariance())); }
From source file:co.turnus.common.util.CommonDataUtil.java
public static StatisticalData createFrom(SummaryStatistics summary) { StatisticalData data = CommonFactory.eINSTANCE.createStatisticalData(); if (summary.getN() != 0) { data.setMax(summary.getMax());/*from w ww . jav a 2s . c o m*/ data.setMin(summary.getMin()); data.setSamples(summary.getN()); data.setSum(summary.getSum()); data.setVariance(summary.getVariance()); data.setMean(summary.getMean()); } return data; }
From source file:cn.edu.suda.core.stats.StatsUtils.java
public static DataMatrix addTTest(DataMatrix dm, int m, int n) { int col = dm.getDcol(); dm.addCols(2);//from ww w. j a v a2s .co m dm.setColname(col, "ABS_t_value"); dm.setColname(col + 1, "P_value"); for (int i = 0; i < dm.getDrow(); i++) { double[] array = dm.getRow(i); SummaryStatistics stats1 = new SummaryStatistics(); SummaryStatistics stats2 = new SummaryStatistics(); for (int j = 0; j < m; j++) { stats1.addValue(array[j]); } for (int j = m; j < m + n; j++) { stats2.addValue(array[j]); } double var1 = stats1.getVariance(); double var2 = stats2.getVariance(); if (var1 == 0 && var2 == 0) { dm.setValue(i, col, 0); dm.setValue(i, col + 1, 1); } else { double t = Math.abs(TestUtils.t(stats1, stats2)); double p = TestUtils.tTest(stats1, stats2); t = Utils.formatNumber(t, 4); p = Utils.formatNumber(p, 4); dm.setValue(i, col, t); dm.setValue(i, col + 1, p); } } return dm; }
From source file:com.trickl.stats.GammaDistributionOutlier.java
@Override public IntPredicate apply(int[] edgeFlows) { // Calculate the distribution of flow across edges SummaryStatistics flowSummaryStatistics = new SummaryStatistics(); for (int flow : edgeFlows) { flowSummaryStatistics.addValue(flow); }//www . j a va2s . c om double flowVar = flowSummaryStatistics.getVariance(); double flowMean = flowSummaryStatistics.getMean(); double gammaShape = (flowMean * flowMean) / flowVar; double gammaScale = flowVar / flowMean; GammaDistribution gammaDistribution = new GammaDistribution(gammaShape, gammaScale); return new ValueAboveHasProbabilityBelow(gammaDistribution, probability); }
From source file:net.sourceforge.jabm.report.AbstractReportVariables.java
public void recordMoments(Object statName, Map<Object, Number> variables, SummaryStatistics stats) { variables.put(createVariable(statName + ".mean"), stats.getMean()); variables.put(createVariable(statName + ".variance"), stats.getVariance()); }
From source file:io.fabric8.example.variance.http.VarianceProcessor.java
@Override public void process(Exchange exchange) throws Exception { 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 w w . j a va 2s .c o m*/ String variance = Double.toString(summaryStatistics.getVariance()); exchange.getOut().setBody(variance); }
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();//from ww w.j a v a2s . c om } 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: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 w w . java 2 s .c o m*/ 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:gr.cti.android.experimentation.controller.api.HistoryController.java
/** * Parse a time instant and create a TempReading object. * * @param millis the millis of the timestamp. * @param function the function to aggregate. * @param statistics the data values/*w w w .j av a 2 s .com*/ * @return the aggregated TempReading for this time instant. */ private TempReading parse(final long millis, final String function, SummaryStatistics statistics) { final Double value; switch (function) { case "avg": value = statistics.getMean(); break; case "max": value = statistics.getMax(); break; case "min": value = statistics.getMin(); break; case "var": value = statistics.getVariance(); break; case "sum": value = statistics.getSum(); break; default: value = statistics.getMean(); } return new TempReading(millis, value); }
From source file:net.lizalab.util.RdRandRandomTest.java
/** * Tests RdRandRandom by verifying the average of the distribution of digits 0-9 * over 100 million values. Also runs the test for Random and SecureRandom for * reference.//www . j ava 2 s .c o m * Based on Mean Test outlined in <i>Beautiful Testing</i> published by O'Reilly. * @throws GeneralSecurityException * @throws SeedException */ @Test public final void testRdRandRandomMean() throws GeneralSecurityException, SeedException { final String methodName = "testRdRandRandom : "; SummaryStatistics stats = new SummaryStatistics(); // Initialize the array ndigits = new int[10]; for (int i = 0; i < 10; i++) { ndigits[i] = 0; stats.addValue(i); } // Calculate the confidence intervals to assert. mean = stats.getMean(); stdDev = stats.getStandardDeviation(); var = stats.getVariance(); LOGGER.info("{} Normal mean: {}", methodName, mean); LOGGER.info("{} Normal std: {}", methodName, stdDev); LOGGER.info("{} Normal var: {}", methodName, var); // 99.7% CI is within 3 std. double expectedDev3SD = 3 * stdDev / Math.sqrt(values); smLowerRng3SD = mean - expectedDev3SD; smUpperRng3SD = mean + expectedDev3SD; // 95% CI is within 2 std. double expectedDev2SD = 2 * stdDev / Math.sqrt(values); smLowerRng2SD = mean - expectedDev2SD; smUpperRng2SD = mean + expectedDev2SD; LOGGER.info("{} Generating {} values.", methodName, values); LOGGER.info("{} Sample mean expected in range {} - {} 99.7% of the times.", methodName, smLowerRng3SD, smUpperRng3SD); LOGGER.info("{} Sample mean expected in range {} - {} 95% of the times.", methodName, smLowerRng2SD, smUpperRng2SD); LOGGER.info("{} Running for Random..", methodName); Random random = new Random(); meanTest(random, false); LOGGER.info("{} Running for RdRand..", methodName); random = new RdRandRandom(); meanTest(random, true); LOGGER.info("{} Running for SecureRandom..", methodName); random = new SecureRandom(); meanTest(random, false); LOGGER.info("{} Running Uncommons Maths AESCounterRNG using RdRandSeedGenerator..", methodName); random = new AESCounterRNG(new RdRandSeedGenerator()); meanTest(random, false); }