Example usage for java.lang Double isNaN

List of usage examples for java.lang Double isNaN

Introduction

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

Prototype

public boolean isNaN() 

Source Link

Document

Returns true if this Double value is a Not-a-Number (NaN), false otherwise.

Usage

From source file:weka.core.ChartUtils.java

/**
 * Create a box plot from summary data (mean, median, q1, q3, min, max,
 * minOutlier, maxOutlier, list of outliers)
 * //  w  w w . j  a  v  a2  s  .c om
 * @param summary summary data
 * @param outliers list of outlier values
 * @param additionalArgs additional options to the renderer
 * @return a box plot chart
 * @throws Exception if a problem occurs
 */
protected static JFreeChart getBoxPlotFromSummaryData(List<Double> summary, List<Double> outliers,
        List<String> additionalArgs) throws Exception {

    if (summary.size() != 8) {
        throw new Exception("Expected 8 values in the summary argument: mean, median, "
                + "q1, q3, min, max, minOutlier, maxOutlier");
    }

    String plotTitle = "Box Plog";
    String userTitle = getOption(additionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
    String xLabel = getOption(additionalArgs, "-x-label");
    xLabel = xLabel == null ? "" : xLabel;
    String yLabel = getOption(additionalArgs, "-y-label");
    yLabel = yLabel == null ? "" : yLabel;

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    Double mean = summary.get(0);
    Double median = summary.get(1);
    Double q1 = summary.get(2);
    Double q3 = summary.get(3);
    Double min = summary.get(4);
    Double max = summary.get(5);
    Double minOutlier = summary.get(6);
    Double maxOutlier = summary.get(7);

    if (mean.isNaN() || median.isNaN() || min.isNaN() || max.isNaN() || q1.isNaN() || q3.isNaN()) {
        throw new Exception("NaN in summary data - can't generate box plot");
    }

    BoxAndWhiskerItem item = new BoxAndWhiskerItem(mean, median, q1, q3, min, max, minOutlier, maxOutlier,
            outliers);

    dataset.add(item, "", "");

    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.15);

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(plotTitle, new Font("SansSerif", Font.BOLD, 12), plot, false);

    return chart;
}

From source file:edu.jhuapl.bsp.detector.OpenMath.java

public static double median(double[] in) {
    if (in != null) {
        if (in.length > 0) {
            double[] d = new double[in.length];
            for (int i = 0; i < in.length; i++) {
                d[i] = in[i];/*from w w w . jav  a  2  s  .c  o m*/
            }
            Arrays.sort(d);
            Double median = null;
            int index = (int) Math.ceil(d.length / 2);
            if ((d.length & 1) == 1) {
                median = new Double(d[index]);
            } else {
                median = new Double((d[index] + d[index - 1]) / 2.0);
            }
            if (median.isNaN() || median.isInfinite()) {
                return 0.0;
            } else {
                return median.doubleValue();
            }
        } else {
            return 0.0;
        }
    }
    return 0.0;
}

From source file:edu.jhuapl.bsp.detector.OpenMath.java

public static double[] median(double[][] in) {
    if (in != null) {
        int M = in.length, N = in[0].length;
        double medians[] = ones(N, 0);
        double vals[] = new double[M];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                vals[j] = in[j][i];//from   w  ww  .  jav a  2 s  . co m
            }
            Arrays.sort(vals);
            Double median = null;
            int index = (int) Math.ceil(vals.length / 2);
            if ((vals.length & 1) == 1) {
                median = new Double(vals[index]);
            } else {
                median = new Double((vals[index] + vals[index - 1]) / 2.0);
            }
            if (!median.isNaN() && !median.isInfinite()) {
                medians[i] = median;
            }
        }
        return medians;
    }
    return new double[0];
}

From source file:com.liferay.dynamic.data.mapping.form.evaluator.internal.functions.IsDecimalFunction.java

@Override
public Object evaluate(Object... parameters) {
    if (parameters.length != 1) {
        throw new IllegalArgumentException("One parameter is expected");
    }/* w w w. ja  v a2 s . c  o m*/

    Double value = NumberUtils.toDouble(parameters[0].toString(), Double.NaN);

    return !value.isNaN();
}

From source file:com.krawler.baseline.crm.bizservice.el.ExpressionManagerImpl.java

