List of usage examples for org.apache.commons.math3.stat.descriptive.moment StandardDeviation StandardDeviation
public StandardDeviation()
From source file:org.opentox.jaqpot3.qsar.util.WekaInstancesProcess.java
private static double normedValue(Instances dataInst, int attributeIndex) { double[] attrValues = dataInst.attributeToDoubleArray(attributeIndex); StandardDeviation std = new StandardDeviation(); return std.evaluate(attrValues); }
From source file:org.softinica.maven.jmeter.report.analyser.SummaryReportAnalyzer.java
@Override protected void fillTable(Table table, Multimap<Object, Sample> grouped) { StandardDeviation deviation = new StandardDeviation(); for (Object key : grouped.keySet()) { double total = 0D; int sampleCount = grouped.get(key).size(); double[] values = new double[sampleCount]; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; long minTimestamp = Long.MAX_VALUE; long maxTimestamp = Long.MIN_VALUE; long totalBytes = 0; int errorCount = 0; int i = 0; for (Sample sample : grouped.get(key)) { total += sample.getValue();/*from www .java 2 s .c o m*/ values[i] = sample.getValue(); i++; if (min > sample.getValue()) { min = sample.getValue(); } if (max < sample.getValue()) { max = sample.getValue(); } if (!sample.isSuccess()) { errorCount++; } if (minTimestamp > sample.getTimestamp()) { minTimestamp = sample.getTimestamp(); } if (maxTimestamp < sample.getTimestamp()) { maxTimestamp = sample.getTimestamp(); } totalBytes += sample.getByteCount(); } table.put(key, LABEL, key.toString()); table.put(key, SAMPLES, String.valueOf(sampleCount)); table.put(key, AVERAGE, NUMBER_FORMAT.format(total / sampleCount)); table.put(key, MIN, NUMBER_FORMAT.format(min)); table.put(key, MAX, NUMBER_FORMAT.format(max)); table.put(key, STD_DEV, NUMBER_FORMAT.format(deviation.evaluate(values))); table.put(key, ERROR, NUMBER_FORMAT.format(100.0D * errorCount / sampleCount)); table.put(key, THROUGHPUT, NUMBER_FORMAT.format(sampleCount / total * 1000)); table.put(key, KB_PER_SEC, NUMBER_FORMAT.format(totalBytes / total * 1000)); table.put(key, AVERAGE_BYTES, NUMBER_FORMAT.format(totalBytes / sampleCount)); } }
From source file:org.terracotta.statistics.derived.histogram.HistogramFittingTest.java
@Test @Ignore//from w w w . j a va 2s. co m public void evaluateFlatHistogramErrors() { StandardDeviation parameter = new StandardDeviation(); for (int i = 0; i < 1000; i++) { parameter.increment(flatHistogramFit(System.nanoTime())[1]); System.out.println("Flat Histogram Slope: Iteration: " + i + " S.D:" + parameter.getResult()); } }
From source file:org.terracotta.statistics.derived.histogram.HistogramFittingTest.java
@Test @Ignore/*from w w w .j a va 2 s.co m*/ public void evaluateGaussianHistogramErrors() { StandardDeviation centroid = new StandardDeviation(); StandardDeviation width = new StandardDeviation(); for (int i = 0; i < 1000; i++) { double[] parameters = gaussianHistogramFit(System.nanoTime()); centroid.increment(parameters[1]); width.increment(parameters[2]); System.out.println("Gaussian Histogram Centroid: Iteration: " + i + " S.D:" + centroid.getResult()); System.out.println("Gaussian Histogram Width: Iteration: " + i + " S.D:" + width.getResult()); } }
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;//w w w .j a v a2 s.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.CompareHypervolumes.java
private static void generateTables(String[] problems, HeuristicFunctionType[] heuristicFunctions, int numberOfObjectives, String[] algorithms) throws InterruptedException, IOException { String outputDirectory = outpath; try (FileWriter fileWriter = new FileWriter(outputDirectory + "TABLES_" + numberOfObjectives + ".txt")) { StringBuilder tableString = new StringBuilder(); DecimalFormat decimalFormatter = new DecimalFormat("0.00E0"); StandardDeviation standardDeviation = new StandardDeviation(); pfKnown: {/*from www .jav a 2 s.c o m*/ tableString.append("\\documentclass{paper}\n" + "\n" + "\\usepackage[T1]{fontenc}\n" + "\\usepackage[latin1]{inputenc}\n" + "\\usepackage[hidelinks]{hyperref}\n" + "\\usepackage{tabulary}\n" + "\\usepackage{booktabs}\n" + "\\usepackage{multirow}\n" + "\\usepackage{amsmath}\n" + "\\usepackage{mathtools}\n" + "\\usepackage{graphicx}\n" + "\\usepackage{array}\n" + "\\usepackage[linesnumbered,ruled,inoutnumbered]{algorithm2e}\n" + "\\usepackage{subfigure}\n" + "\\usepackage[hypcap]{caption}\n" + "\\usepackage{pdflscape}\n" + "\n" + "\\begin{document}\n" + "\n" + "\\begin{landscape}\n" + "\n"); tableString .append("\\begin{table}[!htb]\n" + "\t\\centering\n" + "\t\\def\\arraystretch{1.5}\n" + "\t\\setlength{\\tabcolsep}{10pt}\n" + "\t\\fontsize{8pt}{10pt}\\selectfont" + "\t\\caption{Hypervolume of the $PF_{known}$ fronts for ") .append(numberOfObjectives).append(" objectives}\n" + "\t\\label{tab:Hypervolumes ") .append(numberOfObjectives).append(" objectives}\n" + "\t\\begin{tabulary}{\\textwidth}{c"); for (String algorithm : algorithms) { tableString.append("c"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { tableString.append("c"); } } tableString.append("}\n"); tableString.append("\t\t\\toprule\n"); tableString.append("\t\t\\textbf{System}"); for (String algorithm : algorithms) { tableString.append(" & \\textbf{").append(algorithm).append("}"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { tableString.append(" & \\textbf{").append(algorithm).append("-") .append(heuristicFunction.toString()).append("}"); } } tableString.append("\\\\\n"); tableString.append("\t\t\\midrule\n"); for (String problem : problems) { HypervolumeHandler hypervolumeHandler = new HypervolumeHandler(); for (String algorithm : algorithms) { String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + numberOfObjectives + "obj/"; //Best PFknown hypervolume //Populate HypervolueHandler hypervolumeHandler.addParetoFront(mecbaDirectory + "All_FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { String path = outpath; path += algorithm + "/" + numberOfObjectives + "objectives/"; String hyperheuristicDirectory = path + heuristicFunction.toString() + "/" + problem + "/"; hypervolumeHandler.addParetoFront(hyperheuristicDirectory + "FUN.txt"); } } double[] mecbaHypervolumes = new double[algorithms.length]; double[] hyperheuristicHypervolumes = new double[heuristicFunctions.length * algorithms.length]; Arrays.fill(hyperheuristicHypervolumes, 0D); for (int i = 0; i < algorithms.length; i++) { String algorithm = algorithms[i]; String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + numberOfObjectives + "obj/"; //Calculate Hypervolume mecbaHypervolumes[i] = hypervolumeHandler.calculateHypervolume(mecbaDirectory + "All_FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem, numberOfObjectives); for (int j = 0; j < heuristicFunctions.length; j++) { HeuristicFunctionType heuristicFunction = heuristicFunctions[j]; String path = outpath; path += algorithm + "/" + numberOfObjectives + "objectives/"; String hyperheuristicDirectory = path + heuristicFunction.toString() + "/" + problem + "/"; hyperheuristicHypervolumes[i * heuristicFunctions.length + j] = hypervolumeHandler .calculateHypervolume(hyperheuristicDirectory + "FUN.txt", numberOfObjectives); } } //Write PFknown results double maxHypervolume = Double.NEGATIVE_INFINITY; for (int i = 0; i < mecbaHypervolumes.length; i++) { double hypervolume = mecbaHypervolumes[i]; if (hypervolume > maxHypervolume) { maxHypervolume = hypervolume; } } for (int i = 0; i < heuristicFunctions.length; i++) { if (hyperheuristicHypervolumes[i] > maxHypervolume) { maxHypervolume = hyperheuristicHypervolumes[i]; } } tableString.append("\t\t" + problem.replaceAll("\\_", "\\\\_")); for (int i = 0; i < algorithms.length; i++) { tableString.append(" & "); double mecbaHypervolume = mecbaHypervolumes[i]; if (maxHypervolume == mecbaHypervolume) { tableString.append("\\textbf{"); } tableString.append(decimalFormatter.format(mecbaHypervolume)); if (maxHypervolume == mecbaHypervolume) { tableString.append("}"); } for (int j = 0; j < heuristicFunctions.length; j++) { tableString.append(" & "); double hyperheuristicHypervolume = hyperheuristicHypervolumes[i * heuristicFunctions.length + j]; if (maxHypervolume == hyperheuristicHypervolume) { tableString.append("\\textbf{"); } tableString.append(decimalFormatter.format(hyperheuristicHypervolume)); if (maxHypervolume == hyperheuristicHypervolume) { tableString.append("}"); } } } tableString.append("\\\\\n"); } tableString.append("\t\t\\bottomrule\n"); tableString.append("\t\\end{tabulary}\n"); tableString.append("\\end{table}\n\n"); } //Best mean hypervolume mean: { tableString.append("\\begin{table}[!htb]\n" + "\\centering\n" + "\t\\def\\arraystretch{1.5}\n" + "\t\\setlength{\\tabcolsep}{10pt}\n" + "\t\\fontsize{8pt}{10pt}\\selectfont" + "\t\\caption{Hypervolume average found for " + numberOfObjectives + " objectives}\n" + "\t\\label{tab:Hypervolumes average " + numberOfObjectives + " objectives}\n" + "\t\\begin{tabulary}{\\textwidth}{c"); for (String algorithm : algorithms) { tableString.append("c"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { tableString.append("c"); } } tableString.append("}\n"); tableString.append("\t\t\\toprule\n"); tableString.append("\t\t\\textbf{System}"); for (String algorithm : algorithms) { tableString.append(" & \\textbf{" + algorithm + "}"); for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { tableString.append(" & \\textbf{" + algorithm + "-" + heuristicFunction.toString() + "}"); } } tableString.append("\\\\\n"); tableString.append("\t\t\\midrule\n"); for (String problem : problems) { HypervolumeHandler hypervolumeHandler = new HypervolumeHandler(); for (String algorithm : algorithms) { String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + numberOfObjectives + "obj/"; for (int i = 0; i < EXECUTIONS; i++) { hypervolumeHandler.addParetoFront( mecbaDirectory + "FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem + "-" + i + ".NaoDominadas"); } for (HeuristicFunctionType heuristicFunction : heuristicFunctions) { String path = outpath; path += algorithm + "/" + numberOfObjectives + "objectives/"; String hyperheuristicDirectory = path + heuristicFunction.toString() + "/" + problem + "/"; for (int j = 0; j < EXECUTIONS; j++) { hypervolumeHandler .addParetoFront(hyperheuristicDirectory + "EXECUTION_" + j + "/FUN.txt"); } } } double[][] mecbaHypervolumes = new double[algorithms.length][EXECUTIONS]; for (double[] mecbaHypervolume : mecbaHypervolumes) { Arrays.fill(mecbaHypervolume, 0D); } double mecbaMeanHypervolume[] = new double[algorithms.length]; Arrays.fill(mecbaMeanHypervolume, 0D); double[][] hyperheuristicHypervolumes = new double[algorithms.length * heuristicFunctions.length][EXECUTIONS]; for (double[] hyperheuristicHypervolume : hyperheuristicHypervolumes) { Arrays.fill(hyperheuristicHypervolume, 0D); } double[] hyperheuristicMeanHypervolumes = new double[algorithms.length * heuristicFunctions.length]; Arrays.fill(hyperheuristicMeanHypervolumes, 0D); for (int i = 0; i < algorithms.length; i++) { String algorithm = algorithms[i]; String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/" + problem + "_Comb_" + numberOfObjectives + "obj/"; for (int j = 0; j < EXECUTIONS; j++) { mecbaHypervolumes[i][j] = hypervolumeHandler .calculateHypervolume( mecbaDirectory + "FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem + "-" + j + ".NaoDominadas", numberOfObjectives); mecbaMeanHypervolume[i] += mecbaHypervolumes[i][j]; for (int k = 0; k < heuristicFunctions.length; k++) { String path = outpath; path += algorithm + "/" + numberOfObjectives + "objectives/"; String hyperheuristicDirectory = path + heuristicFunctions[k] + "/" + problem + "/"; hyperheuristicHypervolumes[i * heuristicFunctions.length + k][j] = hypervolumeHandler.calculateHypervolume( hyperheuristicDirectory + "EXECUTION_" + j + "/FUN.txt", numberOfObjectives); hyperheuristicMeanHypervolumes[i * heuristicFunctions.length + k] += hyperheuristicHypervolumes[i * heuristicFunctions.length + k][j]; } } } for (int i = 0; i < mecbaMeanHypervolume.length; i++) { mecbaMeanHypervolume[i] /= (double) EXECUTIONS; } for (int i = 0; i < hyperheuristicMeanHypervolumes.length; i++) { hyperheuristicMeanHypervolumes[i] /= (double) EXECUTIONS; } double maxMean = Double.NEGATIVE_INFINITY; String maxHeuristic = "NULL"; for (int i = 0; i < mecbaMeanHypervolume.length; i++) { double mean = mecbaMeanHypervolume[i]; if (mean > maxMean) { maxMean = mean; maxHeuristic = algorithms[i]; } } for (int i = 0; i < hyperheuristicMeanHypervolumes.length; i++) { double hyperheuristicMeanHypervolume = hyperheuristicMeanHypervolumes[i]; if (hyperheuristicMeanHypervolume > maxMean) { maxMean = hyperheuristicMeanHypervolume; maxHeuristic = algorithms[i / heuristicFunctions.length] + "-" + heuristicFunctions[i % heuristicFunctions.length]; } } HashMap<String, double[]> values = new HashMap<>(); for (int i = 0; i < algorithms.length; i++) { String algorithm = algorithms[i]; values.put(algorithm, mecbaHypervolumes[i]); } for (int i = 0; i < hyperheuristicHypervolumes.length; i++) { double[] hyperheuristicHypervolume = hyperheuristicHypervolumes[i]; HeuristicFunctionType heuristicFunction = heuristicFunctions[i % heuristicFunctions.length]; String algorithm = algorithms[i / heuristicFunctions.length]; values.put(algorithm + "-" + heuristicFunction.toString(), hyperheuristicHypervolume); } HashMap<String, HashMap<String, Boolean>> result = KruskalWallisTest.test(values); tableString.append("\t\t" + problem.replaceAll("\\_", "\\\\_")); for (int i = 0; i < algorithms.length; i++) { String algorithm = algorithms[i]; tableString.append(" & "); if (algorithm.equals(maxHeuristic) || !result.get(algorithm).get(maxHeuristic)) { tableString.append("\\textbf{"); } tableString.append(decimalFormatter.format(mecbaMeanHypervolume[i])); tableString.append(" (") .append(decimalFormatter.format(standardDeviation.evaluate(mecbaHypervolumes[i]))) .append(")"); if (algorithm.equals(maxHeuristic) || !result.get(algorithm).get(maxHeuristic)) { tableString.append("}"); } for (int j = 0; j < heuristicFunctions.length; j++) { String heuristicFunction = algorithm + "-" + heuristicFunctions[j]; tableString.append(" & "); if (heuristicFunction.equals(maxHeuristic) || !result.get(heuristicFunction).get(maxHeuristic)) { tableString.append("\\textbf{"); } tableString.append(decimalFormatter .format(hyperheuristicMeanHypervolumes[i * heuristicFunctions.length + j])); tableString.append(" (") .append(decimalFormatter.format(standardDeviation.evaluate( hyperheuristicHypervolumes[i * heuristicFunctions.length + j]))) .append(")"); if (heuristicFunction.equals(maxHeuristic) || !result.get(heuristicFunction).get(maxHeuristic)) { tableString.append("}"); } } } tableString.append("\\\\\n"); } tableString.append("\t\t\\bottomrule\n"); tableString.append("\t\\end{tabulary}\n"); tableString.append("\\end{table}\n"); } tableString.append("\n" + "\\end{landscape}\n" + "\n" + "\\end{document}\n"); fileWriter.write(tableString.toString().replaceAll("ChoiceFunction", "CF") .replaceAll("MultiArmedBandit", "MAB")); } }
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" };//www. j a v a 2s . c o m 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); } } }
From source file:util.ManageResults.java
/** * /*from w w w. ja v a2s . com*/ * @param fun * @return the standard deviation */ private static double getStandardDeviation(List<Double> fun) { double[] funArray = new double[fun.size()]; for (int i = 0; i < funArray.length; i++) { funArray[i] = fun.get(i); } StandardDeviation sd = new StandardDeviation(); return sd.evaluate(funArray); }
From source file:util.ResultsUtil.java
public static double getStandardDeviation(List<Double> fun) { double[] funArray = new double[fun.size()]; for (int i = 0; i < funArray.length; i++) { funArray[i] = fun.get(i); }//ww w . j ava 2s . com StandardDeviation sd = new StandardDeviation(); return sd.evaluate(funArray); }
From source file:utils.ZTransform.java
private void createZTransform(ArrayList<CMatrix> selectedMatrices) { if (selectedMatrices.isEmpty()) { Messenger.showWarningMessage("Please select datasets to continue.", "Empty selection"); return;/*from w ww . ja v a 2 s . c o m*/ } for (CMatrix matrix : selectedMatrices) { if (!(matrix instanceof DoubleCMatrix)) { Messenger.showWarningMessage( "Dataset '" + matrix + "' is not a numeric matrix.\nOperation aborted.", "Data type error."); return; } } //selected matrices for (CMatrix matrix : selectedMatrices) { ArrayList<Double> values = new ArrayList<>(); DoubleCMatrix newMatrix = new DoubleCMatrix(matrix.getName() + " z transformed", matrix.getNumRows(), matrix.getNumColumns()); // for (int i = 0; i < matrix.getNumRows(); i++) { for (int j = 0; j < matrix.getNumColumns(); j++) { try { Double value = (Double) matrix.getValue(i, j); if (value == null || value.isInfinite() || value.isNaN()) { continue; } else { values.add(value); } } catch (Exception e) { } } //loop of num columns } //loop of num rows double[] v = new double[values.size()]; for (int i = 0; i < v.length; i++) { v[i] = values.get(i); } Mean mean = new Mean(); StandardDeviation sd = new StandardDeviation(); double mu = mean.evaluate(v); double sigma = sd.evaluate(v); // System.out.println("Mean: " + mu + " sd:" + sigma); for (int i = 0; i < matrix.getNumRows(); i++) { for (int j = 0; j < matrix.getNumColumns(); j++) { Double value = (Double) matrix.getValue(i, j); if (value == null || value.isInfinite() || value.isNaN()) { continue; } else { newMatrix.setValue(i, j, (value - mu) / sigma); } } } // for (int i = 0; i < matrix.getNumRows(); i++) { newMatrix.setRowLabel(i, matrix.getRowLabel(i)); } // for (int i = 0; i < matrix.getNumColumns(); i++) { newMatrix.setColLabel(i, matrix.getColLabel(i)); } CoolMapMaster.addNewBaseMatrix(newMatrix); } //end of matrices }