Example usage for org.apache.commons.math3.stat.descriptive.moment StandardDeviation evaluate

List of usage examples for org.apache.commons.math3.stat.descriptive.moment StandardDeviation evaluate

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive.moment StandardDeviation evaluate.

Prototype

@Override
public double evaluate(final double[] values) throws MathIllegalArgumentException 

Source Link

Document

Returns the Standard Deviation of the entries in the input array, or Double.NaN if the array is empty.

Usage

From source file:com.itemanalysis.psychometrics.kernel.ScottsBandwidth.java

public double value() {
    StandardDeviation sd = new StandardDeviation();
    double q3 = pcntl.evaluate(x, 75.0);
    double q1 = pcntl.evaluate(x, 25.0);
    double IQR = (q3 - q1) / 1.34;
    double s = sd.evaluate(x);
    double N = (double) x.length;
    double m = Math.min(s, IQR);
    return 1.06 * m * Math.pow(N, -1.0 / 5.0) * adjustmentFactor;
}

From source file:com.graphhopper.jsprit.core.algorithm.acceptor.ExperimentalSchrimpfAcceptance.java

@Override
public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm,
        Collection<VehicleRoutingProblemSolution> solutions) {
    reset();/*ww  w .  java2 s. c om*/
    logger.info("---------------------------------------------------------------------");
    logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold");
    logger.info("start random-walk (see randomWalk.xml)");
    double now = System.currentTimeMillis();
    this.nOfTotalIterations = algorithm.getMaxIterations();

    /*
       * randomWalk to determine standardDev
     */
    final double[] results = new double[nOfRandomWalks];

    Jsprit.Builder builder = new GreedySchrimpfFactory().createGreedyAlgorithmBuilder(problem);
    builder.setCustomAcceptor(new AcceptNewRemoveFirst(1));
    VehicleRoutingAlgorithm vra = builder.buildAlgorithm();
    vra.setMaxIterations(nOfRandomWalks);
    vra.getAlgorithmListeners().addListener(new IterationEndsListener() {

        @Override
        public void informIterationEnds(int iteration, VehicleRoutingProblem problem,
                Collection<VehicleRoutingProblemSolution> solutions) {
            double result = Solutions.bestOf(solutions).getCost();
            //            logger.info("result={}", result);
            results[iteration - 1] = result;
        }

    });
    vra.searchSolutions();

    StandardDeviation dev = new StandardDeviation();
    double standardDeviation = dev.evaluate(results);
    initialThreshold = standardDeviation / 2;

    logger.info("warmup done");
    logger.info("total time: {}s", ((System.currentTimeMillis() - now) / 1000.0));
    logger.info("initial threshold: {}", initialThreshold);
    logger.info("---------------------------------------------------------------------");

}

From source file:com.musicg.api.DetectionApi.java

protected boolean isPassedStandardDeviation(double[][] spectrogramData) {

    // normalize the spectrogramData (with all frames in the spectrogram)
    normalizeSpectrogramData(spectrogramData);

    // analyst data in this frame
    // since fftSampleSize==numSamples, there're only one spectrum which is
    // spectrogramData[last]
    double[] spectrum = spectrogramData[spectrogramData.length - 1];
    // find top most robust frequencies in this frame
    double[] robustFrequencies = new double[numRobust];
    ArrayRankDouble arrayRankDouble = new ArrayRankDouble();
    double nthValue = arrayRankDouble.getNthOrderedValue(spectrum, numRobust, false);
    // end analyst data in this frame

    int count = 0;
    for (int i = 0; i < spectrum.length; i++) {
        if (spectrum[i] >= nthValue) {
            robustFrequencies[count++] = spectrum[i];
            if (count >= numRobust) {
                break;
            }/* w  ww  .ja  v a 2  s  .com*/
        }
    }
    // end find top most robust frequencies

    StandardDeviation standardDeviation = new StandardDeviation();
    double sd = standardDeviation.evaluate(robustFrequencies);

    // range of standard deviation
    boolean result = (sd >= minStandardDeviation && sd <= maxStandardDeviation);
    // System.out.println("sd: " + sd + " " + result);
    return result;
}

From source file:eagle.security.userprofile.model.eigen.UserProfileEigenModeler.java

