List of usage examples for org.apache.commons.math3.stat.descriptive.moment Mean Mean
public Mean()
From source file:org.jpmml.evaluator.functions.MeanFunction.java
static private Double evaluate(Collection<?> values) { Mean mean = new Mean(); for (Object value : values) { Double doubleValue = (Double) TypeUtil.parseOrCast(DataType.DOUBLE, value); mean.increment(doubleValue.doubleValue()); }//from w w w.j a va 2 s .c o m return mean.getResult(); }
From source file:org.lenskit.eval.traintest.recommend.TopNLengthMetric.java
@Nullable @Override public Mean createContext(AlgorithmInstance algorithm, DataSet dataSet, RecommenderEngine engine) { return new Mean(); }
From source file:pathwaynet.PathwayCalculator.java
private <E> TestResultForList testForGivenListWilcoxBased(Graph<E, String> graph, Collection<E> componentsInGroup, Collection<E> componentsConsidered, boolean onlyFromSource) { double p = Double.NaN; double meanInGroup = Double.NaN; double meanOutGroup = Double.NaN; // calculate and cache all distances DijkstraDistance<E, String> distances = new DijkstraDistance<>(graph); HashMap<E, Map<E, Number>> distancesMap = new HashMap<>(); graph.getVertices().stream().forEach((component) -> { Map<E, Number> distancesFromThis = distances.getDistanceMap(component); distancesMap.put(component, distancesFromThis); });/*from w ww .j a v a 2 s .co m*/ // generate in-group list and out-group list HashSet<E> componentsInGroupAvailable = new HashSet<>(); HashSet<E> componentsOutGroupAvailable = new HashSet<>(); componentsInGroupAvailable.addAll(graph.getVertices()); componentsOutGroupAvailable.addAll(graph.getVertices()); componentsInGroupAvailable.retainAll(componentsConsidered); componentsOutGroupAvailable.retainAll(componentsConsidered); componentsInGroupAvailable.retainAll(componentsInGroup); componentsOutGroupAvailable.removeAll(componentsInGroup); // store within-group distances for the given list, as well as distances between components in the list and ones out of the list ArrayList<Double> distInGroup = new ArrayList<>(); ArrayList<Double> distOutGroup = new ArrayList<>(); componentsInGroupAvailable.forEach((component1) -> { componentsInGroupAvailable.forEach((component2) -> { Number minDist = getShortestDistance(distancesMap, component1, component2, onlyFromSource); if (!component1.equals(component2) && minDist != null) { distInGroup.add(minDist.doubleValue()); } }); componentsOutGroupAvailable.forEach((component2) -> { Number minDist = getShortestDistance(distancesMap, component1, component2, onlyFromSource); if (!component1.equals(component2) && minDist != null) { distOutGroup.add(minDist.doubleValue()); } }); }); if (distInGroup.size() >= 2 && distOutGroup.size() >= 2) { double[] distInGroupVector = new double[distInGroup.size()]; double[] distOutGroupVector = new double[distOutGroup.size()]; for (int i = 0; i < distInGroup.size(); i++) distInGroupVector[i] = distInGroup.get(i); for (int i = 0; i < distOutGroup.size(); i++) distOutGroupVector[i] = distOutGroup.get(i); p = new MannWhitneyUTest().mannWhitneyUTest(distInGroupVector, distOutGroupVector); //System.err.println(distInGroup+"\t"+distOutGroup); meanInGroup = new Mean().evaluate(distInGroupVector); meanOutGroup = new Mean().evaluate(distOutGroupVector); } else { System.err.println("Error: please check your list: too few components involving in the pathway"); } return new TestResultForList(p, meanInGroup, meanOutGroup); }
From source file:pathwaynet.PathwayCalculator.java
private <E> TestResultForList testForGivenListPermutationBased(Graph<E, String> graph, Collection<E> componentsInGroup, Collection<E> componentsConsidered, boolean onlyFromSource) { // calculate and cache all distances DijkstraDistance<E, String> distances = new DijkstraDistance<>(graph); HashMap<E, Map<E, Number>> distancesMap = new HashMap<>(); graph.getVertices().stream().forEach((component) -> { Map<E, Number> distancesFromThis = distances.getDistanceMap(component); distancesMap.put(component, distancesFromThis); });/*w w w . ja v a 2s. co m*/ // generate in-group list and all-available list HashSet<E> componentsInGroupAvailable = new HashSet<>(); componentsInGroupAvailable.addAll(graph.getVertices()); componentsInGroupAvailable.retainAll(componentsConsidered); componentsInGroupAvailable.retainAll(componentsInGroup); HashSet<E> componentsAvailable = new HashSet<>(); componentsAvailable.addAll(graph.getVertices()); componentsAvailable.retainAll(componentsConsidered); // store within-group distances for the given list if (componentsInGroupAvailable.size() < 2 || componentsInGroupAvailable.size() > componentsAvailable.size() - 2) { System.err.println( "ERROE! Please check your component list: too few or too many components in the list."); return new TestResultForList(Double.NaN, Double.NaN, Double.NaN); } ArrayList<Double> distInGroup = new ArrayList<>(); componentsInGroupAvailable.forEach((component1) -> { componentsInGroupAvailable.forEach((component2) -> { Number minDist = getShortestDistance(distancesMap, component1, component2, onlyFromSource); if (!component1.equals(component2) && minDist != null) { distInGroup.add(minDist.doubleValue()); } }); }); double[] distInGroupVector = new double[distInGroup.size()]; for (int i = 0; i < distInGroup.size(); i++) distInGroupVector[i] = distInGroup.get(i); double meanInGroup = new Mean().evaluate(distInGroupVector); // permutations ArrayList<Double> meansInPermutGroups = new ArrayList<>(); ArrayList<HashSet<E>> permutatedGroups = generatePermutatedGroups(componentsAvailable, componentsInGroupAvailable.size()); permutatedGroups.forEach((componentsInPermutatedGroup) -> { ArrayList<Double> distInPermutGroup = new ArrayList<>(); componentsInPermutatedGroup.forEach((component1) -> { componentsInPermutatedGroup.forEach((component2) -> { Number minDist = getShortestDistance(distancesMap, component1, component2, onlyFromSource); if (!component1.equals(component2) && minDist != null) { distInPermutGroup.add(minDist.doubleValue()); } }); }); double[] distInPermutGroupVector = new double[distInPermutGroup.size()]; for (int i = 0; i < distInPermutGroup.size(); i++) distInPermutGroupVector[i] = distInPermutGroup.get(i); meansInPermutGroups.add(new Mean().evaluate(distInPermutGroupVector)); }); double[] meansInPermutGroupsVector = new double[meansInPermutGroups.size()]; for (int i = 0; i < meansInPermutGroups.size(); i++) meansInPermutGroupsVector[i] = meansInPermutGroups.get(i); double medianPermut = new Median().evaluate(meansInPermutGroupsVector); double p = ((double) meansInPermutGroups.stream().filter(notGreaterThan(meanInGroup)).count()) / meansInPermutGroups.size(); return new TestResultForList(p, meanInGroup, medianPermut); }
From source file:pt.minha.calibration.AbstractBenchmark.java
protected Result stop(boolean interarrival) { double cpu = ((double) (mxbean.getCurrentThreadCpuTime() - cputime)) / idx; if (interarrival) { for (int i = idx - 1; i > 0; i--) times[i] -= times[i - 1];//w w w . j ava2 s. c om begin = 1; } Mean mean = new Mean(); double m = mean.evaluate(times, begin, idx - begin); Variance var = new Variance(); double v = var.evaluate(times, m, begin, idx - begin); return new Result(m, v, cpu); }
From source file:ro.hasna.ts.math.normalization.ZNormalizer.java
public ZNormalizer() { this(new Mean(), new StandardDeviation(false)); }
From source file:ro.hasna.ts.math.representation.PiecewiseLinearAggregateApproximation.java
/** * Transform a given sequence of values using the algorithm PLAA. * * @param values the sequence of values//from w w w . ja v a 2 s .c o m * @return the result of the transformation */ public MeanSlopePair[] transform(double[] values) { int len = values.length; if (len < segments) { throw new ArrayLengthIsTooSmallException(len, segments, true); } int modulo = len % segments; if (modulo != 0) { throw new ArrayLengthIsNotDivisibleException(len, segments); } MeanSlopePair[] reducedValues = new MeanSlopePair[segments]; int segmentSize = len / segments; double[] x = new double[segmentSize]; for (int i = 0; i < segmentSize; i++) { x[i] = i + 1; } double variance = new Variance(true).evaluate(x); for (int i = 0; i < segments; i++) { double[] y = new double[segmentSize]; System.arraycopy(values, i * segmentSize, y, 0, segmentSize); double covariance = new Covariance().covariance(x, y, true); double mean = new Mean().evaluate(y); reducedValues[i] = new MeanSlopePair(mean, covariance / variance); } return reducedValues; }
From source file:Rotationforest.Covariance.java
/** * Computes the covariance between the two arrays. * * <p>Array lengths must match and the common length must be at least 2.</p> * * @param xArray first data array//from w w w. jav a 2 s. c o m * @param yArray second data array * @param biasCorrected if true, returned value will be bias-corrected * @return returns the covariance for the two arrays * @throws MathIllegalArgumentException if the arrays lengths do not match or * there is insufficient data */ public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected) throws MathIllegalArgumentException { Mean mean = new Mean(); double result = 0d; int length = xArray.length; if (length != yArray.length) { throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length); } else if (length < 2) { throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, length, 2); } else { double xMean = mean.evaluate(xArray); double yMean = mean.evaluate(yArray); for (int i = 0; i < length; i++) { double xDev = xArray[i] - xMean; double yDev = yArray[i] - yMean; result += (xDev * yDev - result) / (i + 1); } } return biasCorrected ? result * ((double) length / (double) (length - 1)) : result; }
From source file:umd.lu.thesis.pums2010.DurPredictStDev.java
public static void main(String[] args) throws Exception { DurationPrediction dp = new DurationPrediction(); File f = new File(ThesisProperties.getProperties("simulation.pums2010.duration.prediction.output")); String line;/* ww w . j a v a 2s. c o m*/ Person2010 p = new Person2010(); int d = -1; int toy = -1; // init predictionDiffs for all runs; this is the final result. HashMap<Integer, double[]> predictionDiffs = new HashMap<>(); for (int i = 0; i < obsCount; i++) { double[] tmpList = new double[runCounts]; predictionDiffs.put(i, tmpList); } HashMap<Integer, Double> predictions = new HashMap<>(); for (int count = 0; count < runCounts; count++) { System.out.println(" " + count + "/" + runCounts); // init observations and predictions for each run/file HashMap<Integer, Double> observations = new HashMap<>(); for (int i = 0; i < obsCount; i++) { observations.put(i, 0.0); predictions.put(i, 0.0); } try (FileInputStream fstream = new FileInputStream( ThesisProperties.getProperties("simulation.pums2010.duration.prediction.input")); BufferedReader br = new BufferedReader(new InputStreamReader(fstream));) { while ((line = br.readLine()) != null) { if (!line.toLowerCase().startsWith("id")) { // Columns needed: EG(137), BO(67), BR(70), BW(75), CP(94), CZ(104), CG(85) d = Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.eg, line)); p.setHhType(Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.bo, line))); p.setNp(Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.br, line))); p.setIncLevel(Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.bw, line))); p.setEmpStatus(Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.cp, line))); toy = Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.cz, line)); p.setAge(Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.cg, line))); Integer durPrediction = dp.findTourDuration(p, d, TripType.BUSINESS, toy); Integer durObservation = Integer .parseInt(ExcelUtils.getColumnValue(ExcelUtils.db, line)) > 29 ? 29 : Integer.parseInt(ExcelUtils.getColumnValue(ExcelUtils.db, line)); observations.put(durObservation, observations.get(durObservation) + 1); // durPrediction is 1 to 30. Hence the minus 1. if (durPrediction < 1 || durPrediction > obsCount) { System.out.println("*** ERROR: durPrediction too large/small: " + durPrediction); System.exit(1); } predictions.put(durPrediction - 1, predictions.get(durPrediction - 1) + 1); } } // calculate diffs: for (int i = 0; i < obsCount; i++) { predictionDiffs.get(i)[count] = predictions.get(i); } br.close(); } catch (Exception ex) { System.out.println("---------------------" + d); System.out.println("---------- "); for (int key : predictions.keySet()) { System.out.println("-- key: " + key + ", value: " + predictions.get(key)); } sLog.error(ex.getLocalizedMessage(), ex); System.exit(1); } } // output results try (FileWriter fw = new FileWriter(f); BufferedWriter bw = new BufferedWriter(fw)) { for (int i = 0; i < obsCount; i++) { StandardDeviation stDevInstance = new StandardDeviation(); double stDev = stDevInstance.evaluate(predictionDiffs.get(i)); Mean avgInstance = new Mean(); double avg = avgInstance.evaluate(predictionDiffs.get(i)); bw.write(i + "\t" + avg + "\t" + stDev + "\n"); } } catch (Exception ex) { System.out.println("---------------------" + d); sLog.error(ex.getLocalizedMessage(), ex); System.exit(1); } }
From source file:util.comparisons.ComputeIndicators.java
public static void main(String[] args) throws IOException, InterruptedException { int[] numberOfObjectivesArray = new int[] { 2, 4 }; String[] problems = new String[] { "OO_MyBatis", "OA_AJHsqldb", "OA_AJHotDraw", "OO_BCEL", "OO_JHotDraw", "OA_HealthWatcher", // "OA_TollSystems", "OO_JBoss" }; HeuristicFunctionType[] heuristicFunctions = new HeuristicFunctionType[] { HeuristicFunctionType.ChoiceFunction, HeuristicFunctionType.MultiArmedBandit }; String[] algorithms = new String[] { "NSGA-II", // "SPEA2" };/*from www.j a v a 2 s . c om*/ MetricsUtil metricsUtil = new MetricsUtil(); DecimalFormat decimalFormatter = new DecimalFormat("0.00E0"); Mean mean = new Mean(); StandardDeviation standardDeviation = new StandardDeviation(); InvertedGenerationalDistance igd = new InvertedGenerationalDistance(); GenerationalDistance gd = new GenerationalDistance(); Spread spread = new Spread(); Coverage coverage = new Coverage(); for (int objectives : numberOfObjectivesArray) { try (FileWriter IGDWriter = new FileWriter("experiment/IGD_" + objectives + ".tex"); FileWriter spreadWriter = new FileWriter("experiment/SPREAD_" + objectives + ".tex"); FileWriter GDWriter = new FileWriter("experiment/GD_" + objectives + ".tex"); FileWriter coverageWriter = new FileWriter("experiment/COVERAGE_" + objectives + ".tex")) { StringBuilder latexTableBuilder = new StringBuilder(); latexTableBuilder.append("\\documentclass{paper}\n").append("\n") .append("\\usepackage[T1]{fontenc}\n").append("\\usepackage[latin1]{inputenc}\n") .append("\\usepackage[hidelinks]{hyperref}\n").append("\\usepackage{tabulary}\n") .append("\\usepackage{booktabs}\n").append("\\usepackage{multirow}\n") .append("\\usepackage{amsmath}\n").append("\\usepackage{mathtools}\n") .append("\\usepackage{graphicx}\n").append("\\usepackage{array}\n") .append("\\usepackage[linesnumbered,ruled,inoutnumbered]{algorithm2e}\n") .append("\\usepackage{subfigure}\n").append("\\usepackage[hypcap]{caption}\n") .append("\\usepackage{pdflscape}\n").append("\n").append("\\begin{document}\n").append("\n") .append("\\begin{landscape}\n").append("\n"); pfKnown: { latexTableBuilder.append("\\begin{table}[!htb]\n").append("\t\\centering\n") .append("\t\\def\\arraystretch{1.5}\n") // .append("\t\\setlength{\\tabcolsep}{10pt}\n") // .append("\t\\fontsize{8pt}{10pt}\\selectfont\n") .append("\t\\caption{INDICATOR found for $PF_{known}$ for ").append(objectives) .append(" objectives}\n").append("\t\\label{tab:INDICATOR ").append(objectives) .append(" objectives}\n").append("\t\\begin{tabulary}{\\linewidth}{c"); for (String algorithm : algorithms) { latexTableBuilder.append("c"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { latexTableBuilder.append("c"); } } latexTableBuilder.append("}\n").append("\t\t\\toprule\n").append("\t\t\\textbf{System}"); for (String algorithm : algorithms) { latexTableBuilder.append(" & \\textbf{").append(algorithm).append("}"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { latexTableBuilder.append(" & \\textbf{").append(algorithm).append("-") .append(heuristicFunction.toString()).append("}"); } } latexTableBuilder.append("\\\\\n").append("\t\t\\midrule\n"); for (String problem : problems) { NonDominatedSolutionList trueFront = new NonDominatedSolutionList(); pfTrueComposing: { for (String algorithm : algorithms) { SolutionSet mecbaFront = metricsUtil.readNonDominatedSolutionSet( "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + objectives + "obj/All_FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem); trueFront.addAll(mecbaFront); for (HeuristicFunctionType hyperHeuristic : heuristicFunctions) { SolutionSet front = metricsUtil.readNonDominatedSolutionSet( "experiment/" + algorithm + "/" + objectives + "objectives/" + hyperHeuristic.toString() + "/" + problem + "/FUN.txt"); trueFront.addAll(front); } } } double[][] trueFrontMatrix = trueFront.writeObjectivesToMatrix(); HashMap<String, Double> igdMap = new HashMap<>(); HashMap<String, Double> gdMap = new HashMap<>(); HashMap<String, Double> spreadMap = new HashMap<>(); HashMap<String, Double> coverageMap = new HashMap<>(); for (String algorithm : algorithms) { double[][] mecbaFront = metricsUtil .readFront("resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + objectives + "obj/All_FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem); igdMap.put(algorithm, igd.invertedGenerationalDistance(mecbaFront, trueFrontMatrix, objectives)); gdMap.put(algorithm, gd.generationalDistance(mecbaFront, trueFrontMatrix, objectives)); spreadMap.put(algorithm, spread.spread(mecbaFront, trueFrontMatrix, objectives)); coverageMap.put(algorithm, coverage.coverage(mecbaFront, trueFrontMatrix)); for (HeuristicFunctionType heuristic : heuristicFunctions) { String heuristicS = heuristic.toString(); double[][] heuristicFront = metricsUtil.readFront("experiment/" + algorithm + "/" + objectives + "objectives/" + heuristicS + "/" + problem + "/FUN.txt"); igdMap.put(algorithm + "-" + heuristicS, igd .invertedGenerationalDistance(heuristicFront, trueFrontMatrix, objectives)); gdMap.put(algorithm + "-" + heuristicS, gd.generationalDistance(heuristicFront, trueFrontMatrix, objectives)); spreadMap.put(algorithm + "-" + heuristicS, spread.spread(heuristicFront, trueFrontMatrix, objectives)); coverageMap.put(algorithm + "-" + heuristicS, coverage.coverage(heuristicFront, trueFrontMatrix)); } } latexTableBuilder.append("\t\t").append(problem); String latexTable = latexTableBuilder.toString(); latexTableBuilder = new StringBuilder(); latexTable = latexTable.replaceAll("O[OA]\\_", "").replaceAll("ChoiceFunction", "CF") .replaceAll("MultiArmedBandit", "MAB"); IGDWriter.write(latexTable.replaceAll("INDICATOR", "IGD")); spreadWriter.write(latexTable.replaceAll("INDICATOR", "Spread")); GDWriter.write(latexTable.replaceAll("INDICATOR", "GD")); coverageWriter.write(latexTable.replaceAll("INDICATOR", "Coverage")); String bestHeuristicIGD = "NULL"; String bestHeuristicGD = "NULL"; String bestHeuristicSpread = "NULL"; String bestHeuristicCoverage = "NULL"; getBest: { double bestMeanIGD = Double.POSITIVE_INFINITY; double bestMeanGD = Double.POSITIVE_INFINITY; double bestMeanSpread = Double.NEGATIVE_INFINITY; double bestMeanCoverage = Double.NEGATIVE_INFINITY; for (String heuristic : igdMap.keySet()) { double heuristicIGD = igdMap.get(heuristic); double heuristicGD = gdMap.get(heuristic); double heuristicSpread = spreadMap.get(heuristic); double heuristicCoverage = coverageMap.get(heuristic); if (heuristicIGD < bestMeanIGD) { bestMeanIGD = heuristicIGD; bestHeuristicIGD = heuristic; } if (heuristicGD < bestMeanGD) { bestMeanGD = heuristicGD; bestHeuristicGD = heuristic; } if (heuristicSpread > bestMeanSpread) { bestMeanSpread = heuristicSpread; bestHeuristicSpread = heuristic; } if (heuristicCoverage > bestMeanCoverage) { bestMeanCoverage = heuristicCoverage; bestHeuristicCoverage = heuristic; } } } StringBuilder igdBuilder = new StringBuilder(); StringBuilder gdBuilder = new StringBuilder(); StringBuilder spreadBuilder = new StringBuilder(); StringBuilder coverageBuilder = new StringBuilder(); String[] newHeuristicFunctions = new String[heuristicFunctions.length * algorithms.length + algorithms.length]; fulfillNewHeuristics: { int i = 0; for (String algorithm : algorithms) { newHeuristicFunctions[i++] = algorithm; for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { newHeuristicFunctions[i++] = algorithm + "-" + heuristicFunction.toString(); } } } for (String heuristic : newHeuristicFunctions) { igdBuilder.append(" & "); boolean bold = heuristic.equals(bestHeuristicIGD) || igdMap.get(heuristic).equals(igdMap.get(bestHeuristicIGD)); if (bold) { igdBuilder.append("\\textbf{"); } igdBuilder.append(decimalFormatter.format(igdMap.get(heuristic))); if (bold) { igdBuilder.append("}"); } gdBuilder.append(" & "); bold = heuristic.equals(bestHeuristicGD) || gdMap.get(heuristic).equals(gdMap.get(bestHeuristicGD)); if (bold) { gdBuilder.append("\\textbf{"); } gdBuilder.append(decimalFormatter.format(gdMap.get(heuristic))); if (bold) { gdBuilder.append("}"); } spreadBuilder.append(" & "); bold = heuristic.equals(bestHeuristicSpread) || spreadMap.get(heuristic).equals(spreadMap.get(bestHeuristicSpread)); if (bold) { spreadBuilder.append("\\textbf{"); } spreadBuilder.append(decimalFormatter.format(spreadMap.get(heuristic))); if (bold) { spreadBuilder.append("}"); } coverageBuilder.append(" & "); bold = heuristic.equals(bestHeuristicCoverage) || coverageMap.get(heuristic).equals(coverageMap.get(bestHeuristicCoverage)); if (bold) { coverageBuilder.append("\\textbf{"); } coverageBuilder.append(decimalFormatter.format(coverageMap.get(heuristic))); if (bold) { coverageBuilder.append("}"); } } IGDWriter.write(igdBuilder + "\\\\\n"); spreadWriter.write(spreadBuilder + "\\\\\n"); GDWriter.write(gdBuilder + "\\\\\n"); coverageWriter.write(coverageBuilder + "\\\\\n"); } latexTableBuilder = new StringBuilder(); latexTableBuilder.append("\t\t\\bottomrule\n").append("\t\\end{tabulary}\n") .append("\\end{table}\n\n"); } averages: { latexTableBuilder.append("\\begin{table}[!htb]\n").append("\t\\centering\n") .append("\t\\def\\arraystretch{1.5}\n") // .append("\t\\setlength{\\tabcolsep}{10pt}\n") // .append("\t\\fontsize{8pt}{10pt}\\selectfont\n") .append("\t\\caption{INDICATOR averages found for ").append(objectives) .append(" objectives}\n").append("\t\\label{tab:INDICATOR ").append(objectives) .append(" objectives}\n").append("\t\\begin{tabulary}{\\linewidth}{c"); for (String algorithm : algorithms) { latexTableBuilder.append("c"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { latexTableBuilder.append("c"); } } latexTableBuilder.append("}\n").append("\t\t\\toprule\n").append("\t\t\\textbf{System}"); for (String algorithm : algorithms) { latexTableBuilder.append(" & \\textbf{").append(algorithm).append("}"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { latexTableBuilder.append(" & \\textbf{").append(algorithm).append("-") .append(heuristicFunction.toString()).append("}"); } } latexTableBuilder.append("\\\\\n").append("\t\t\\midrule\n"); for (String problem : problems) { NonDominatedSolutionList trueFront = new NonDominatedSolutionList(); pfTrueComposing: { for (String algorithm : algorithms) { SolutionSet mecbaFront = metricsUtil.readNonDominatedSolutionSet( "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + objectives + "obj/All_FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem); trueFront.addAll(mecbaFront); for (HeuristicFunctionType hyperHeuristic : heuristicFunctions) { SolutionSet front = metricsUtil.readNonDominatedSolutionSet( "experiment/" + algorithm + "/" + objectives + "objectives/" + hyperHeuristic.toString() + "/" + problem + "/FUN.txt"); trueFront.addAll(front); } } } double[][] trueFrontMatrix = trueFront.writeObjectivesToMatrix(); HashMap<String, double[]> igdMap = new HashMap<>(); HashMap<String, double[]> gdMap = new HashMap<>(); HashMap<String, double[]> spreadMap = new HashMap<>(); HashMap<String, double[]> coverageMap = new HashMap<>(); mocaito: { for (String algorithm : algorithms) { double[] mecbaIGDs = new double[EXECUTIONS]; double[] mecbaGDs = new double[EXECUTIONS]; double[] mecbaSpreads = new double[EXECUTIONS]; double[] mecbaCoverages = new double[EXECUTIONS]; for (int i = 0; i < EXECUTIONS; i++) { double[][] mecbaFront = metricsUtil.readFront("resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + objectives + "obj/FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem + "-" + i + ".NaoDominadas"); mecbaIGDs[i] = igd.invertedGenerationalDistance(mecbaFront, trueFrontMatrix, objectives); mecbaGDs[i] = gd.generationalDistance(mecbaFront, trueFrontMatrix, objectives); mecbaSpreads[i] = spread.spread(mecbaFront, trueFrontMatrix, objectives); mecbaCoverages[i] = coverage.coverage(mecbaFront, trueFrontMatrix); } igdMap.put(algorithm, mecbaIGDs); gdMap.put(algorithm, mecbaGDs); spreadMap.put(algorithm, mecbaSpreads); coverageMap.put(algorithm, mecbaCoverages); } } for (String algorithm : algorithms) { for (HeuristicFunctionType heuristic : heuristicFunctions) { String heuristicS = heuristic.toString(); double[] hhIGDs = new double[EXECUTIONS]; double[] hhGDs = new double[EXECUTIONS]; double[] hhSpreads = new double[EXECUTIONS]; double[] hhCoverages = new double[EXECUTIONS]; for (int i = 0; i < EXECUTIONS; i++) { double[][] hhFront = metricsUtil .readFront("experiment/" + algorithm + "/" + objectives + "objectives/" + heuristicS + "/" + problem + "/EXECUTION_" + i + "/FUN.txt"); hhIGDs[i] = igd.invertedGenerationalDistance(hhFront, trueFrontMatrix, objectives); hhGDs[i] = gd.generationalDistance(hhFront, trueFrontMatrix, objectives); hhSpreads[i] = spread.spread(hhFront, trueFrontMatrix, objectives); hhCoverages[i] = coverage.coverage(hhFront, trueFrontMatrix); } igdMap.put(algorithm + "-" + heuristicS, hhIGDs); gdMap.put(algorithm + "-" + heuristicS, hhGDs); spreadMap.put(algorithm + "-" + heuristicS, hhSpreads); coverageMap.put(algorithm + "-" + heuristicS, hhCoverages); } } HashMap<String, HashMap<String, Boolean>> igdResult = KruskalWallisTest.test(igdMap); HashMap<String, HashMap<String, Boolean>> gdResult = KruskalWallisTest.test(gdMap); HashMap<String, HashMap<String, Boolean>> spreadResult = KruskalWallisTest.test(spreadMap); HashMap<String, HashMap<String, Boolean>> coverageResult = KruskalWallisTest .test(coverageMap); latexTableBuilder.append("\t\t").append(problem); String latexTable = latexTableBuilder.toString(); latexTable = latexTable.replaceAll("O[OA]\\_", "").replaceAll("ChoiceFunction", "CF") .replaceAll("MultiArmedBandit", "MAB"); IGDWriter.write(latexTable.replaceAll("INDICATOR", "IGD")); spreadWriter.write(latexTable.replaceAll("INDICATOR", "Spread")); GDWriter.write(latexTable.replaceAll("INDICATOR", "GD")); coverageWriter.write(latexTable.replaceAll("INDICATOR", "Coverage")); latexTableBuilder = new StringBuilder(); String bestHeuristicIGD = "NULL"; String bestHeuristicGD = "NULL"; String bestHeuristicSpread = "NULL"; String bestHeuristicCoverage = "NULL"; getBest: { double bestMeanIGD = Double.POSITIVE_INFINITY; double bestMeanGD = Double.POSITIVE_INFINITY; double bestMeanSpread = Double.NEGATIVE_INFINITY; double bestMeanCoverage = Double.NEGATIVE_INFINITY; for (String heuristic : igdMap.keySet()) { double heuristicMeanIGD = mean.evaluate(igdMap.get(heuristic)); double heuristicMeanGD = mean.evaluate(gdMap.get(heuristic)); double heuristicMeanSpread = mean.evaluate(spreadMap.get(heuristic)); double heuristicMeanCoverage = mean.evaluate(coverageMap.get(heuristic)); if (heuristicMeanIGD < bestMeanIGD) { bestMeanIGD = heuristicMeanIGD; bestHeuristicIGD = heuristic; } if (heuristicMeanGD < bestMeanGD) { bestMeanGD = heuristicMeanGD; bestHeuristicGD = heuristic; } if (heuristicMeanSpread > bestMeanSpread) { bestMeanSpread = heuristicMeanSpread; bestHeuristicSpread = heuristic; } if (heuristicMeanCoverage > bestMeanCoverage) { bestMeanCoverage = heuristicMeanCoverage; bestHeuristicCoverage = heuristic; } } } StringBuilder igdBuilder = new StringBuilder(); StringBuilder gdBuilder = new StringBuilder(); StringBuilder spreadBuilder = new StringBuilder(); StringBuilder coverageBuilder = new StringBuilder(); String[] newHeuristicFunctions = new String[heuristicFunctions.length * algorithms.length + algorithms.length]; fulfillNewHeuristics: { int i = 0; for (String algorithm : algorithms) { newHeuristicFunctions[i++] = algorithm; for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { newHeuristicFunctions[i++] = algorithm + "-" + heuristicFunction.toString(); } } } for (String heuristic : newHeuristicFunctions) { igdBuilder.append(" & "); boolean bold = heuristic.equals(bestHeuristicIGD) || !igdResult.get(heuristic).get(bestHeuristicIGD); if (bold) { igdBuilder.append("\\textbf{"); } igdBuilder.append(decimalFormatter.format(mean.evaluate(igdMap.get(heuristic))) + " (" + decimalFormatter.format(standardDeviation.evaluate(igdMap.get(heuristic))) + ")"); if (bold) { igdBuilder.append("}"); } gdBuilder.append(" & "); bold = heuristic.equals(bestHeuristicGD) || !gdResult.get(heuristic).get(bestHeuristicGD); if (bold) { gdBuilder.append("\\textbf{"); } gdBuilder.append(decimalFormatter.format(mean.evaluate(gdMap.get(heuristic))) + " (" + decimalFormatter.format(standardDeviation.evaluate(gdMap.get(heuristic))) + ")"); if (bold) { gdBuilder.append("}"); } spreadBuilder.append(" & "); bold = heuristic.equals(bestHeuristicSpread) || !spreadResult.get(heuristic).get(bestHeuristicSpread); if (bold) { spreadBuilder.append("\\textbf{"); } spreadBuilder.append(decimalFormatter.format(mean.evaluate(spreadMap.get(heuristic))) + " (" + decimalFormatter.format(standardDeviation.evaluate(spreadMap.get(heuristic))) + ")"); if (bold) { spreadBuilder.append("}"); } coverageBuilder.append(" & "); bold = heuristic.equals(bestHeuristicCoverage) || !coverageResult.get(heuristic).get(bestHeuristicCoverage); if (bold) { coverageBuilder.append("\\textbf{"); } coverageBuilder .append(decimalFormatter.format(mean.evaluate(coverageMap.get(heuristic)))) .append(" (") .append(decimalFormatter .format(standardDeviation.evaluate(coverageMap.get(heuristic)))) .append(")"); if (bold) { coverageBuilder.append("}"); } } IGDWriter.write(igdBuilder + "\\\\\n"); spreadWriter.write(spreadBuilder + "\\\\\n"); GDWriter.write(gdBuilder + "\\\\\n"); coverageWriter.write(coverageBuilder + "\\\\\n"); } latexTableBuilder.append("\t\t\\bottomrule\n").append("\t\\end{tabulary}\n") .append("\\end{table}\n\n"); } latexTableBuilder.append("\\end{landscape}\n\n").append("\\end{document}"); String latexTable = latexTableBuilder.toString(); IGDWriter.write(latexTable); spreadWriter.write(latexTable); GDWriter.write(latexTable); coverageWriter.write(latexTable); } } }