Example usage for java.lang Double NEGATIVE_INFINITY

List of usage examples for java.lang Double NEGATIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Double NEGATIVE_INFINITY.

Prototype

double NEGATIVE_INFINITY

To view the source code for java.lang Double NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type double .

Usage

From source file:dr.evomodel.epidemiology.casetocase.CaseToCaseTreeLikelihood.java

private double getLatestTaxonTime() {
    double latestTime = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < treeModel.getExternalNodeCount(); i++) {
        Taxon taxon = treeModel.getNodeTaxon(treeModel.getExternalNode(i));
        if (taxon.getDate().getTimeValue() > latestTime) {
            latestTime = taxon.getDate().getTimeValue();
        }/*from  www .  j a va  2 s .co  m*/

    }
    return latestTime;
}

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat64DecodeNegInfinity() throws IOException {
    JsonParser p = f.createParser("\"-Infinity\"");
    p.nextToken();// w ww  .  ja  va 2  s. c  o  m
    assertTrue(Double.NEGATIVE_INFINITY == JsonValueHandler.FLOAT64.readValue(p));
}

From source file:beast.evolution.tree.partitioned.IndividualSEIR.java

public double evaluateLogP() {

    //        try {
    //            PrintStream firstSteam = new PrintStream("tt.nex");
    ///* w ww .j  a v  a2  s.co  m*/
    //            PartitionedTreeLogger.debugLog(tree, 0, false, firstSteam);
    //        } catch (FileNotFoundException e){
    //            e.printStackTrace();
    //        }

    double transLogProb = 0;

    double rate = baseTransmissionRate.getValue();

    ArrayList<ClinicalCase> previouslyInfectious = new ArrayList<>();

    double currentEventTime;
    boolean first = true;

    for (TreeEvent event : sortedTreeEvents) {
        currentEventTime = event.getTime();

        ClinicalCase thisCase = event.getCase();

        if (event.getType() == EventType.INFECTION) {
            if (first) {
                // index infection

                if (indexCasePrior != null) {
                    transLogProb += Math.log(indexCasePrior.get(thisCase));
                }
                if (initialInfectionTimePrior != null) {
                    transLogProb += initialInfectionTimePrior.logDensity(currentEventTime);
                }
                if (!hasLatentPeriods) {
                    previouslyInfectious.add(thisCase);
                }

                first = false;

            } else {

                ClinicalCase infector = event.getInfector();

                if (thisCase.wasEverInfected()) {
                    if (previouslyInfectious.contains(thisCase)) {
                        return Double.NEGATIVE_INFINITY;
                    }
                    if (event.getTime() > thisCase.getEndTime()) {
                        return Double.NEGATIVE_INFINITY;
                    }
                    if (infector.getEndTime() < event.getTime()) {
                        return Double.NEGATIVE_INFINITY;
                    }
                    if (getInfectiousTime(infector) > event.getTime()) {
                        return Double.NEGATIVE_INFINITY;
                    }
                    if (!previouslyInfectious.contains(infector)) {
                        throw new RuntimeException("Infector not previously infected");
                    }
                }

                // no other previously infectious case has infected this case...

                for (ClinicalCase nonInfector : previouslyInfectious) {

                    double timeDuringWhichNoInfection;
                    if (nonInfector.getEndTime() < event.getTime()) {
                        timeDuringWhichNoInfection = nonInfector.getEndTime() - getInfectiousTime(nonInfector);
                    } else {
                        timeDuringWhichNoInfection = event.getTime() - getInfectiousTime(nonInfector);
                    }

                    if (timeDuringWhichNoInfection < 0) {
                        throw new RuntimeException("negative time");
                    }

                    double transRate = rate;
                    if (hasGeography) {
                        try {
                            transRate *= kernel.getValue((GeographicallyLocatedClinicalCase) thisCase,
                                    (GeographicallyLocatedClinicalCase) nonInfector);
                        } catch (FunctionEvaluationException e) {
                            e.printStackTrace();
                        }
                    }

                    transLogProb += -transRate * timeDuringWhichNoInfection;
                }

                // ...until the end

                if (thisCase.wasEverInfected()) {
                    double transRate = rate;
                    if (hasGeography) {
                        try {
                            transRate *= kernel.getValue((GeographicallyLocatedClinicalCase) thisCase,
                                    (GeographicallyLocatedClinicalCase) infector);
                        } catch (FunctionEvaluationException e) {
                            e.printStackTrace();
                        }
                    }
                    transLogProb += Math.log(transRate);
                }
                if (!hasLatentPeriods) {
                    previouslyInfectious.add(thisCase);
                }
            }

        } else if (event.getType() == EventType.INFECTIOUSNESS) {
            if (event.getTime() < Double.POSITIVE_INFINITY) {

                if (event.getTime() > event.getCase().getEndTime()) {
                    return Double.NEGATIVE_INFINITY;
                }

                if (first) {
                    throw new RuntimeException("First event is not an infection");
                }

                previouslyInfectious.add(thisCase);
            }
        }
    }

    double periodsLogProb = 0;

    for (DurationDistribution category : infectiousCategories) {
        if (category.hasProbability()) {
            List<ClinicalCase> relevantCases = new ArrayList<>();

            for (ClinicalCase aCase : outbreak.getCases()) {
                if (getInfectiousCategory(aCase) == category) {
                    relevantCases.add(aCase);
                }
            }

            Double[] infectiousPeriods = new Double[relevantCases.size()];

            for (int i = 0; i < infectiousPeriods.length; i++) {
                infectiousPeriods[i] = relevantCases.get(i).getEndTime()
                        - getInfectiousTime(relevantCases.get(i));
            }

            RealParameter collectionOfValues = new RealParameter(infectiousPeriods);

            periodsLogProb += category.getLogProbability(collectionOfValues);
        }
    }

    // just reject states where these round to +INF

    if (transLogProb == Double.POSITIVE_INFINITY) {
        System.out.println("TransLogProb +INF");
        return Double.NEGATIVE_INFINITY;
    }
    if (periodsLogProb == Double.POSITIVE_INFINITY) {
        System.out.println("PeriodsLogProb +INF");
        return Double.NEGATIVE_INFINITY;
    }

    logP = periodsLogProb + transLogProb;

    return logP;
}

