Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

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

Prototype

public boolean isInfinite() 

Source Link

Document

Returns true if this Double value is infinitely large in magnitude, false otherwise.

Usage

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

private static Map<MarkerKey, MarkerManhattenData> assembleManhattenPlotData(OperationKey testOpKey)
        throws IOException {

    Map<MarkerKey, MarkerManhattenData> markerKeyChrPosPVal;

    CommonTestOperationDataSet<? extends TrendTestOperationEntry> testOpDS = (CommonTestOperationDataSet<? extends TrendTestOperationEntry>) OperationManager
            .generateOperationDataSet(testOpKey);
    final Iterator<MarkerKey> testOpMarkerKeys = testOpDS.getMarkersKeysSource().iterator();
    final Iterator<Double> testOpPValues = testOpDS.getPs(-1, -1).iterator();

    final DataSetSource matrixDS = MatrixFactory.generateMatrixDataSetSource(testOpKey.getParentMatrixKey());
    final MarkersMetadataSource matrixMarkersMS = matrixDS.getMarkersMetadatasSource();
    final Iterator<String> matrixMarkersChromosomes = matrixMarkersMS.getChromosomes().iterator();
    final Iterator<Integer> matrixMarkersPositions = matrixMarkersMS.getPositions().iterator();
    markerKeyChrPosPVal = new LinkedHashMap<MarkerKey, MarkerManhattenData>(matrixMarkersMS.size());
    MarkerKey nextTestMarkerKey = testOpMarkerKeys.hasNext() ? testOpMarkerKeys.next() : null;
    for (final MarkerKey markerKey : matrixDS.getMarkersKeysSource()) {
        final String chromosome = matrixMarkersChromosomes.next();
        final int position = matrixMarkersPositions.next();
        Double pValue;
        if (markerKey.equals(nextTestMarkerKey)) {
            pValue = testOpPValues.next();
            if (pValue.isNaN() || pValue.isInfinite()) { // Ignore invalid P-Values
                pValue = null;//from www.j a  v  a  2 s .c  o  m
            }
            nextTestMarkerKey = testOpMarkerKeys.hasNext() ? testOpMarkerKeys.next() : null;
        } else {
            // The current markerKey has no entry in the test operation,
            // thus we have no P-Value for it, so we mark it as totally insignificant.
            pValue = 1.0;
        }
        MarkerManhattenData data = new MarkerManhattenData(chromosome, position, pValue);
        markerKeyChrPosPVal.put(markerKey, data);
    }

    //      long snpNumber = rdInfoMarkerSet.getMarkerSetSize();
    //      if (snpNumber < 250000) {
    //         hetzyThreshold = 0.5 / snpNumber;  // (0.05 / 10^6 SNPs => 5*10^(-7))
    //      }

    return markerKeyChrPosPVal;
}

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];/*w  w  w  . j  ava 2s . 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.  j a va 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.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  va2s .  co m
    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:org.rhq.core.pc.measurement.MeasurementSenderRunner.java

private void cleanseInvalidNumericValues(MeasurementReport report) {
    Iterator<MeasurementDataNumeric> iter = report.getNumericData().iterator();
    while (iter.hasNext()) {
        MeasurementDataNumeric numeric = iter.next();
        Double value = numeric.getValue();
        if (value == null || value.isInfinite() || value.isNaN()) {
            if (LOG.isDebugEnabled()) {
                String stringValue = getStringValue(value);
                LOG.debug("Numeric metric [" + numeric.getName() + "] with schedule id ["
                        + numeric.getScheduleId() + "] is invalid - value is [" + stringValue + "].");
            }/*from  w  ww .  j  a  v  a  2 s.co  m*/
            iter.remove();
        }
    }
}

From source file:org.kordamp.ezmorph.object.BigDecimalMorpher.java

