List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics addValue
public void addValue(double value)
From source file:edu.washington.gs.skyline.model.quantification.RegressionFit.java
public Double computeRSquared(CalibrationCurve curve, List<WeightedObservedPoint> points) { SummaryStatistics yValues = new SummaryStatistics(); SummaryStatistics residuals = new SummaryStatistics(); for (WeightedObservedPoint point : points) { Double yFitted = curve.getY(point.getX()); if (yFitted == null) { continue; }//from ww w.ja v a 2 s .c om yValues.addValue(point.getY()); residuals.addValue(point.getY() - yFitted); } if (0 == residuals.getN()) { return null; } double yMean = yValues.getMean(); double totalSumOfSquares = points.stream().mapToDouble(p -> (p.getY() - yMean) * (p.getY() - yMean)).sum(); double sumOfSquaresOfResiduals = residuals.getSumsq(); double rSquared = 1 - sumOfSquaresOfResiduals / totalSumOfSquares; return rSquared; }
From source file:fr.gael.drb.cortex.topic.sentinel3.jai.operator.QuicklookSlstrRIF.java
private BufferedImage toGrayScale(Raster in, PixelCorrection c, boolean invertColors, boolean ignoreBadStats) { int width = in.getWidth(); int height = in.getHeight(); // compute stats SummaryStatistics stats = new SummaryStatistics(); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int pixel = checkAndApplyCorrection(in.getSample(i, j, 0), c); if (pixel != c.nodata) stats.addValue(pixel); }//from w w w . j av a 2 s . co m } double lowerBound = Math.max(stats.getMin(), stats.getMean() - 3 * stats.getStandardDeviation()); double upperBound = Math.min(stats.getMax(), stats.getMean() + 3 * stats.getStandardDeviation()); if (!ignoreBadStats) if (Double.isNaN(stats.getMean()) || Double.isNaN(stats.getStandardDeviation()) || stats.getStandardDeviation() < 1) throw new IllegalStateException("Ugly band stats. Acquired during night?"); return toGrayScale(in, c, invertColors, lowerBound, upperBound); }
From source file:cl.usach.managedbeans.CreditosManagedBean.java
public double buscarPromedioSprintAsignatura(SprintAsignatura sprintA) { List<SprintGrupos> spgs = buscarSprintGrupos(sprintA); SummaryStatistics stats = new SummaryStatistics(); int a;//from ww w.j ava 2 s. c o m for (SprintGrupos sprintGrupos : spgs) { List<Equipo> eqs = buscarEquipos(sprintGrupos); for (Equipo equipo : eqs) { a = buscarTiempoTareas(equipo); stats.addValue(a); } } double mean = stats.getMean(); mean = (double) Math.round(mean * 10) / 10; return mean; }
From source file:cl.usach.managedbeans.CreditosManagedBean.java
public double buscarDesviacionEstandarSprintAsignatura(SprintAsignatura sprintA) { List<SprintGrupos> spgs = buscarSprintGrupos(sprintA); SummaryStatistics stats = new SummaryStatistics(); int a;//from ww w . j a va 2 s. c om for (SprintGrupos sprintGrupos : spgs) { List<Equipo> eqs = buscarEquipos(sprintGrupos); for (Equipo equipo : eqs) { a = buscarTiempoTareas(equipo); stats.addValue(a); } } double dv = stats.getStandardDeviation(); dv = (double) Math.round(dv * 10) / 10; return dv; }
From source file:ijfx.core.stats.DefaultImageStatisticsService.java
@Override public SummaryStatistics getSummaryStatistics(Dataset dataset) { SummaryStatistics summary = new SummaryStatistics(); Cursor<RealType<?>> cursor = dataset.cursor(); cursor.reset();/*from w w w. j a v a 2 s. c o m*/ while (cursor.hasNext()) { cursor.fwd(); double value = cursor.get().getRealDouble(); summary.addValue(value); } return summary; }
From source file:model.experiments.stickyprices.StickyPricesCSVPrinter.java
private static void oneHundredLearningCompetitive(File file) throws IOException { CSVWriter writer = new CSVWriter(new FileWriter(file)); writer.writeNext(new String[] { "production", "price" }); //this will take a looong time //run the test 5 times! for (long i = 0; i < 100; i++) { //create the run MacroII macroII = new MacroII(i); TripolistScenario scenario = new TripolistScenario(macroII); macroII.setScenario(scenario);//from w w w . ja v a2s . co m scenario.setAdditionalCompetitors(4); //set the demand scenario.setAskPricingStrategy(InventoryBufferSalesControl.class); scenario.setControlType( MonopolistScenario.MonopolistScenarioIntegratedControlEnum.MARGINAL_PLANT_CONTROL); //start it and have one step macroII.start(); macroII.schedule.step(macroII); //now set the right parameters for (Firm firm : scenario.getCompetitors()) { final SalesDepartment salesDepartment = firm.getSalesDepartment(UndifferentiatedGoodType.GENERIC); //learning assert salesDepartment.getPredictorStrategy() instanceof RecursiveSalePredictor; } //run the model for (int j = 0; j < 5000; j++) { macroII.schedule.step(macroII); MarginalMaximizerPIDTuning.printProgressBar(5000, j, 100); } //average over the last 500 steps SummaryStatistics prices = new SummaryStatistics(); SummaryStatistics quantities = new SummaryStatistics(); for (int j = 0; j < 500; j++) { macroII.schedule.step(macroII); assert !Float.isNaN(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice()); prices.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice()); quantities.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayVolume()); } String[] resultString = new String[2]; resultString[0] = String.valueOf(quantities.getMean()); resultString[1] = String.valueOf(prices.getMean()); System.out.println(Arrays.toString(resultString)); writer.writeNext(resultString); writer.flush(); } writer.close(); }
From source file:com.hurence.logisland.sampling.AverageSampler.java
/** * divide the points sequence into equally sized buckets * and select the first point of each bucket * * @param inputRecords the iput list//w w w . j av a 2 s . c om * @return */ @Override public List<Record> sample(List<Record> inputRecords) { SummaryStatistics stats = new SummaryStatistics(); // simple average to 100 data points final int realBucketSize = SamplingUtils.fitBucketSize(inputRecords, bucketSize); return SamplingUtils.grouped(inputRecords, realBucketSize).map(bucket -> { bucket.forEach(record -> { final Double recordValue = getRecordValue(record); if (recordValue != null) stats.addValue(recordValue); }); final double meanValue = stats.getMean(); final Record sampleRecord = getTimeValueRecord(bucket.get(0)); final FieldType fieldType = bucket.get(0).getField(valueFieldName).getType(); switch (fieldType) { case INT: sampleRecord.setField(valueFieldName, fieldType, (int) Math.round(meanValue)); break; case LONG: sampleRecord.setField(valueFieldName, fieldType, Math.round(meanValue)); break; case FLOAT: sampleRecord.setField(valueFieldName, fieldType, (float) meanValue); break; case DOUBLE: sampleRecord.setField(valueFieldName, fieldType, meanValue); break; } return sampleRecord; }).collect(Collectors.toList()); }
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./* ww w .j a va 2 s. c om*/ * 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); }
From source file:model.experiments.stickyprices.StickyPricesCSVPrinter.java
private static void competitiveSweepRun(int additionalCompetitors) throws IOException { CSVWriter writer = new CSVWriter(new FileWriter( Paths.get("runs", "rawdata", "competitivePeriodSweep" + additionalCompetitors + ".csv").toFile())); writer.writeNext(new String[] { "speed", "distance", "finaldistance", "variance" }); for (int speed = 1; speed < 30; speed++) { SummaryStatistics distance = new SummaryStatistics(); SummaryStatistics finalDistance = new SummaryStatistics(); SummaryStatistics variance = new SummaryStatistics(); for (int seed = 0; seed < 50; seed++) { final double[] result = competitiveSweepRun(seed, 101, 1, 1, 14, .1f, .1f, speed, 58, null, additionalCompetitors); distance.addValue(result[0]); finalDistance.addValue(result[1]); variance.addValue(result[2]); }//from ww w . j ava 2s.co m final String[] nextLine = { String.valueOf(speed), String.valueOf(distance.getMean()), String.valueOf(finalDistance.getMean()), String.valueOf(variance.getMean()) }; System.out.println(Arrays.toString(nextLine)); writer.writeNext(nextLine); writer.flush(); } writer.close(); }
From source file:ijfx.ui.plugin.panel.OverlayPanel.java
protected XYChart.Series<Double, Double> getOverlayHistogram(Overlay overlay) { Timer timer = timerService.getTimer(this.getClass()); timer.start();/*from www .j av a 2 s .com*/ Double[] valueList = statsService.getValueList(currentDisplay(), overlay); timer.elapsed("Getting the stats"); SummaryStatistics sumup = new SummaryStatistics(); for (Double v : valueList) { sumup.addValue(v); } timer.elapsed("Building the sumup"); double min = sumup.getMin(); double max = sumup.getMax(); double range = max - min; int bins = 100;//new Double(max - min).intValue(); EmpiricalDistribution distribution = new EmpiricalDistribution(bins); double[] values = ArrayUtils.toPrimitive(valueList); Arrays.parallelSort(values); distribution.load(values); timer.elapsed("Sort and distrubution repartition up"); XYChart.Series<Double, Double> serie = new XYChart.Series<>(); ArrayList<Data<Double, Double>> data = new ArrayList<>(bins); double k = min; for (SummaryStatistics st : distribution.getBinStats()) { data.add(new Data<Double, Double>(k, new Double(st.getN()))); k += range / bins; } serie.getData().clear(); serie.getData().addAll(data); timer.elapsed("Creating charts"); return serie; }