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:ch.epfl.lsir.xin.algorithm.baseline.ItemAverage.java

/**
 * this function predicts a rating from a user to an item
 * *//*from ww w  .  j  a  v  a2  s.  c  om*/
public double predict(int userIndex, int itemIndex) {
    double value = this.ratingMatrix.getItemMean(itemIndex);
    if (Double.isNaN(value)) {
        return this.ratingMatrix.getAverageRating();
    } else {
        return value;
    }
}

From source file:ch.epfl.lsir.xin.algorithm.baseline.UserAverage.java

/**
 * this function predicts a rating from a user to an item
 * *///from ww w .  j  av  a 2s.  co m
public double predict(int userIndex, int itemIndex) {
    double value = this.ratingMatrix.getUsersMean().get(userIndex);
    if (Double.isNaN(value)) {
        return this.ratingMatrix.getAverageRating();
    } else {
        return value;
    }
}

From source file:com.od.jtimeseries.ui.visualizer.chart.creator.EfficientXYLineAndShapeRenderer.java

/**
* Draws the item (first pass). This method draws the lines
* connecting the items.//from   w w  w .ja  v a  2 s  .c  o m
*
* @param g2  the graphics device.
* @param state  the renderer state.
* @param dataArea  the area within which the data is being drawn.
* @param plot  the plot (can be used to obtain standard color
*              information etc).
* @param domainAxis  the domain axis.
* @param rangeAxis  the range axis.
* @param dataset  the dataset.
* @param pass  the pass.
* @param series  the series index (zero-based).
* @param item  the item index (zero-based).
*/
protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset,
        int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
    if (item == 0) {
        return;
    }

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    double x0 = dataset.getXValue(series, item - 1);
    double y0 = dataset.getYValue(series, item - 1);
    if (Double.isNaN(y0) || Double.isNaN(x0)) {
        return;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    // only draw if we have good values
    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
        return;
    }

    int transX0Int = (int) transX0;
    int transX1Int = (int) transX1;

    //make sure we store the max and min y for this x
    boolean isSameX = transX0Int == transX1Int;
    if (isSameX) {
        minY = Math.min(transY0, minY);
        minY = Math.min(transY1, minY);
        maxY = Math.max(transY0, maxY);
        maxY = Math.max(transY1, maxY);
        storedLine = true;
    }

    //if we have moved x, or this the last item in the series, draw
    if (!isSameX || isLastItem(dataset, series, item)) {
        Stroke s = getItemStroke(series, item);
        Paint p = getItemPaint(series, item);
        if (storedLine) {
            drawLine(state, g2, plot, transX0Int, minY, transX0Int, maxY, s, p);
            linesDrawn++;
        }
        drawLine(state, g2, plot, transX0Int, transY0, transX1Int, transY1, s, p);
        linesDrawn++;
        storedLine = false;
        minY = Integer.MAX_VALUE;
        maxY = Integer.MIN_VALUE;
    }

    //           if ( isLastItem(dataset, series, item)) {
    //               System.out.println("Lines drawn " + linesDrawn + "/" + dataset.getItemCount(series));
    //           }
}

From source file:Main.java

/**
 * Returns <code>true</code> if the specified number is a
 * Not-a-Number (NaN) value, <code>false</code> otherwise.
 *
 * <p>Note that this method is equivalent to the {@link
 * Double#isNaN(double) Double.isNaN} method; the functionality is
 * included in this class for convenience.
 *
 * @param   d   the value to be tested./* w  ww.j  a v a 2s. c o m*/
 * @return  <code>true</code> if the value of the argument is NaN;
 *          <code>false</code> otherwise.
 */
public static boolean isNaN(double d) {
    return Double.isNaN(d);
}

From source file:com.joptimizer.util.Utils.java

/**
 * The smallest positive (epsilon) such that 1.0 + epsilon != 1.0.
 * @see http://en.wikipedia.org/wiki/Machine_epsilon#Approximation_using_Java
 *//* www .j  a  v a 2  s.  c  o m*/