public Object morph(Object value) {
    if (value instanceof BigDecimal) {
        return value;
    }/*from   ww w .ja va  2 s  .com*/

    if (value == null) {
        if (isUseDefault()) {
            return defaultValue;
        } else {
            return (BigDecimal) null;
        }
    }

    if (value instanceof Number) {
        if (value instanceof Float) {
            Float f = ((Float) value);
            if (f.isInfinite() || f.isNaN()) {
                throw new MorphException("BigDecimal can not be infinite or NaN");
            }
        } else if (value instanceof Double) {
            Double d = ((Double) value);
            if (d.isInfinite() || d.isNaN()) {
                throw new MorphException("BigDecimal can not be infinite or NaN");
            }
        } else if (value instanceof BigInteger) {
            return new BigDecimal((BigInteger) value);
        }

        return new BigDecimal(((Number) value).doubleValue());
    } else {
        try {
            String str = String.valueOf(value).trim();
            if (str.length() == 0 || str.equalsIgnoreCase("null")) {
                return (BigDecimal) null;
            } else {
                return new BigDecimal(str);
            }
        } catch (NumberFormatException nfe) {
            if (isUseDefault()) {
                return defaultValue;
            } else {
                throw new MorphException(nfe);
            }
        }
    }
}

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;/* ww  w  .  ja  v  a 2 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.kordamp.ezmorph.object.BigIntegerMorpher.java

public Object morph(Object value) {
    if (value instanceof BigInteger) {
        return value;
    }//  ww w  .  j a  v  a  2 s . co m

    if (value == null) {
        if (isUseDefault()) {
            return defaultValue;
        } else {
            return (BigInteger) null;
        }
    }

    if (value instanceof Number) {
        if (value instanceof Float) {
            Float f = ((Float) value);
            if (f.isInfinite() || f.isNaN()) {
                throw new MorphException("BigInteger can not be infinite or NaN");
            }
        } else if (value instanceof Double) {
            Double d = ((Double) value);
            if (d.isInfinite() || d.isNaN()) {
                throw new MorphException("BigInteger can not be infinite or NaN");
            }
        } else if (value instanceof BigDecimal) {
            return ((BigDecimal) value).toBigInteger();
        }
        return BigInteger.valueOf(((Number) value).longValue());
    } else {
        try {
            String str = getIntegerValue(value);
            if (str.length() == 0 || str.equalsIgnoreCase("null")) {
                return (BigInteger) null;
            } else {
                return new BigInteger(str);
            }
        } catch (NumberFormatException nfe) {
            if (isUseDefault()) {
                return defaultValue;
            } else {
                throw new MorphException(nfe);
            }
        }
    }
}

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;/*from   w ww.  java2 s.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:org.openscience.cdk.applications.taverna.qsar.GetMolecularWeightDistributionFromQSARVectorActivity.java

@Override
@SuppressWarnings("unchecked")
public void work() throws Exception {
    // Get input/*w w  w.ja  v  a2s  . c o m*/
    Map<UUID, Map<String, Object>> vectorMap;
    try {
        vectorMap = (Map<UUID, Map<String, Object>>) this.getInputAsObject(this.INPUT_PORTS[0]);
    } catch (Exception e) {
        ErrorLogger.getInstance().writeError(CDKTavernaException.WRONG_INPUT_PORT_TYPE, this.getActivityName(),
                e);
        throw new CDKTavernaException(this.getConfiguration().getActivityName(), e.getMessage());
    }
    File targetFile = this.getInputAsFile(this.INPUT_PORTS[1]);
    String directory = Tools.getDirectory(targetFile);
    String name = Tools.getFileName(targetFile);
    // Do work
    ChartTool chartTool = new ChartTool();
    ArrayList<String> molIdSWeightCSV = new ArrayList<String>();
    ArrayList<String> weightDistributionCSV = new ArrayList<String>();
    try {
        QSARVectorUtility util = new QSARVectorUtility();
        List<UUID> uuids = util.getUUIDs(vectorMap);
        LinkedList<Double> weigths = new LinkedList<Double>();
        int maxWeight = 0;
        molIdSWeightCSV.add("ID;Molecular Weight (g/mol);");
        for (int i = 0; i < uuids.size(); i++) {
            UUID uuid = uuids.get(i);
            Map<String, Object> values = vectorMap.get(uuid);
            Double weight = (Double) values.get("weight");
            if (weight.isInfinite() || weight.isNaN()) {
                continue;
            }
            weigths.add(weight);
            if (weight.intValue() > maxWeight) {
                maxWeight = weight.intValue();
            }
            molIdSWeightCSV.add(uuid.toString() + ";" + String.format("%.2f", weight) + ";");
        }
        int[] weightDistribution = new int[maxWeight + 1];
        for (Double weight : weigths) {
            int value = weight.intValue();
            weightDistribution[value]++;
        }
        weightDistributionCSV.add("Molecular Weight (g/mol);Number Of Molecules;");
        for (int i = 1; i < weightDistribution.length; i++) {
            weightDistributionCSV.add(i + ";" + weightDistribution[i] + ";");
        }
        // Create chart
        XYSeries series = new XYSeries("Weight");
        for (int i = 0; i < weightDistribution.length; i++) {
            series.add(i, weightDistribution[i]);
        }
        XYSeriesCollection dataset = new XYSeriesCollection(series);
        JFreeChart chart = chartTool.createXYBarChart("Weight Distribution", "Weight (g/mol)",
                "Number of Compounds", dataset, true, false);
        File file = FileNameGenerator.getNewFile(directory, ".pdf", name);
        chartTool.writeChartAsPDF(file, Collections.singletonList((Object) chart));
    } catch (Exception e) {
        ErrorLogger.getInstance().writeError("Error during extraction of molecular weight from QSAR vector!",
                this.getActivityName(), e);
        throw new CDKTavernaException(this.getConfiguration().getActivityName(), e.getMessage());
    }
    // Set output
    this.setOutputAsStringList(weightDistributionCSV, this.OUTPUT_PORTS[0]);
    this.setOutputAsStringList(molIdSWeightCSV, this.OUTPUT_PORTS[1]);
}