From source file:net.iponweb.hadoop.streaming.avro.IOWJsonDecoder.java

@Override
public double readDouble() throws IOException {
    advance(Symbol.DOUBLE);/*from  w w  w  .ja va2 s  .  co  m*/
    if (in.getCurrentToken().isNumeric()) {
        double result = in.getDoubleValue();
        in.nextToken();
        return result;
    } else {
        try {
            String s = in.getText();
            in.nextToken();
            if (s.equals("NaN")) {
                return Double.NaN;
            } else if (s.equals("-Inf")) {
                return Double.NEGATIVE_INFINITY;
            } else if (s.equals("+Inf")) {
                return Double.POSITIVE_INFINITY;
            } else {
                return Double.parseDouble(s);
            }
        } catch (Exception e) {
            throw error("double (" + e.getMessage() + ")");
        }
    }
}

From source file:no.ntnu.idi.dm.clustering.KMeans.java

/**
 * Get a new centroid for empty clusters. We therefore take the instance
 * with the largest SSE to the cluster centroid having the largest SSE. Get
 * the idea? Read slowly.//  ww  w. j ava  2 s .  co  m
 * 
 * @return a new centroid (rather: a clone thereof :))
 */
private double[] getSubstituteCentroid() {
    double maxSSE = Double.NEGATIVE_INFINITY;
    int maxSSEIndex = -1;
    for (int clusterIndex = 0; clusterIndex < k; clusterIndex++) {
        clusters[clusterIndex].calculateCentroid(data);
        double currentSSE = clusters[clusterIndex].SSE(data);
        if (currentSSE > maxSSE) {
            maxSSE = currentSSE;
            maxSSEIndex = clusterIndex;
        }
    }

    if (clusters[maxSSEIndex].getInstanceIndexWithMaxSSE(data) == -1) {
        return null;
    }
    return data[clusters[maxSSEIndex].getInstanceIndexWithMaxSSE(data)].clone();
}

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.  j a va2  s.c o  m
            tableString.append("\\documentclass{paper}\n" + "\n" + "\\usepackage[T1]{fontenc}\n"
                    + "\\usepackage[latin1]{inputenc}\n" + "\\usepackage[hidelinks]{hyperref}\n"
                    + "\\usepackage{tabulary}\n" + "\\usepackage{booktabs}\n" + "\\usepackage{multirow}\n"
                    + "\\usepackage{amsmath}\n" + "\\usepackage{mathtools}\n" + "\\usepackage{graphicx}\n"
                    + "\\usepackage{array}\n" + "\\usepackage[linesnumbered,ruled,inoutnumbered]{algorithm2e}\n"
                    + "\\usepackage{subfigure}\n" + "\\usepackage[hypcap]{caption}\n"
                    + "\\usepackage{pdflscape}\n" + "\n" + "\\begin{document}\n" + "\n" + "\\begin{landscape}\n"
                    + "\n");

            tableString
                    .append("\\begin{table}[!htb]\n" + "\t\\centering\n" + "\t\\def\\arraystretch{1.5}\n"
                            + "\t\\setlength{\\tabcolsep}{10pt}\n" + "\t\\fontsize{8pt}{10pt}\\selectfont"
                            + "\t\\caption{Hypervolume of the $PF_{known}$ fronts for ")
                    .append(numberOfObjectives).append(" objectives}\n" + "\t\\label{tab:Hypervolumes ")
                    .append(numberOfObjectives).append(" objectives}\n" + "\t\\begin{tabulary}{\\textwidth}{c");
            for (String algorithm : algorithms) {
                tableString.append("c");
                for (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.apache.drill.exec.fn.impl.TestNewMathFunctions.java

@Test
public void testLog10WithDouble() throws Throwable {
    String json = "{" + "\"positive_infinity\" : Infinity," + "\"negative_infinity\" : -Infinity,"
            + "\"nan\" : NaN," + "\"num1\": 0.0," + "\"num2\": 0.1," + "\"num3\": 1.0," + "\"num4\": 1.5,"
            + "\"num5\": -1.5," + "\"num6\": 10.0" + "}";
    String query = "select " + "log10(positive_infinity) as pos_inf, " + "log10(negative_infinity) as neg_inf, "
            + "log10(nan) as nan, " + "log10(num1) as num1, " + "log10(num2) as num2, "
            + "log10(num3) as num3, " + "log10(num4) as num4, " + "log10(num5) as num5, "
            + "log10(num6) as num6 " + "from dfs.`data.json`";
    File file = new File(dirTestWatcher.getRootDir(), "data.json");
    try {//from w w w.j  a  va  2 s . c  om
        FileUtils.writeStringToFile(file, json);
        setSessionOption(ExecConstants.JSON_READ_NUMBERS_AS_DOUBLE, true);
        setSessionOption(ExecConstants.JSON_READER_NAN_INF_NUMBERS, true);
        testBuilder().sqlQuery(query).ordered()
                .baselineColumns("pos_inf", "neg_inf", "nan", "num1", "num2", "num3", "num4", "num5", "num6")
                .baselineValues(Double.POSITIVE_INFINITY, Double.NaN, Double.NaN, Double.NEGATIVE_INFINITY,
                        -1.0d, 0d, 0.17609125905568124d, Double.NaN, 1.0d)
                .go();
    } finally {
        resetSessionOption(ExecConstants.JSON_READ_NUMBERS_AS_DOUBLE);
        resetSessionOption(ExecConstants.JSON_READER_NAN_INF_NUMBERS);
        FileUtils.deleteQuietly(file);
    }
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

public JFreeChart getChart(List<String> idsToPaint) {
    if (paramX == null || paramY == null) {
        return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend);
    }//from w w  w  . ja  va  2 s  . c o m

    NumberAxis xAxis = new NumberAxis(AttributeUtilities.getNameWithUnit(paramX, unitX, transformX));
    NumberAxis yAxis = new NumberAxis(AttributeUtilities.getNameWithUnit(paramY, unitY, transformY));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    double usedMinX = Double.POSITIVE_INFINITY;
    double usedMaxX = Double.NEGATIVE_INFINITY;
    int index = 0;
    ColorAndShapeCreator colorAndShapeCreator = new ColorAndShapeCreator(idsToPaint.size());

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        try {
            if (plotable != null) {
                if (plotable.getType() == Plotable.BOTH || plotable.getType() == Plotable.BOTH_STRICT) {
                    Double minArg = Plotable.transform(
                            plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX),
                            transformX);
                    Double maxArg = Plotable.transform(
                            plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX),
                            transformX);

                    if (isValid(minArg)) {
                        usedMinX = Math.min(usedMinX, minArg);
                    }

                    if (isValid(maxArg)) {
                        usedMaxX = Math.max(usedMaxX, maxArg);
                    }

                    for (Map<String, Integer> choice : plotable.getAllChoices()) {
                        double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX,
                                transformY, choice);

                        if (points != null) {
                            for (int i = 0; i < points[0].length; i++) {
                                if (isValid(points[0][i])) {
                                    usedMinX = Math.min(usedMinX, points[0][i]);
                                    usedMaxX = Math.max(usedMaxX, points[0][i]);
                                }
                            }
                        }
                    }
                } else if (plotable.getType() == Plotable.DATASET
                        || plotable.getType() == Plotable.DATASET_STRICT) {
                    double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX,
                            transformY);

                    if (points != null) {
                        for (int i = 0; i < points[0].length; i++) {
                            if (isValid(points[0][i])) {
                                usedMinX = Math.min(usedMinX, points[0][i]);
                                usedMaxX = Math.max(usedMaxX, points[0][i]);
                            }
                        }
                    }
                } else if (plotable.getType() == Plotable.FUNCTION) {
                    Double minArg = Plotable.transform(
                            plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX),
                            transformX);
                    Double maxArg = Plotable.transform(
                            plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX),
                            transformX);

                    if (isValid(minArg)) {
                        usedMinX = Math.min(usedMinX, minArg);
                    }

                    if (isValid(maxArg)) {
                        usedMaxX = Math.max(usedMaxX, maxArg);
                    }
                } else if (plotable.getType() == Plotable.FUNCTION_SAMPLE) {
                    Double minArg = Plotable.transform(
                            plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX),
                            transformX);
                    Double maxArg = Plotable.transform(
                            plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX),
                            transformX);

                    if (isValid(minArg)) {
                        usedMinX = Math.min(usedMinX, minArg);
                    }

                    if (isValid(maxArg)) {
                        usedMaxX = Math.max(usedMaxX, maxArg);
                    }

                    for (Double x : plotable.getSamples()) {
                        Double xx = Plotable.transform(plotable.convertToUnit(paramX, x, unitX), transformX);

                        if (isValid(xx)) {
                            usedMinX = Math.min(usedMinX, xx);
                            usedMaxX = Math.max(usedMaxX, xx);
                        }
                    }
                }
            }
        } catch (ConvertException e) {
        }
    }

    if (Double.isInfinite(usedMinX)) {
        usedMinX = 0.0;
    }

    if (Double.isInfinite(usedMaxX)) {
        usedMaxX = 100.0;
    }

    if (paramX.equals(AttributeUtilities.TIME) || paramX.equals(AttributeUtilities.CONCENTRATION)) {
        usedMinX = Math.min(usedMinX, 0.0);
        xAxis.setAutoRangeIncludesZero(true);
    } else {
        xAxis.setAutoRangeIncludesZero(false);
    }

    if (paramY.equals(AttributeUtilities.TIME) || paramY.equals(AttributeUtilities.CONCENTRATION)) {
        yAxis.setAutoRangeIncludesZero(true);
    } else {
        yAxis.setAutoRangeIncludesZero(false);
    }

    if (usedMinX == usedMaxX) {
        usedMinX -= 1.0;
        usedMaxX += 1.0;
    }

    if (useManualRange && minX < maxX && minY < maxY) {
        usedMinX = minX;
        usedMaxX = maxX;
        xAxis.setRange(new Range(minX, maxX));
        yAxis.setRange(new Range(minY, maxY));
    }

    Set<ConvertException> convertExceptions = new LinkedHashSet<>();

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable != null && plotable.getType() == Plotable.DATASET) {
            try {
                plotDataSet(plot, plotable, id, colorAndShapeCreator.getColorList().get(index),
                        colorAndShapeCreator.getShapeList().get(index));
                index++;
            } catch (ConvertException e) {
                convertExceptions.add(e);
            }
        }
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable != null && plotable.getType() == Plotable.DATASET_STRICT) {
            try {
                plotDataSetStrict(plot, plotable, id);
                index++;
            } catch (ConvertException e) {
                convertExceptions.add(e);
            }
        }
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable != null && plotable.getType() == Plotable.FUNCTION) {
            try {
                plotFunction(plot, plotable, id, colorAndShapeCreator.getColorList().get(index),
                        colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX);
                index++;
            } catch (ConvertException e) {
                convertExceptions.add(e);
            }
        }
    }

    warnings = new ArrayList<>();

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable != null && plotable.getType() == Plotable.FUNCTION_SAMPLE) {
            try {
                plotFunctionSample(plot, plotable, id, colorAndShapeCreator.getColorList().get(index),
                        colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX, warnings);
                index++;
            } catch (ConvertException e) {
                convertExceptions.add(e);
            }
        }
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable != null && plotable.getType() == Plotable.BOTH) {
            try {
                plotBoth(plot, plotable, id, colorAndShapeCreator.getColorList().get(index),
                        colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX);
                index++;
            } catch (ConvertException e) {
                convertExceptions.add(e);
            }
        }
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable != null && plotable.getType() == Plotable.BOTH_STRICT) {
            try {
                plotBothStrict(plot, plotable, id, usedMinX, usedMaxX);
                index++;
            } catch (ConvertException e) {
                convertExceptions.add(e);
            }
        }
    }

    if (!convertExceptions.isEmpty()) {
        String warning = "Some datasets/functions cannot be converted to the desired unit\n";

        warning += "Uncovertable units: ";

        for (ConvertException e : convertExceptions) {
            warning += e.getFromUnit() + "->" + e.getToUnit() + ", ";
        }

        warning = warning.substring(0, warning.length() - 2);

        JOptionPane.showMessageDialog(this, warning, "Warning", JOptionPane.WARNING_MESSAGE);
    }

    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
}

