List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics getMean
public double getMean()
From source file:cl.usach.managedbeans.CreditosManagedBean.java
public double buscarPromedioSrpintGrupo(SprintGrupos springG) { List<Equipo> eqs = buscarEquipos(springG); SummaryStatistics stats = new SummaryStatistics(); int s;/*ww w .j a v a 2 s . com*/ for (Equipo equipo : eqs) { s = buscarTiempoTareas(equipo); stats.addValue(s); } double mean = stats.getMean(); mean = (double) Math.round(mean * 10) / 10; return mean; }
From source file:com.github.rinde.rinsim.util.StochasticSuppliersTest.java
/** * Tests whether the rescaling of the mean of a truncated normal distribution * is implemented correctly.// ww w. j ava2 s .c o m */ @Test public void testNormalScaleMean() { final double[] means = new double[] { 1d, 2d, 3d, 10d, 100d }; final double[] sds = new double[] { 1d, 1d, 3d, 5d, 100d }; for (int i = 0; i < means.length; i++) { final StochasticSupplier<Double> ss = StochasticSuppliers.normal().mean(means[i]).std(sds[i]) .lowerBound(0).scaleMean().redrawWhenOutOfBounds().buildDouble(); final RandomGenerator rng = new MersenneTwister(123); final SummaryStatistics stats = new SummaryStatistics(); for (int j = 0; j < 10000; j++) { stats.addValue(ss.get(rng.nextLong())); } // 1 % deviation from mean is acceptable final double allowedDeviation = 0.01 * means[i]; assertEquals(means[i], stats.getMean(), allowedDeviation); } }
From source file:net.recommenders.rival.evaluation.statistics.ConfidenceInterval.java
/** * Method that takes only one metric as parameter. It is useful when * comparing more than two metrics (so that a confidence interval is * computed for each of them), as suggested in [Sakai, 2014] * * @param alpha probability of incorrectly rejecting the null hypothesis (1 * - confidence_level)/* w w w .j a v a2 s.c o m*/ * @param metricValuesPerDimension one value of the metric for each * dimension * @return array with the confidence interval: [mean - margin of error, mean * + margin of error] */ public double[] getConfidenceInterval(final double alpha, final Map<?, Double> metricValuesPerDimension) { SummaryStatistics differences = new SummaryStatistics(); for (Double d : metricValuesPerDimension.values()) { differences.addValue(d); } return getConfidenceInterval(alpha, (int) differences.getN() - 1, (int) differences.getN(), differences.getStandardDeviation(), differences.getMean()); }
From source file:model.scenario.SimpleBuyerScenarioTest.java
@Test public void rightPriceAndQuantityTestWithCascadeControllerFixed4Buyers() { for (int i = 0; i < 20; i++) { //to sell 4 you need to price them between 60 and 51 everytime final MacroII macroII = new MacroII(System.currentTimeMillis()); SimpleBuyerScenario scenario = new SimpleBuyerScenario(macroII); scenario.setControllerType(CascadePIDController.class); scenario.setTargetInventory(20); scenario.setConsumptionRate(4);/*from w w w.j av a2 s . c o m*/ scenario.setNumberOfBuyers(4); scenario.setNumberOfSuppliers(50); scenario.setSupplyIntercept(0); scenario.setSupplySlope(1); //4 buyers, buying 4 each, should be 16 units in total macroII.setScenario(scenario); macroII.start(); for (PurchasesDepartment department : scenario.getDepartments()) department.setTradePriority(Priority.BEFORE_STANDARD); while (macroII.schedule.getTime() < 3500) { System.out.println("--------------------------------"); macroII.schedule.step(macroII); for (PurchasesDepartment department : scenario.getDepartments()) System.out.println("inflow: " + department.getTodayInflow() + ", price: " + department.getLastOfferedPrice() + ", averaged: " + department.getAveragedClosingPrice()); } SummaryStatistics averagePrice = new SummaryStatistics(); for (int j = 0; j < 1000; j++) { macroII.schedule.step(macroII); averagePrice.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getLastPrice()); } //price should be any between 60 and 51 assertEquals(16, averagePrice.getMean(), .5d); assertEquals(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getYesterdayVolume(), 16, 1d); //every day 4 goods should have been traded } }
From source file:model.scenario.OneLinkSupplyChainResult.java
public static OneLinkSupplyChainResult everybodyLearnedCompetitivePIDRun(long random, final float dividePIByThis, final int beefPricingSpeed, File csvFileToWrite) { final MacroII macroII = new MacroII(random); final OneLinkSupplyChainScenarioWithCheatingBuyingPrice scenario1 = new OneLinkSupplyChainScenarioWithCheatingBuyingPrice( macroII) {/* ww w . jav a2 s . c o m*/ @Override protected void buildBeefSalesPredictor(SalesDepartment dept) { FixedDecreaseSalesPredictor predictor = SalesPredictor.Factory .newSalesPredictor(FixedDecreaseSalesPredictor.class, dept); predictor.setDecrementDelta(0); dept.setPredictorStrategy(predictor); } @Override public void buildFoodPurchasesPredictor(PurchasesDepartment department) { department.setPredictor(new FixedIncreasePurchasesPredictor(0)); } @Override protected SalesDepartment createSalesDepartment(Firm firm, Market goodmarket) { SalesDepartment department = super.createSalesDepartment(firm, goodmarket); if (goodmarket.getGoodType().equals(OneLinkSupplyChainScenario.OUTPUT_GOOD)) department.setPredictorStrategy(new FixedDecreaseSalesPredictor(0)); return department; } @Override protected HumanResources createPlant(Blueprint blueprint, Firm firm, Market laborMarket) { HumanResources hr = super.createPlant(blueprint, firm, laborMarket); hr.setPredictor(new FixedIncreasePurchasesPredictor(0)); return hr; } }; scenario1.setControlType(MarginalMaximizer.class); scenario1.setSalesDepartmentType(SalesDepartmentOneAtATime.class); scenario1.setBeefPriceFilterer(null); //competition! scenario1.setNumberOfBeefProducers(5); scenario1.setNumberOfFoodProducers(5); scenario1.setDivideProportionalGainByThis(dividePIByThis); scenario1.setDivideIntegrativeGainByThis(dividePIByThis); //no delay scenario1.setBeefPricingSpeed(beefPricingSpeed); //add csv writer if needed if (csvFileToWrite != null) DailyStatCollector.addDailyStatCollectorToModel(csvFileToWrite, macroII); macroII.setScenario(scenario1); macroII.start(); while (macroII.schedule.getTime() < 14000) { macroII.schedule.step(macroII); } //I used to assert this: //Assert.assertEquals(macroII.getMarket(OneLinkSupplyChainScenario.OUTPUT_GOOD).getLatestObservation(MarketDataType.AVERAGE_CLOSING_PRICE),85l,6l ); //but that's too hard because while on average the price hovers there, competition is noisy. Sometimes a lot. //so what I did was to attach a daily stat collector and then check the average of the last 10 prices SummaryStatistics averageFoodPrice = new SummaryStatistics(); SummaryStatistics averageBeefProduced = new SummaryStatistics(); SummaryStatistics averageBeefPrice = new SummaryStatistics(); for (int j = 0; j < 1000; j++) { //make the model run one more day: macroII.schedule.step(macroII); averageFoodPrice.addValue(macroII.getMarket(OneLinkSupplyChainScenario.OUTPUT_GOOD) .getLatestObservation(MarketDataType.AVERAGE_CLOSING_PRICE)); averageBeefProduced.addValue(macroII.getMarket(OneLinkSupplyChainScenario.INPUT_GOOD) .countTodayProductionByRegisteredSellers()); averageBeefPrice.addValue(macroII.getMarket(OneLinkSupplyChainScenario.INPUT_GOOD) .getLatestObservation(MarketDataType.AVERAGE_CLOSING_PRICE)); } System.out.println("beef price: " + averageBeefPrice.getMean()); System.out.println("food price: " + averageFoodPrice.getMean()); System.out.println("produced: " + averageBeefProduced.getMean()); extractAndPrintSlopesOfBeefSellers(macroII); System.out.println(); macroII.finish(); return new OneLinkSupplyChainResult(averageBeefPrice.getMean(), averageFoodPrice.getMean(), averageBeefProduced.getMean(), macroII); }
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 www . j a v a 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:gdsc.smlm.results.filter.HysteresisFilter.java
@Override public void setup(MemoryPeakResults peakResults) { ok = new HashSet<PeakResult>(); // Create a set of candidates and valid peaks MemoryPeakResults traceResults = new MemoryPeakResults(); // Initialise peaks to check LinkedList<PeakResult> candidates = new LinkedList<PeakResult>(); for (PeakResult result : peakResults.getResults()) { switch (getStatus(result)) { case OK:/*from w ww . j a v a2 s .c o m*/ ok.add(result); traceResults.add(result); break; case CANDIDATE: candidates.add(result); traceResults.add(result); break; default: break; } } if (candidates.isEmpty()) return; // Find average precision of the candidates and use it for the search // distance SummaryStatistics stats = new SummaryStatistics(); final double nmPerPixel = peakResults.getNmPerPixel(); final double gain = peakResults.getGain(); final boolean emCCD = peakResults.isEMCCD(); for (PeakResult peakResult : candidates) { stats.addValue(peakResult.getPrecision(nmPerPixel, gain, emCCD)); } double distanceThreshold = stats.getMean() * searchDistance / nmPerPixel; // Trace through candidates TraceManager tm = new TraceManager(traceResults); tm.setTraceMode(TraceMode.LATEST_FORERUNNER); tm.traceMolecules(distanceThreshold, 1); Trace[] traces = tm.getTraces(); for (Trace trace : traces) { if (trace.size() > 1) { // Check if the trace touches a valid point boolean isOk = false; for (PeakResult result : trace.getPoints()) { if (ok.contains(result)) { isOk = true; break; } ok.add(result); } // Add the entire trace to the OK points if (isOk) { for (PeakResult result : trace.getPoints()) { ok.add(result); } } } } }
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 www .ja v a2 s.c o 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:net.adamjak.thomas.graph.application.gui.ResultsWidnow.java
private JTable createJtResults() { if (this.results.containsKey("resultsData")) { GraphTestResult[][] results = (GraphTestResult[][]) this.results.get("resultsData"); String[] columnNames = { "Graph ID", "Avarage time", "Standard deviation", "Minimum", "Maximum" }; Object[][] data = new Object[results[0].length][5]; for (int graph = 0; graph < results[0].length; graph++) { SummaryStatistics summaryStatistics = new SummaryStatistics(); for (int run = 0; run < results.length; run++) { summaryStatistics.addValue((double) results[run][graph].getValue("timeInSeconds")); }//w ww.j a va 2 s. c o m data[graph][0] = graph; data[graph][1] = summaryStatistics.getMean(); data[graph][2] = summaryStatistics.getStandardDeviation(); data[graph][3] = summaryStatistics.getMin(); data[graph][4] = summaryStatistics.getMax(); } return new JTable(data, columnNames); } else { String[] columnNames = { "Description", "Result" }; Object[][] data = new Object[this.results.keySet().size()][2]; int i = 0; for (String key : this.results.keySet()) { data[i][0] = key; data[i][1] = this.results.get(key); i++; } return new JTable(data, columnNames); } }
From source file:model.scenario.OneLinkSupplyChainResult.java
public static OneLinkSupplyChainResult foodMonopolistOneRun(long random, float divideMonopolistGainsByThis, int beefSpeed, final boolean beefLearned, final boolean foodLearned, File csvFileToWrite, Path regressionCSV) {//from w w w. j a va 2s . c o m final MacroII macroII = new MacroII(random); final OneLinkSupplyChainScenarioWithCheatingBuyingPrice scenario1 = new OneLinkSupplyChainScenarioWithCheatingBuyingPrice( macroII) { @Override protected void buildBeefSalesPredictor(SalesDepartment dept) { if (beefLearned) { FixedDecreaseSalesPredictor predictor = SalesPredictor.Factory .newSalesPredictor(FixedDecreaseSalesPredictor.class, dept); predictor.setDecrementDelta(0); dept.setPredictorStrategy(predictor); } else { } } @Override public void buildFoodPurchasesPredictor(PurchasesDepartment department) { if (foodLearned) department.setPredictor(new FixedIncreasePurchasesPredictor(1)); else { final ErrorCorrectingPurchasePredictor predictor = new ErrorCorrectingPurchasePredictor(macroII, department); try { if (regressionCSV != null) predictor.setDebugWriter(regressionCSV); } catch (IOException e) { e.printStackTrace(); } department.setPredictor(predictor); } } @Override protected SalesDepartment createSalesDepartment(Firm firm, Market goodmarket) { SalesDepartment department = super.createSalesDepartment(firm, goodmarket); if (goodmarket.getGoodType().equals(OneLinkSupplyChainScenario.OUTPUT_GOOD)) { if (foodLearned) department.setPredictorStrategy(new FixedDecreaseSalesPredictor(1)); } return department; } @Override protected HumanResources createPlant(Blueprint blueprint, Firm firm, Market laborMarket) { HumanResources hr = super.createPlant(blueprint, firm, laborMarket); if (blueprint.getOutputs().containsKey(OneLinkSupplyChainScenario.INPUT_GOOD)) { if (beefLearned) { hr.setPredictor(new FixedIncreasePurchasesPredictor(0)); } } if (blueprint.getOutputs().containsKey(OneLinkSupplyChainScenario.OUTPUT_GOOD)) { if (foodLearned) hr.setPredictor(new FixedIncreasePurchasesPredictor(1)); } return hr; } }; scenario1.setControlType(MarginalMaximizer.class); scenario1.setSalesDepartmentType(SalesDepartmentOneAtATime.class); scenario1.setBeefPriceFilterer(null); //competition! scenario1.setNumberOfBeefProducers(5); scenario1.setBeefTargetInventory(100); scenario1.setNumberOfFoodProducers(1); scenario1.setFoodTargetInventory(100); scenario1.setDivideProportionalGainByThis(divideMonopolistGainsByThis); scenario1.setDivideIntegrativeGainByThis(divideMonopolistGainsByThis); //no delay scenario1.setBeefPricingSpeed(beefSpeed); //add csv writer if needed if (csvFileToWrite != null) DailyStatCollector.addDailyStatCollectorToModel(csvFileToWrite, macroII); macroII.setScenario(scenario1); macroII.start(); while (macroII.schedule.getTime() < 14000) { macroII.schedule.step(macroII); } SummaryStatistics averageFoodPrice = new SummaryStatistics(); SummaryStatistics averageBeefProduced = new SummaryStatistics(); SummaryStatistics averageBeefPrice = new SummaryStatistics(); for (int j = 0; j < 1000; j++) { //make the model run one more day: macroII.schedule.step(macroII); averageFoodPrice.addValue(macroII.getMarket(OneLinkSupplyChainScenario.OUTPUT_GOOD) .getLatestObservation(MarketDataType.AVERAGE_CLOSING_PRICE)); averageBeefProduced .addValue(macroII.getMarket(OneLinkSupplyChainScenario.INPUT_GOOD).getYesterdayVolume()); averageBeefPrice.addValue(macroII.getMarket(OneLinkSupplyChainScenario.INPUT_GOOD) .getLatestObservation(MarketDataType.AVERAGE_CLOSING_PRICE)); } System.out.println("seed: " + random); System.out.println("beef price: " + averageBeefPrice.getMean()); System.out.println("food price: " + averageFoodPrice.getMean()); System.out.println("produced: " + averageBeefProduced.getMean()); extractAndPrintSlopesOfBeefSellers(macroII); System.out.println(); ((Firm) (macroII.getMarket(OneLinkSupplyChainScenario.OUTPUT_GOOD).getSellers().iterator().next())) .getPurchaseDepartment(OneLinkSupplyChainScenario.INPUT_GOOD).getData() .writeToCSVFile(Paths.get("runs", "purchases.csv").toFile()); macroII.finish(); return new OneLinkSupplyChainResult(averageBeefPrice.getMean(), averageFoodPrice.getMean(), averageBeefProduced.getMean(), macroII); }