List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics getMean
public double getMean()
From source file:model.experiments.tuningRuns.CompetitiveAveragingGridSearch.java
public static CompetitiveAveragingResult exponentialRuns(float hrWeight, PriceAverager.NoTradingDayPolicy hrPolicy, float salesWeight, PriceAverager.NoTradingDayPolicy salesPolicy, int maximizerAveragePeriod) { SummaryStatistics averageResultingPrice = new SummaryStatistics(); SummaryStatistics averageResultingQuantity = new SummaryStatistics(); SummaryStatistics averageStandardDeviation = new SummaryStatistics(); for (int i = 0; i < 5; i++) { final MacroII macroII = new MacroII(i); final TripolistScenario scenario1 = new TripolistScenario(macroII); scenario1.setSalesDepartmentType(SalesDepartmentOneAtATime.class); scenario1.setAskPricingStrategy(SalesControlWithFixedInventoryAndPID.class); scenario1.setControlType(//from w w w . j a v a 2s . c o m MonopolistScenario.MonopolistScenarioIntegratedControlEnum.MARGINAL_PLANT_CONTROL); scenario1.setAdditionalCompetitors(4); scenario1.setWorkersToBeRehiredEveryDay(true); scenario1.setDemandIntercept(102); scenario1.setSalesPricePreditorStrategy(FixedDecreaseSalesPredictor.class); //assign scenario macroII.setScenario(scenario1); macroII.start(); macroII.schedule.step(macroII); for (Firm firm : scenario1.getCompetitors()) { for (HumanResources hr : firm.getHRs()) { hr.setPredictor(new FixedIncreasePurchasesPredictor(0)); hr.setPriceAverager(new ExponentialPriceAverager(hrWeight, hrPolicy)); } firm.getSalesDepartment(UndifferentiatedGoodType.GENERIC) .setPriceAverager(new ExponentialPriceAverager(salesWeight, salesPolicy)); firm.getSalesDepartment(UndifferentiatedGoodType.GENERIC) .setPredictorStrategy(new FixedDecreaseSalesPredictor(0)); } for (final PlantControl control : scenario1.getMaximizers()) { ((MarginalPlantControl) control).getMaximizer() .setHowManyDaysBeforeEachCheck(maximizerAveragePeriod); } while (macroII.schedule.getTime() < 10000) { macroII.schedule.step(macroII); } SummaryStatistics prices = new SummaryStatistics(); SummaryStatistics quantities = new SummaryStatistics(); for (int j = 0; j < 500; j++) { macroII.schedule.step(macroII); prices.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice()); quantities.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayVolume()); } //okay? averageResultingPrice.addValue(prices.getMean()); averageResultingQuantity.addValue(quantities.getMean()); averageStandardDeviation.addValue(prices.getStandardDeviation()); } //okay? return new CompetitiveAveragingResult(averageResultingPrice.getMean(), averageResultingQuantity.getMean(), averageStandardDeviation.getMean()); }
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:net.sourceforge.jabm.report.AbstractReportVariables.java
public void recordSummaryStatistics(Object statName, Map<Object, Number> variables, SummaryStatistics stats) { variables.put(createVariable(statName + ".mean"), stats.getMean()); variables.put(createVariable(statName + ".min"), stats.getMin()); variables.put(createVariable(statName + ".max"), stats.getMax()); variables.put(createVariable(statName + ".n"), stats.getN()); variables.put(createVariable(statName + ".stdev"), stats.getStandardDeviation()); }
From source file:ijfx.plugins.MeanProjection.java
@Override public <T extends RealType<T>> void process(List<T> list, Sampler<T> sampler) { SummaryStatistics summaryStatistics = new SummaryStatistics(); list.stream().forEach((t) -> summaryStatistics.addValue(t.getRealDouble())); //Set result/*ww w . j a v a 2s.c o m*/ sampler.get().setReal(summaryStatistics.getMean()); }
From source file:model.experiments.LearningSupplyChainExperiment.java
public static void monopolist(final boolean beefLearned, final boolean foodLearned, long seed) { final MacroII macroII = new MacroII(seed); final OneLinkSupplyChainScenarioWithCheatingBuyingPrice scenario1 = new OneLinkSupplyChainScenarioWithCheatingBuyingPrice( macroII) {//from w w w . j ava2s.co m @Override protected void buildBeefSalesPredictor(SalesDepartment dept) { if (beefLearned) { FixedDecreaseSalesPredictor predictor = SalesPredictor.Factory .newSalesPredictor(FixedDecreaseSalesPredictor.class, dept); predictor.setDecrementDelta(2); dept.setPredictorStrategy(predictor); } else { assert dept.getPredictorStrategy() instanceof RecursiveSalePredictor; //assuming here nothing has been changed and we are still dealing with recursive sale predictors dept.setPredictorStrategy(new RecursiveSalePredictor(model, dept, 500)); } } @Override public void buildFoodPurchasesPredictor(PurchasesDepartment department) { if (foodLearned) 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)) { if (foodLearned) department.setPredictorStrategy(new FixedDecreaseSalesPredictor(0)); } 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(1)); } } if (blueprint.getOutputs().containsKey(OneLinkSupplyChainScenario.OUTPUT_GOOD)) { if (foodLearned) hr.setPredictor(new FixedIncreasePurchasesPredictor(0)); } return hr; } }; scenario1.setControlType(MarginalMaximizer.class); scenario1.setSalesDepartmentType(SalesDepartmentOneAtATime.class); scenario1.setBeefPriceFilterer(null); //competition! scenario1.setNumberOfBeefProducers(1); scenario1.setNumberOfFoodProducers(5); scenario1.setDivideProportionalGainByThis(100f); scenario1.setDivideIntegrativeGainByThis(100f); //no delay scenario1.setBeefPricingSpeed(0); scenario1.setBeefTargetInventory(1000); try { File toWriteTo = Paths.get("runs", "supplychai", "beefshouldlearn.csv").toFile(); CSVWriter writer = new CSVWriter(new FileWriter(toWriteTo)); DailyStatCollector collector = new DailyStatCollector(macroII, writer); collector.start(); } catch (IOException e) { System.err.println("failed to create the file!"); } macroII.setScenario(scenario1); macroII.start(); while (macroII.schedule.getTime() < 14000) { macroII.schedule.step(macroII); printProgressBar(14001, (int) macroII.schedule.getSteps(), 100); } 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)); } ((Firm) macroII.getMarket(OneLinkSupplyChainScenario.OUTPUT_GOOD).getSellers().iterator().next()) .getPurchaseDepartment(OneLinkSupplyChainScenario.INPUT_GOOD).getData() .writeToCSVFile(Paths.get("runs", "supplychai", "beefBuying.csv").toFile()); System.out.println("beef price: " + averageBeefPrice.getMean()); System.out.println("food price: " + averageFoodPrice.getMean()); System.out.println("produced: " + averageBeefProduced.getMean()); System.out.println(); System.out.flush(); }
From source file:ijfx.core.timer.DefaultTimer.java
protected String getRow(String id, SummaryStatistics statics) { return String.format("%30s | %6.0fms | %6.0fms | %8d\n", id.length() > 22 ? id.substring(0, 21) : id, statics.getMean(), statics.getStandardDeviation(), statics.getN()); }
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); }/*from ww w .ja v a 2 s . co m*/ 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:eu.crydee.alignment.aligner.ae.MetricsSummaryAE.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { try {/*from ww w . jav a2 s. c o m*/ String template = IOUtils.toString(getClass() .getResourceAsStream("/eu/crydee/alignment/aligner/ae/" + "metrics-summarizer-template.html")); String titledTemplate = template.replace("@@TITLE@@", "Metrics summarizer" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); StringBuilder sb = new StringBuilder(); sb.append("<table class=\"table table-striped ").append("table-condensed\">\n") .append(" <thead>\n").append(" <tr>\n") .append(" <th>City\\Metric</th>\n"); for (String key : keys) { sb.append(" <th>").append(methodsMetadata.get(key).getRight()).append("</th>\n"); } sb.append(" <tr>\n").append(" </thead>\n").append(" <tbody>\n"); for (String ele : results.rowKeySet()) { sb.append(" <tr>\n").append(" <td>").append(ele) .append("</td>\n"); Map<String, Samples> metricResults = results.row(ele); for (String key : keys) { Samples samples = metricResults.get(key); SummaryStatistics ss = new SummaryStatistics(); samples.samples.forEach(d -> ss.addValue(d)); double mean = ss.getMean(); boolean significant = TestUtils.tTest(samples.mu, ArrayUtils.toPrimitive(samples.samples.toArray(new Double[0])), 0.05), above = samples.mu > mean; String summary = String.format("%.3f", samples.mu) + " <small class=\"text-muted\">" + String.format("%.3f", ss.getMean()) + "" + String.format("%.3f", ss.getStandardDeviation()) + "</small>"; logger.info(ele + "\t" + key + "\t" + summary + "\t" + significant); sb.append(" <td class=\"") .append(significant ? (above ? "success" : "danger") : "warning").append("\">") .append(summary).append("</td>\n"); } sb.append(" </tr>\n"); } sb.append(" </tbody>\n").append(" </table>"); FileUtils.write(new File(htmlFilepath), titledTemplate.replace("@@TABLE@@", sb.toString()), StandardCharsets.UTF_8); } catch (IOException ex) { logger.error("IO problem with the HTML output."); throw new AnalysisEngineProcessException(ex); } }
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/*from www .j av a2 s . co m*/ * @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:gdsc.utils.HSB_Picker.java
private String summary(SummaryStatistics stats) { return String.format("%.3f +/- %.4f", stats.getMean(), stats.getStandardDeviation()); }