From source file:bacter.model.ACGCoalescent.java

/**
 * Compute probability of recombinant edges under conditional coalescent.
 * @param conv conversion with which edge is associated
 * @return log(P)//from   w  w w .jav  a2s  . c  o  m
 */
public double calculateConversionLogP(Conversion conv) {

    double thisLogP = 0.0;

    List<CFEventList.Event> events = acg.getCFEvents();

    // Probability density of location of recombinant edge start
    thisLogP += Math.log(1.0 / acg.getClonalFrameLength());

    // Identify interval containing the start of the recombinant edge
    int startIdx = 0;
    while (events.get(startIdx + 1).getHeight() < conv.getHeight1())
        startIdx += 1;

    for (int i = startIdx; i < events.size() && events.get(i).getHeight() < conv.getHeight2(); i++) {

        double timeA = Math.max(events.get(i).getHeight(), conv.getHeight1());

        double timeB;
        if (i < events.size() - 1)
            timeB = Math.min(conv.getHeight2(), events.get(i + 1).getHeight());
        else
            timeB = conv.getHeight2();

        double intervalArea = popFunc.getIntegral(timeA, timeB);
        thisLogP += -events.get(i).getLineageCount() * intervalArea;
    }

    // Probability of single coalescence event
    thisLogP += Math.log(1.0 / popFunc.getPopSize(conv.getHeight2()));

    // Probability of start site:
    if (conv.getStartSite() == 0) {
        thisLogP += Math.log(deltaInput.get().getValue()
                / (acg.getConvertibleLoci().size() * (deltaInput.get().getValue() - 1)
                        + acg.getTotalConvertibleSequenceLength()));
    } else {
        if (!acg.wholeLocusModeOn())
            thisLogP += Math.log(1.0 / (acg.getConvertibleLoci().size() * (deltaInput.get().getValue() - 1)
                    + acg.getTotalConvertibleSequenceLength()));
        else
            return Double.NEGATIVE_INFINITY;
    }

    // Probability of end site:
    if (conv.getEndSite() == conv.getLocus().getSiteCount() - 1) {
        thisLogP += (conv.getLocus().getSiteCount() - 1 - conv.getStartSite())
                * Math.log(1.0 - 1.0 / deltaInput.get().getValue());
    } else {
        if (!acg.wholeLocusModeOn())
            thisLogP += (conv.getEndSite() - conv.getStartSite())
                    * Math.log(1.0 - 1.0 / deltaInput.get().getValue()) - Math.log(deltaInput.get().getValue());
        else
            return Double.NEGATIVE_INFINITY;
    }

    return thisLogP;
}

