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 static boolean isNaN(double v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:dr.math.distributions.PoissonDistribution.java

public static double logPdf(double x, double mean) {
    PoissonDistributionImpl dist = new PoissonDistributionImpl(mean);
    double pdf = dist.probability(x);
    if (pdf == 0 || Double.isNaN(pdf)) { // bad estimate
        return x * Math.log(mean) - Poisson.gammln(x + 1) - mean;
    }//from  w ww.  jav  a2  s . com
    return Math.log(pdf);

}

From source file:beast.math.distributions.BetaDistribution.java

private void recomputeZ() {
    if (Double.isNaN(z)) {
        z = Gamma.logGamma(alpha) + Gamma.logGamma(beta) - Gamma.logGamma(alpha + beta);
    }
}

From source file:com.dataartisans.flinktraining.exercises.datastream_java.utils.TravelTimePredictionModel.java

/**
 * Predicts the time of a taxi to arrive from a certain direction and Euclidean distance.
 *
 * @param direction The direction from which the taxi arrives.
 * @param distance The Euclidean distance that the taxi has to drive.
 * @return A prediction of the time that the taxi will be traveling or -1 if no prediction is
 *         possible, yet./*from   w  w w.  j  a  v  a  2 s .  com*/
 */
public int predictTravelTime(int direction, double distance) {
    byte directionBucket = getDirectionBucket(direction);
    double prediction = models[directionBucket].predict(distance);

    if (Double.isNaN(prediction)) {
        return -1;
    } else {
        return (int) prediction;
    }
}

From source file:org.jreserve.dummy.plot.charts.AbstractBarChart.java

private void updateBounds(double v) {
    if (Double.isNaN(minValue) || minValue > v)
        minValue = v;//from w w w . j av  a2 s  . c om
    if (Double.isNaN(maxValue) || maxValue < v)
        maxValue = v;
}

From source file:net.librec.recommender.item.RecommendedItemListTestCase.java

public static void testSparseMatrixAndRecommender() {
    Table<Integer, Integer, Double> table = HashBasedTable.create();
    table.put(1, 2, 3.0);/*  w  ww  .  j  a  va  2  s .  c o m*/
    table.put(3, 4, 3.0);
    table.put(5, 2, 3.0);
    table.put(4, 6, 3.0);
    SparseMatrix testMatrix = new SparseMatrix(6, 7, table);
    for (MatrixEntry matrixEntry : testMatrix) {
        System.out.println(matrixEntry.row() + " " + matrixEntry.column() + " " + matrixEntry.get());
    }
    System.out.println();

    int numUsers = 6;
    RecommendedItemList recommendedList = new RecommendedItemList(numUsers - 1, numUsers);

    for (MatrixEntry matrixEntry : testMatrix) {
        int userIdx = matrixEntry.row();
        int itemIdx = matrixEntry.column();
        double predictRating = 3.0;
        if (Double.isNaN(predictRating)) {
            predictRating = 2.0;
        }
        recommendedList.addUserItemIdx(userIdx, itemIdx, predictRating);
    }

    Iterator<MatrixEntry> testMatrixIter = testMatrix.iterator();
    Iterator<UserItemRatingEntry> recommendedEntryIter = recommendedList.entryIterator();

    while (testMatrixIter.hasNext()) {

        if (recommendedEntryIter.hasNext()) {

            MatrixEntry testMatrixEntry = testMatrixIter.next();
            UserItemRatingEntry userItemRatingEntry = recommendedEntryIter.next();

            System.out.println(
                    testMatrixEntry.row() + " " + testMatrixEntry.column() + " " + testMatrixEntry.get());
            System.out.println(userItemRatingEntry.getUserIdx() + " " + userItemRatingEntry.getItemIdx() + " "
                    + userItemRatingEntry.getValue());

            if (testMatrixEntry.row() == userItemRatingEntry.getUserIdx()
                    && testMatrixEntry.column() == userItemRatingEntry.getItemIdx()) {
            } else {
                throw new IndexOutOfBoundsException("index of recommendedList does not equal testMatrix index");
            }

        } else {
            throw new IndexOutOfBoundsException(
                    "index size of recommendedList does not equal testMatrix index size");
        }
    }
}

From source file:com.yahoo.egads.models.tsmm.TimeSeriesAbstractModel.java

public static boolean betterThan(TimeSeriesAbstractModel model1, TimeSeriesAbstractModel model2) {
    // Special case. Any model is better than no model!
    if (model2 == null) {
        return true;
    }/*from  w w  w .  j  a  v  a  2s  .  c o m*/

    int score = 0;
    score += compareError(model1.getBias(), model2.getBias());
    score += compareError(model1.getMAD(), model2.getMAD());
    score += compareError(model1.getMAPE(), model2.getMAPE());
    score += compareError(model1.getMSE(), model2.getMSE());
    score += compareError(model1.getSAE(), model2.getSAE());

    if (score == 0) {
        // At this point, we're still unsure which one is best
        // so we'll take another approach
        double mapeDiff = model1.getMAPE() - model2.getMAPE();
        double diff = model1.getBias() - model2.getBias() + model1.getMAD() - model2.getMAD()
                + (Double.isNaN(mapeDiff) ? 0 : mapeDiff) + model1.getMSE() - model2.getMSE() + model1.getSAE()
                - model2.getSAE();
        return (diff < 0);
    }

    return (score > 0);
}

From source file:io.warp10.continuum.gts.GTSOutliersHelper.java

protected static double max(GeoTimeSerie gts) throws WarpScriptException {
    double max = gts.doubleValues[0];
    if (Double.isNaN(max)) {
        throw new WarpScriptException("Method max: GTS contains NaN");
    }//w  w  w .j  av a  2  s  . c  om

    for (int i = 1; i < gts.values; i++) {
        if (max < gts.doubleValues[i]) {
            max = gts.doubleValues[i];
        }
    }
    return max;
}

From source file:jmbench.plots.OverallRelativeAreaPlot.java

public void addLibrary(String name, int seriesIndex, double[] results) {
    for (int i = 0; i < sizeNames.length; i++) {
        double v = results[i];
        if (!Double.isNaN(v))
            dataset.addValue(v, name, sizeNames[i]);
    }/*  w  w  w.  j  a v  a  2 s . c  om*/

    StackedAreaRenderer renderer = (StackedAreaRenderer) plot.getRenderer();

    float STROKE_SIZE = 5f;

    //        renderer.setSeriesPaint(numDataSets, OperationsVersusSizePlot.getColor(seriesIndex));
    renderer.setSeriesStroke(numDataSets,
            OperationsVersusSizePlot.getStroke(seriesIndex, STROKE_SIZE, STROKE_SIZE * 2));

    numDataSets++;
}

From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java

private static double[] prepareForSummaryStatsAlternative(Number[] x, int length) {
    double[] retvector = new double[length];

    int c = 0;//from www.j av a2  s .c  o m
    for (int i = 0; i < x.length; i++) {
        if (x[i] != null) {
            double xvalue = x[i].doubleValue();
            if (!Double.isNaN(xvalue)) {
                retvector[c++] = xvalue;
            }
        }
    }

    // Throw exception if c != length in the end?

    return retvector;
}

From source file:pzalejko.iot.hardware.home.core.service.DefaultTemperatureService.java

@Override
public Optional<TemperatureEntity> getTemperatureEntity() {
    final double temperature = loadTemperatureFromFile(sourceFilePath, fileName);
    if (!Double.isNaN(temperature)) {
        LOG.debug(LogMessages.READ_TEMPERATURE, temperature);
        return Optional.of(new TemperatureEntity(temperature, System.currentTimeMillis()));
    }//from  w ww .java  2  s.  com

    return Optional.empty();
}