Example usage for org.apache.commons.math3.stat.descriptive.moment Mean Mean

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

Introduction

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

Prototype

public Mean() 

Source Link

Document

Constructs a Mean.

Usage

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"
    };//ww  w. j a v a2 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:cz.cuni.mff.d3s.spl.utils.StatisticsUtils.java

/** Compute arithmetic mean of given data.
 * //from ww  w .  j av  a 2  s.  co  m
 * @param values Array of values to compute the mean from.
 * @return Mean of the provided values.
 */
public static double mean(double... values) {
    Mean mean = new Mean();
    return mean.evaluate(values);
}

From source file:br.unicamp.ic.recod.gpsi.measures.gpsiNormalBhattacharyyaDistanceScore.java

@Override
public double score(double[][][] input) {

    Mean mean = new Mean();
    Variance var = new Variance();

    double mu0, sigs0, mu1, sigs1;
    double dist[][] = new double[2][];

    dist[0] = MatrixUtils.createRealMatrix(input[0]).getColumn(0);
    dist[1] = MatrixUtils.createRealMatrix(input[1]).getColumn(0);

    mu0 = mean.evaluate(dist[0]);//from   w  w w  .  j a va 2s.c o  m
    sigs0 = var.evaluate(dist[0]) + Double.MIN_VALUE;
    mu1 = mean.evaluate(dist[1]);
    sigs1 = var.evaluate(dist[1]) + Double.MIN_VALUE;

    double distance = (Math.log((sigs0 / sigs1 + sigs1 / sigs0 + 2) / 4)
            + (Math.pow(mu1 - mu0, 2.0) / (sigs0 + sigs1))) / 4;

    return distance == Double.POSITIVE_INFINITY ? 0 : distance;

}

From source file:br.unicamp.ic.recod.gpsi.measures.gpsiMeanAndStandardDeviationDistanceScore.java

@Override
public double score(double[][][] input) {

    double[][] means = new double[2][];
    double[] sDistances;
    VectorialMean mean;//  w w w .j  av  a 2 s. co m
    Mean mean_ = new Mean();
    EuclideanDistance distance = new EuclideanDistance();

    int i, j;
    double d = 0;

    for (i = 0; i < 2; i++) {
        mean = new VectorialMean(input[i][0].length);
        for (j = 0; j < input[i].length; j++)
            mean.increment(input[i][j]);
        means[i] = mean.getResult();
    }

    d = distance.compute(means[0], means[1]);

    double deviations = 0.0;

    for (i = 0; i < 2; i++) {
        sDistances = new double[input[i].length];
        for (j = 0; j < input[i].length; j++)
            sDistances[j] = distance.compute(means[i], input[i][j]);
        deviations += mean_.evaluate(sDistances);
    }

    return d / deviations;

}

From source file:com.facebook.presto.benchmark.driver.Stat.java

public Stat(double[] values) {
    mean = new Mean().evaluate(values);
    standardDeviation = new StandardDeviation().evaluate(values);
    median = new Median().evaluate(values);
}

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

public ScaleQualityStatistics() {
    var = new Variance(false);
    mean = new Mean();
}

From source file:com.cloudera.oryx.rdf.common.eval.Evaluation.java

/**
 * @param classifier a {@link com.cloudera.oryx.rdf.common.tree.TreeBasedClassifier} (e.g. {@link com.cloudera.oryx.rdf.common.tree.DecisionForest})
 *  trained on data with a numeric target
 * @param testSet test set to evaluate on
 * @return root mean squared error over the test set square root of mean squared difference between actual
 *  and predicted numeric target value//from   w w  w.j ava2 s .  c o  m
 */
public static double rootMeanSquaredError(TreeBasedClassifier classifier, Iterable<Example> testSet) {
    StorelessUnivariateStatistic mse = new Mean();
    for (Example test : testSet) {
        NumericFeature actual = (NumericFeature) test.getTarget();
        NumericPrediction prediction = (NumericPrediction) classifier.classify(test);
        double diff = actual.getValue() - prediction.getPrediction();
        mse.increment(diff * diff);
    }
    return FastMath.sqrt(mse.getResult());
}

From source file:com.cloudera.oryx.common.stats.RunningStatistics.java

public RunningStatistics() {
    this.mean = new Mean();
    this.min = new Min();
    this.max = new Max();
}

From source file:com.itemanalysis.psychometrics.cmh.CmhTableRow.java

public CmhTableRow(Object rowValue) {
    this.rowValue = rowValue;
    columns = new Frequency();
    mean = new Mean();
}

From source file:com.itemanalysis.psychometrics.irt.estimation.RaschScaleQualityStatistics.java

public RaschScaleQualityStatistics() {
    var = new Variance(false);
    mean = new Mean();
}