From source file:egat.cli.strategyregret.StrategyRegretCommandHandler.java

protected void findRegret(Profile profile, SymmetricGame game) {
    Player[] players = profile.players().toArray(new Player[0]);
    Strategy[] strategies = new Strategy[players.length];

    for (int i = 0; i < players.length; i++) {
        strategies[i] = profile.getStrategy(players[i]);
    }//from  w ww .jav  a 2  s.co  m

    int playerIndex = 0;

    if (playerId != null) {
        for (int i = 0; i < players.length; i++) {
            if (playerId.equals(players[i].getID())) {
                playerIndex = i;
                break;
            }
        }
    }

    System.out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    System.out.print("<strategy-regret>");

    double maxPayoff = Double.NEGATIVE_INFINITY;

    Action[] actions = game.getActions().toArray(new Action[0]);
    double[] payoffs = new double[actions.length];

    for (int i = 0; i < actions.length; i++) {
        strategies[playerIndex] = Games.createStrategy(new Action[] { actions[i] }, new Number[] { 1.0 });
        double response = game.payoff(Games.createProfile(players, strategies)).getPayoff(players[0])
                .getValue();
        payoffs[i] = response;
        maxPayoff = Math.max(response, maxPayoff);
    }

    for (int i = 0; i < actions.length; i++) {
        System.out.print(String.format("<action id=\"%s\" regret=\"%f\" />", actions[i].getID(),
                maxPayoff - payoffs[i]));
    }

    System.out.print("</strategy-regret>");
}