private void computeStats(RealMatrix m) {

    if (m.getColumnDimension() != this.cmdTypes.length) {
        LOG.error("Please fix the commands list in config file");
        return;/*w w  w  . j a v a 2  s.c o m*/
    }
    statistics = new UserCommandStatistics[m.getColumnDimension()];
    for (int i = 0; i < m.getColumnDimension(); i++) {
        UserCommandStatistics stats = new UserCommandStatistics();
        stats.setCommandName(this.cmdTypes[i]);
        RealVector colData = m.getColumnVector(i);
        StandardDeviation deviation = new StandardDeviation();
        double stddev = deviation.evaluate(colData.toArray());
        //LOG.info("stddev is nan?" + (stddev == Double.NaN? "yes":"no"));
        if (stddev <= lowVarianceVal)
            stats.setLowVariant(true);
        else
            stats.setLowVariant(false);
        stats.setStddev(stddev);
        Mean mean = new Mean();
        double mu = mean.evaluate(colData.toArray());
        //LOG.info("mu is nan?" + (mu == Double.NaN? "yes":"no"));
        stats.setMean(mu);
        statistics[i] = stats;
    }
}

From source file:com.itemanalysis.psychometrics.rasch.JMLE.java

public void linearTransformation(DefaultLinearTransformation lt, int precision) {
    Mean pMean = new Mean();
    StandardDeviation pSd = new StandardDeviation();

    //set transformation and rescale persons
    double newScale = lt.getScale();
    double newMean = lt.getIntercept();
    double oldPersonMean = pMean.evaluate(theta);
    double oldPersonSd = pSd.evaluate(theta);

    lt.setScaleAndIntercept(oldPersonMean, newMean, oldPersonSd, newScale);

    for (int i = 0; i < theta.length; i++) {
        theta[i] = lt.transform(theta[i]);
    }//from ww  w .ja  v a2s  . c o m

    //set transformation and rescale items
    Mean iMean = new Mean();
    StandardDeviation iSd = new StandardDeviation();
    double tempDifficulty = 0.0;

    for (VariableName v : items.keySet()) {
        tempDifficulty = items.get(v).getDifficulty();
        iMean.increment(tempDifficulty);
        iSd.increment(tempDifficulty);
    }

    lt.setScaleAndIntercept(iMean.getResult(), newMean, iSd.getResult(), newScale);

    for (VariableName v : items.keySet()) {
        items.get(v).linearTransformation(lt, precision);
    }

    //set transformation and rescale thresholds
    RatingScaleThresholds tempThresholds = null;

    for (String s : thresholds.keySet()) {
        tempThresholds = thresholds.get(s);
        lt.setScaleAndIntercept(tempThresholds.getThresholdMean(), newMean,
                tempThresholds.getThresholdStandardDeviation(), newScale);
        thresholds.get(s).linearTransformation(lt, precision);
    }
}

From source file:br.unicamp.ic.recod.gpsi.applications.gpsiJGAPEvolver.java