public Object evaluateExpression(String expression, String key, Map<String, ExpressionVariables> variables) {
    Object result = null;//  w w w. ja  va2 s .c om
    if (variables != null && !variables.isEmpty()) {
        Object compiledExpression = MVEL.compileExpression(expression);

        for (ExpressionVariables variable : variables.values()) {
            try {
                result = MVEL.executeExpression(compiledExpression, variable.getVariablesMapForFormulae());
                if (result instanceof Double) {
                    Double d = (Double) result;
                    if (d == null || d.isInfinite() || d.isNaN())
                        result = null;
                }
                variable.getOutputMap().put(key, result);
            } catch (Exception e) {
                LOG.info("Can't evaluate the expression:" + expression, e);
            }
        }
    }
    return result;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.features.wordDifficulty.FrequencyOfWordAndContextUFE.java

private void addToFeatureList(String featureName, Double prob, String phrase) {
    if (prob.isNaN() || prob.isInfinite()) {
        prob = 0.0;/*from  ww w  .  ja  v a2 s.c o  m*/
        logger.log(Level.INFO, "No prob for: " + phrase);
    }
    // the frequency calculation of ngrams with - or ' does not work properly
    // weka replaces the missing value with the mean of the feature for most classifiers

    if (prob == 0.0 && StringUtils.containsAny(phrase, "-'")) {
        featList.addAll(
                Arrays.asList(new Feature(featureName, new MissingValue(MissingValueNonNominalType.NUMERIC))));
    }
    featList.addAll(Arrays.asList(new Feature(PROBABILITY, prob)));

}

From source file:org.gwaspi.reports.GenericReportGenerator.java

public static XYDataset getManhattanZoomByChrAndPos(ManhattanPlotZoom manhattanPlotZoom, OperationKey testOpKey,
        ChromosomeKey chr, MarkerKey markerKey, long requestedPhysPos, long requestedPosWindow) {
    XYDataset resultXYDataset = null;//w ww.j av  a 2s  .c  o m

    try {
        // ESTIMATE WINDOW SIZE
        Long minPosition;
        Long maxPosition;
        if (markerKey == null) {
            minPosition = requestedPhysPos;
            maxPosition = minPosition + requestedPosWindow;
        } else {
            final Long middlePosition = requestedPhysPos;
            minPosition = Math.round(middlePosition - (double) requestedPosWindow / 2);
            maxPosition = minPosition + requestedPosWindow;
        }

        Map<MarkerKey, Object[]> markerKeyChrPosPVal;

        CommonTestOperationDataSet<? extends TrendTestOperationEntry> testOpDS = (CommonTestOperationDataSet<? extends TrendTestOperationEntry>) OperationManager
                .generateOperationDataSet(testOpKey);
        Iterator<MarkerMetadata> markersMetadatasIt = testOpDS.getMarkersMetadatasSource().iterator();
        Iterator<Double> psIt = testOpDS.getPs(-1, -1).iterator();
        markerKeyChrPosPVal = new LinkedHashMap<MarkerKey, Object[]>(testOpDS.getNumMarkers());
        for (MarkerKey curMarkerKey : testOpDS.getMarkersKeysSource()) {
            Double pValue = psIt.next();
            MarkerMetadata markerMetadata = markersMetadatasIt.next();
            String curChr = markerMetadata.getChr();
            int curPos = markerMetadata.getPos();
            if (!curChr.equals(chr.toString()) || (curPos >= minPosition) || (curPos <= maxPosition)) {
                continue;
            }
            if (pValue.isNaN() || pValue.isInfinite()) { // Ignore invalid P-Values
                pValue = null;
            }
            Object[] data = new Object[] { markerMetadata.getChr(), markerMetadata.getPos(), pValue };
            markerKeyChrPosPVal.put(curMarkerKey, data);
        }

        //<editor-fold defaultstate="expanded" desc="BUILD XYDataset">
        XYSeries dataSeries = new XYSeries("");

        Map<String, MarkerKey> labeler = new LinkedHashMap<String, MarkerKey>();
        for (Map.Entry<MarkerKey, Object[]> entry : markerKeyChrPosPVal.entrySet()) {
            MarkerKey tmpMarker = entry.getKey();
            Object[] data = entry.getValue(); // CHR, POS, PVAL

            int position = (Integer) data[1];
            double pVal = 1;
            if (data[2] != null) {
                pVal = (Double) data[2]; // Is allready free of NaN
            }

            if (pVal < 1 && !Double.isInfinite(pVal)) {
                dataSeries.add(position, pVal);
                labeler.put(chr + "_" + position, tmpMarker);
                //labeler.put(key, "");
            }
        }
        manhattanPlotZoom.setLabelerMap(labeler);

        dataSeries.setDescription("Zoom chr " + chr + " from position " + minPosition + " to " + maxPosition);

        resultXYDataset = new XYSeriesCollection(dataSeries);
        //</editor-fold>
    } catch (IOException ex) {
        log.error(null, ex);
    }

    return resultXYDataset;
}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCategoricalCorrelationPlot.java

private List<Double> removeNaNandNulls(List<Double> inputList) {
    List<Double> dList = new ArrayList<Double>();
    for (Double d : inputList) {
        if ((d != null) && (!d.isNaN())) {
            dList.add(d);/*from  w w  w.  j  a v a2 s . c  o m*/
        }
    }
    return dList;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.DRInitialController.java

/**
 * Create the table model for the top panel table. Table contains
 * log-transformed concentration and replicate slopes per condition
 *
 * @param dataToFit/*from  w w  w .j ava 2s .c om*/
 * @return the model
 */
protected NonEditableTableModel createTableModel(List<DoseResponsePair> dataToFit) {
    int maxReplicates = 0;
    for (DoseResponsePair entry : dataToFit) {
        int replicates = entry.getResponses().size();
        if (replicates > maxReplicates) {
            maxReplicates = replicates;
        }
    }
    Object[][] data = new Object[dataToFit.size()][maxReplicates + 1];

    int rowIndex = 0;
    for (DoseResponsePair entry : dataToFit) {
        //log concentration is put on 1st column
        data[rowIndex][0] = AnalysisUtils.roundThreeDecimals(entry.getDose());

        for (int columnIndex = 1; columnIndex < entry.getResponses().size() + 1; columnIndex++) {
            try {
                Double slope = entry.getResponses().get(columnIndex - 1);
                if (slope != null && !slope.isNaN()) {
                    // round to three decimals slopes and coefficients
                    slope = AnalysisUtils.roundThreeDecimals(entry.getResponses().get(columnIndex - 1));
                    // show in table slope + (coefficient)
                    data[rowIndex][columnIndex] = slope;
                } else if (slope == null) {
                    data[rowIndex][columnIndex] = "excluded";
                } else if (slope.isNaN()) {
                    data[rowIndex][columnIndex] = "NaN";
                }
            } catch (IndexOutOfBoundsException e) {
                data[rowIndex][columnIndex] = "";
            }

        }
        rowIndex++;
    }
    // array of column names for table model
    String[] columnNames = new String[data[0].length];
    columnNames[0] = "Log-concentration";
    for (int x = 1; x < columnNames.length; x++) {
        columnNames[x] = "Repl " + (x);
    }

    NonEditableTableModel nonEditableTableModel = new NonEditableTableModel();
    nonEditableTableModel.setDataVector(data, columnNames);
    return nonEditableTableModel;
}

From source file:mondrian.udf.InverseNormalUdf.java

public Object execute(Evaluator evaluator, Argument[] args) {
    final Object argValue = args[0].evaluateScalar(evaluator);
    LOGGER.debug("Inverse Normal argument was : " + argValue);
    if (!(argValue instanceof Number)) {
        // Argument might be a RuntimeException indicating that
        // the cache does not yet have the required cell value. The
        // function will be called again when the cache is loaded.
        return null;
    }/*from   ww  w.ja  v  a 2s .c o m*/

    final Double d = new Double(((Number) argValue).doubleValue());
    LOGGER.debug("Inverse Normal argument as Double was : " + d);

    if (d.isNaN()) {
        return null;
    }

    // If probability is nonnumeric or
    //   probability < 0 or
    //   probability > 1,
    // returns an error.
    double dbl = d.doubleValue();
    if (dbl < 0.0 || dbl > 1.0) {
        LOGGER.debug("Invalid value for inverse normal distribution: " + dbl);
        throw new MondrianEvaluationException("Invalid value for inverse normal distribution: " + dbl);
    }
    try {
        Double result = new Double(nd.inverseCumulativeProbability(dbl));
        LOGGER.debug("Inverse Normal result : " + result.doubleValue());
        return result;
    } catch (MathException e) {
        LOGGER.debug("Exception calculating inverse normal distribution: " + dbl, e);
        throw new MondrianEvaluationException("Exception calculating inverse normal distribution: " + dbl);
    }
}