public static final double getDoubleMachineEpsilon() {

    if (!Double.isNaN(RELATIVE_MACHINE_PRECISION)) {
        return RELATIVE_MACHINE_PRECISION;
    }

    synchronized (RELATIVE_MACHINE_PRECISION) {

        if (!Double.isNaN(RELATIVE_MACHINE_PRECISION)) {
            return RELATIVE_MACHINE_PRECISION;
        }

        double eps = 1.;
        do {
            eps /= 2.;
        } while ((double) (1. + (eps / 2.)) != 1.);

        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "Calculated double machine epsilon: " + eps);
        RELATIVE_MACHINE_PRECISION = eps;
    }

    return RELATIVE_MACHINE_PRECISION;
}

From source file:org.immutables.gson.stream.JsonGeneratorWriter.java

@Override
public JsonWriter value(double value) throws IOException {
    if (!isLenient() && (Double.isNaN(value) || Double.isInfinite(value))) {
        throw new IllegalArgumentException("JSON forbids NaN and infinities: " + value);
    }/*  w  ww.  ja  va  2  s. c om*/
    generator.writeNumber(value);
    return this;
}

From source file:de.ingrid.interfaces.csw.admin.validation.AbstractValidator.java

public void rejectIfNaN(final Errors errors, final String field) {
    Object val = errors.getFieldValue(field);
    if (val == null || (val instanceof Double && Double.isNaN((Double) val))) {
        rejectError(errors, field, "invalid");
    }/* w w  w .  j  av a  2  s  .c o m*/

}

From source file:com.backelite.sonarqube.commons.surefire.SurefireStaxHandler.java

private static long getTimeAttributeInMS(String value) throws XMLStreamException {
    // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602
    try {//from   ww w  . j  a  v a2s. c o  m
        Double time = ParsingUtils.parseNumber(value, Locale.ENGLISH);
        return !Double.isNaN(time) ? (long) ParsingUtils.scaleValue(time * 1000, 3) : 0L;
    } catch (ParseException e) {
        throw new XMLStreamException(e);
    }
}

From source file:com.clust4j.algo.preprocess.impute.MeanImputation.java

@Override
public double[][] transform(final double[][] dat) {
    checkMat(dat);/*from w w  w  . j a va 2  s .co  m*/

    final LogTimer timer = new LogTimer();
    final double[][] copy = MatUtils.copy(dat);
    final int m = dat.length, n = dat[0].length;
    info("(" + getName() + ") performing mean imputation on " + m + " x " + n + " dataset");

    // Operates in 2M * N
    for (int col = 0; col < n; col++) {
        int count = 0;
        double sum = 0;
        for (int row = 0; row < m; row++) {
            if (!Double.isNaN(copy[row][col])) {
                sum += copy[row][col];
                count++;
            }
        }

        int nanCt = m - count;
        double mean = sum / (double) count;
        for (int row = 0; row < m; row++) {
            if (Double.isNaN(copy[row][col])) {
                copy[row][col] = mean;
            }
        }

        info("(" + getName() + ") " + nanCt + " NaN" + (nanCt != 1 ? "s" : "") + " identified in column " + col
                + " (column mean=" + mean + ")");
    }

    sayBye(timer);
    return copy;
}

From source file:com.davidsoergel.stats.HeatmapSeries.java

public void incrementPoint(double x, double y, double zIncrement) //throws StatsException
//, final double startx, final double endx,final double starty, final double endy) throws StatsException
{
    if (Double.isNaN(x) || Double.isInfinite(x)) {
        //throw new StatsException("Invalid x value in HeatmapSeries: " + x);
        logger.warn("Invalid x value in HeatmapSeries: " + x);
        return;//w  w w.  ja  v  a 2  s  .  co  m
    }
    if (Double.isNaN(y) || Double.isInfinite(y)) {
        //throw new StatsException("Invalid y value in HeatmapSeries: " + y);
        logger.warn("Invalid y value in HeatmapSeries: " + y);
        return;
    }
    if (Double.isNaN(zIncrement) || Double.isInfinite(zIncrement)) {
        //throw new StatsException("Invalid zIncrement value in SimpleXYZSeries: " + zIncrement);
        logger.warn("Invalid zIncrement value in HeatmapSeries: " + zIncrement);
        return;
    }
    HeatmapPoint currentPoint = points.get(x, y);
    if (currentPoint != null) {
        currentPoint.z += zIncrement;
        updateBounds(x, y, currentPoint.z);
    } else {
        points.put(x, y, new HeatmapPoint(x, y, zIncrement)); //, startx, endx, starty, endy));

        updateBounds(x, y, zIncrement);
    }
}