@Override
public void run() throws InvalidConfigurationException, InterruptedException, Exception {

    int i, j, k;//from   w w  w .  ja v  a 2s  .c  o  m
    byte nFolds = 5;
    gpsiDescriptor descriptor;
    gpsiMLDataset mlDataset;
    gpsiVoxelRawDataset dataset;
    GPGenotype gp;
    double[][] fitnessCurves;
    String[] curveLabels = new String[] { "train", "train_val", "val" };
    double bestScore, currentScore;
    IGPProgram current, bestVal;

    Mean mean = new Mean();
    StandardDeviation sd = new StandardDeviation();

    double validationScore, trainScore, bestValidationScore, bestTrainScore;
    double[][][] samples;

    for (byte f = 0; f < nFolds; f++) {

        System.out.println("\nRun " + (f + 1) + "\n");

        rawDataset.assignFolds(new byte[] { f, (byte) ((f + 1) % nFolds), (byte) ((f + 2) % nFolds) },
                new byte[] { (byte) ((f + 3) % nFolds) }, new byte[] { (byte) ((f + 4) % nFolds) });
        dataset = (gpsiVoxelRawDataset) rawDataset;
        gp = create(config, dataset.getnBands(), fitness);

        // 0: train, 1: train_val, 2: val
        fitnessCurves = new double[super.numGenerations][];
        current = null;
        bestVal = null;
        bestScore = -Double.MAX_VALUE;
        bestValidationScore = -1.0;
        bestTrainScore = -1.0;

        for (int generation = 0; generation < super.numGenerations; generation++) {

            gp.evolve(1);
            gp.getGPPopulation().sortByFitness();

            if (this.dumpGens) {

                double[][][] dists;
                descriptor = new gpsiScalarSpectralIndexDescriptor(
                        new gpsiJGAPVoxelCombiner(fitness.getB(), gp.getGPPopulation().getGPPrograms()[0]));
                mlDataset = new gpsiMLDataset(descriptor);
                mlDataset.loadWholeDataset(rawDataset, true);

                dists = (new gpsiWholeSampler()).sample(mlDataset.getTrainingEntities(), this.classLabels);
                for (i = 0; i < this.classLabels.length; i++) {
                    stream.register(new gpsiDoubleCsvIOElement(dists[i], null,
                            "gens/f" + (f + 1) + "/" + classLabels[i] + "/" + (generation + 1) + ".csv"));
                }

            }

            for (i = 0; i < super.validation; i++) {

                current = gp.getGPPopulation().getGPPrograms()[i];

                descriptor = new gpsiScalarSpectralIndexDescriptor(
                        new gpsiJGAPVoxelCombiner(fitness.getB(), current));
                mlDataset = new gpsiMLDataset(descriptor);
                mlDataset.loadWholeDataset(rawDataset, true);

                samples = this.fitness.getSampler().sample(mlDataset.getValidationEntities(), classLabels);

                validationScore = fitness.getScore().score(samples);
                trainScore = current.getFitnessValue() - 1.0;

                currentScore = mean.evaluate(new double[] { trainScore, validationScore })
                        - sd.evaluate(new double[] { trainScore, validationScore });

                if (currentScore > bestScore) {
                    bestVal = current;
                    bestScore = currentScore;
                    bestTrainScore = trainScore;
                    bestValidationScore = validationScore;
                }

            }

            if (validation > 0) {
                best = new IGPProgram[2];
                best[0] = gp.getAllTimeBest();
                best[1] = bestVal;
                fitnessCurves[generation] = new double[] { best[0].getFitnessValue() - 1.0, bestTrainScore,
                        bestValidationScore };
                System.out.printf("%3dg: %.4f  %.4f  %.4f\n", generation + 1, fitnessCurves[generation][0],
                        fitnessCurves[generation][1], fitnessCurves[generation][2]);
            } else {
                best = new IGPProgram[1];
                best[0] = gp.getAllTimeBest();
                fitnessCurves[generation] = new double[] { gp.getAllTimeBest().getFitnessValue() - 1.0 };
                System.out.printf("%3dg: %.4f\n", generation + 1, fitnessCurves[generation][0]);
            }

        }

        stream.register(new gpsiDoubleCsvIOElement(fitnessCurves, curveLabels, "curves/f" + (f + 1) + ".csv"));

        System.out.println("Best solution for trainning: " + gp.getAllTimeBest().toStringNorm(0));
        stream.register(new gpsiStringIOElement(gp.getAllTimeBest().toStringNorm(0),
                "programs/f" + (f + 1) + "train.program"));

        if (validation > 0) {
            System.out.println("Best solution for trainning and validation: " + bestVal.toStringNorm(0));
            stream.register(new gpsiStringIOElement(bestVal.toStringNorm(0),
                    "programs/f" + (f + 1) + "train_val.program"));
        }

        descriptor = new gpsiScalarSpectralIndexDescriptor(new gpsiJGAPVoxelCombiner(fitness.getB(), best[0]));
        gpsi1NNToMomentScalarClassificationAlgorithm classificationAlgorithm = new gpsi1NNToMomentScalarClassificationAlgorithm(
                new Mean());
        gpsiClassifier classifier = new gpsiClassifier(descriptor, classificationAlgorithm);

        classifier.fit(this.rawDataset.getTrainingEntities());
        classifier.predict(this.rawDataset.getTestEntities());

        int[][] confusionMatrix = classifier.getConfusionMatrix();

        stream.register(new gpsiIntegerCsvIOElement(confusionMatrix, null,
                "confusion_matrices/f" + (f + 1) + "_train.csv"));

        if (validation > 0) {
            descriptor = new gpsiScalarSpectralIndexDescriptor(
                    new gpsiJGAPVoxelCombiner(fitness.getB(), best[1]));
            classificationAlgorithm = new gpsi1NNToMomentScalarClassificationAlgorithm(new Mean());
            classifier = new gpsiClassifier(descriptor, classificationAlgorithm);

            classifier.fit(this.rawDataset.getTrainingEntities());
            classifier.predict(this.rawDataset.getTestEntities());

            confusionMatrix = classifier.getConfusionMatrix();

            stream.register(new gpsiIntegerCsvIOElement(confusionMatrix, null,
                    "confusion_matrices/f" + (f + 1) + "_train_val.csv"));

        }

    }

}

From source file:br.unicamp.ic.recod.gpsi.applications.gpsiJGAPSelectorEvolver.java

@Override
public void run() throws InvalidConfigurationException, InterruptedException, Exception {

    int i, j, k;/*  ww w.  j  a va2 s  .  c o  m*/
    byte nFolds = 5;
    gpsiDescriptor descriptor;
    gpsiMLDataset mlDataset;
    gpsiVoxelRawDataset dataset;
    GPGenotype gp;
    double[][] fitnessCurves;
    String[] curveLabels = new String[] { "train", "train_val", "val" };
    double bestScore, currentScore;
    IGPProgram current;
    IGPProgram[] elite = null;

    Mean mean = new Mean();
    StandardDeviation sd = new StandardDeviation();

    double validationScore, trainScore;
    double[][][] samples;

    for (byte f = 0; f < nFolds; f++) {

        System.out.println("\nRun " + (f + 1) + "\n");

        rawDataset.assignFolds(new byte[] { f, (byte) ((f + 1) % nFolds), (byte) ((f + 2) % nFolds) },
                new byte[] { (byte) ((f + 3) % nFolds) }, new byte[] { (byte) ((f + 4) % nFolds) });
        dataset = (gpsiVoxelRawDataset) rawDataset;
        gp = create(config, dataset.getnBands(), fitness, null);

        // 0: train, 1: train_val, 2: val
        fitnessCurves = new double[super.numGenerations + numGenerationsSel][];
        bestScore = -Double.MAX_VALUE;

        if (validation > 0)
            elite = new IGPProgram[validation];

        for (int generation = 0; generation < numGenerationsSel; generation++) {

            gp.evolve(1);
            gp.getGPPopulation().sortByFitness();

            if (validation > 0)
                elite = mergeElite(elite, gp.getGPPopulation().getGPPrograms(), generation);

            if (this.dumpGens) {

                double[][][] dists;
                descriptor = new gpsiScalarSpectralIndexDescriptor(
                        new gpsiJGAPVoxelCombiner(fitness.getB(), gp.getGPPopulation().getGPPrograms()[0]));
                mlDataset = new gpsiMLDataset(descriptor);
                mlDataset.loadWholeDataset(rawDataset, true);

                dists = (new gpsiWholeSampler()).sample(mlDataset.getTrainingEntities(), this.classLabels);
                for (i = 0; i < this.classLabels.length; i++) {
                    stream.register(new gpsiDoubleCsvIOElement(dists[i], null,
                            "gens/f" + (f + 1) + "/" + classLabels[i] + "/" + (generation + 1) + ".csv"));
                }

            }

            fitnessCurves[generation] = new double[] { gp.getAllTimeBest().getFitnessValue() - 1.0 };
            System.out.printf("%3dg: %.4f\n", generation + 1, fitnessCurves[generation][0]);

        }

        HashSet<Integer> variables = new HashSet<>();
        for (IGPProgram ind : elite) {
            for (CommandGene node : ind.getChromosome(0).getFunctions()) {
                if (node instanceof Variable) {
                    variables.add(Integer.parseInt(node.getName().replace('b', '0')));
                }
            }
        }

        int[] vars = variables.stream().mapToInt(p -> p).toArray();
        Arrays.sort(vars);
        stream.register(new gpsiStringIOElement(Arrays.toString(vars), "selected_bands/f" + (f + 1) + ".out"));

        gp = create(config, dataset.getnBands(), fitness, vars);
        gp.addFittestProgram(elite[0]);

        for (int generation = numGenerationsSel; generation < numGenerationsSel
                + super.numGenerations; generation++) {

            gp.evolve(1);
            gp.getGPPopulation().sortByFitness();

            if (validation > 0)
                elite = mergeElite(elite, gp.getGPPopulation().getGPPrograms(), generation);

            if (this.dumpGens) {

                double[][][] dists;
                descriptor = new gpsiScalarSpectralIndexDescriptor(
                        new gpsiJGAPVoxelCombiner(fitness.getB(), gp.getGPPopulation().getGPPrograms()[0]));
                mlDataset = new gpsiMLDataset(descriptor);
                mlDataset.loadWholeDataset(rawDataset, true);

                dists = (new gpsiWholeSampler()).sample(mlDataset.getTrainingEntities(), this.classLabels);
                for (i = 0; i < this.classLabels.length; i++) {
                    stream.register(new gpsiDoubleCsvIOElement(dists[i], null,
                            "gens/f" + (f + 1) + "/" + classLabels[i] + "/" + (generation + 1) + ".csv"));
                }

            }

            fitnessCurves[generation] = new double[] { gp.getAllTimeBest().getFitnessValue() - 1.0 };
            System.out.printf("%3dg: %.4f\n", generation + 1, fitnessCurves[generation][0]);

        }

        best = new IGPProgram[2];
        best[0] = gp.getAllTimeBest();
        for (i = 0; i < super.validation; i++) {

            current = elite[i];

            descriptor = new gpsiScalarSpectralIndexDescriptor(
                    new gpsiJGAPVoxelCombiner(fitness.getB(), current));
            mlDataset = new gpsiMLDataset(descriptor);
            mlDataset.loadWholeDataset(rawDataset, true);

            samples = this.fitness.getSampler().sample(mlDataset.getValidationEntities(), classLabels);

            validationScore = fitness.getScore().score(samples);
            trainScore = current.getFitnessValue() - 1.0;

            currentScore = mean.evaluate(new double[] { trainScore, validationScore })
                    - sd.evaluate(new double[] { trainScore, validationScore });

            if (currentScore > bestScore) {
                best[1] = current;
                bestScore = currentScore;
            }

        }

        stream.register(new gpsiDoubleCsvIOElement(fitnessCurves, curveLabels, "curves/f" + (f + 1) + ".csv"));

        System.out.println("Best solution for trainning: " + gp.getAllTimeBest().toStringNorm(0));
        stream.register(new gpsiStringIOElement(gp.getAllTimeBest().toStringNorm(0),
                "programs/f" + (f + 1) + "train.program"));

        if (validation > 0) {
            System.out.println("Best solution for trainning and validation: " + best[1].toStringNorm(0));
            stream.register(new gpsiStringIOElement(best[1].toStringNorm(0),
                    "programs/f" + (f + 1) + "train_val.program"));
        }

        descriptor = new gpsiScalarSpectralIndexDescriptor(new gpsiJGAPVoxelCombiner(fitness.getB(), best[0]));
        gpsi1NNToMomentScalarClassificationAlgorithm classificationAlgorithm = new gpsi1NNToMomentScalarClassificationAlgorithm(
                new Mean());
        gpsiClassifier classifier = new gpsiClassifier(descriptor, classificationAlgorithm);

        classifier.fit(this.rawDataset.getTrainingEntities());
        classifier.predict(this.rawDataset.getTestEntities());

        int[][] confusionMatrix = classifier.getConfusionMatrix();

        stream.register(new gpsiIntegerCsvIOElement(confusionMatrix, null,
                "confusion_matrices/f" + (f + 1) + "_train.csv"));

        if (validation > 0) {
            descriptor = new gpsiScalarSpectralIndexDescriptor(
                    new gpsiJGAPVoxelCombiner(fitness.getB(), best[1]));
            classificationAlgorithm = new gpsi1NNToMomentScalarClassificationAlgorithm(new Mean());
            classifier = new gpsiClassifier(descriptor, classificationAlgorithm);

            classifier.fit(this.rawDataset.getTrainingEntities());
            classifier.predict(this.rawDataset.getTestEntities());

            confusionMatrix = classifier.getConfusionMatrix();

            stream.register(new gpsiIntegerCsvIOElement(confusionMatrix, null,
                    "confusion_matrices/f" + (f + 1) + "_train_val.csv"));

        }

    }

}

From source file:hyperheuristics.main.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" };

    String[] heuristicFunctions = new String[] { LowLevelHeuristic.CHOICE_FUNCTION,
            LowLevelHeuristic.MULTI_ARMED_BANDIT, LowLevelHeuristic.RANDOM };

    String[] algorithms = new String[] { "NSGA-II",
            //            "SPEA2"
    };/*from  w w  w  .ja  va  2  s.  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 (String 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 (String heuristicFunction : heuristicFunctions) {
                        latexTableBuilder.append(" & \\textbf{").append(algorithm).append("-")
                                .append(heuristicFunction).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 (String hyperHeuristic : heuristicFunctions) {
                                SolutionSet front = metricsUtil.readNonDominatedSolutionSet(
                                        "experiment/" + algorithm + "/" + objectives + "objectives/"
                                                + hyperHeuristic + "/" + 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 (String heuristic : heuristicFunctions) {
                            double[][] heuristicFront = metricsUtil.readFront("experiment/" + algorithm + "/"
                                    + objectives + "objectives/" + heuristic + "/" + problem + "/FUN.txt");
                            igdMap.put(algorithm + "-" + heuristic, igd
                                    .invertedGenerationalDistance(heuristicFront, trueFrontMatrix, objectives));
                            gdMap.put(algorithm + "-" + heuristic,
                                    gd.generationalDistance(heuristicFront, trueFrontMatrix, objectives));
                            spreadMap.put(algorithm + "-" + heuristic,
                                    spread.spread(heuristicFront, trueFrontMatrix, objectives));
                            coverageMap.put(algorithm + "-" + heuristic,
                                    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 (String heuristicFunction : heuristicFunctions) {
                                newHeuristicFunctions[i++] = algorithm + "-" + heuristicFunction;
                            }
                        }
                    }

                    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 (String 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 (String heuristicFunction : heuristicFunctions) {
                        latexTableBuilder.append(" & \\textbf{").append(algorithm).append("-")
                                .append(heuristicFunction).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 (String hyperHeuristic : heuristicFunctions) {
                                SolutionSet front = metricsUtil.readNonDominatedSolutionSet(
                                        "experiment/" + algorithm + "/" + objectives + "objectives/"
                                                + hyperHeuristic + "/" + 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 (String heuristic : heuristicFunctions) {
                            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/"
                                                + heuristic + "/" + 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 + "-" + heuristic, hhIGDs);
                            gdMap.put(algorithm + "-" + heuristic, hhGDs);
                            spreadMap.put(algorithm + "-" + heuristic, hhSpreads);
                            coverageMap.put(algorithm + "-" + heuristic, 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 (String heuristicFunction : heuristicFunctions) {
                                newHeuristicFunctions[i++] = algorithm + "-" + heuristicFunction;
                            }
                        }
                    }

                    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:hyperheuristics.main.comparisons.CompareHypervolumes.java

private static void generateTables(String[] problems, String[] 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 w w w . ja v  a2  s . c om
            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 (String 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 (String heuristicFunction : heuristicFunctions) {
                    tableString.append(" & \\textbf{").append(algorithm).append("-").append(heuristicFunction)
                            .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 (String heuristicFunction : heuristicFunctions) {
                        String path = outpath;
                        path += algorithm + "/" + numberOfObjectives + "objectives/";
                        String hyperheuristicDirectory = path + heuristicFunction + "/" + 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++) {
                        String heuristicFunction = heuristicFunctions[j];
                        String path = outpath;
                        path += algorithm + "/" + numberOfObjectives + "objectives/";
                        String hyperheuristicDirectory = path + heuristicFunction + "/" + 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 (String 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 (String heuristicFunction : heuristicFunctions) {
                    tableString.append(" & \\textbf{" + algorithm + "-" + heuristicFunction + "}");
                }
            }
            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 (String heuristicFunction : heuristicFunctions) {
                        String path = outpath;
                        path += algorithm + "/" + numberOfObjectives + "objectives/";
                        String hyperheuristicDirectory = path + heuristicFunction + "/" + 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];
                    String heuristicFunction = heuristicFunctions[i % heuristicFunctions.length];
                    String algorithm = algorithms[i / heuristicFunctions.length];
                    values.put(algorithm + "-" + heuristicFunction, 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:org.hawkular.datamining.forecast.utils.Utils.java

public static double standardDeviation(Double[] residuals) {
    double[] primitiveResiduals = ArrayUtils.toPrimitive(residuals);
    StandardDeviation standardDeviation = new StandardDeviation();
    return standardDeviation.evaluate(primitiveResiduals);
}