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:OAT.ui.util.TradeRenderer.java

@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    //        setSeriesShape(series, new DefaultCaret(), false);

    //Enter, Exit
    double y = dataset.getYValue(series, item);
    int side = ((TradeDataset) dataset).get(item).getSide().sign;

    if (Double.isNaN(y) || y <= 0) {
        setSeriesPaint(series, null, false);
        setSeriesStroke(series, null, false);
        setSeriesShape(series, null, false);
    } else {// w w  w.  j  a  v a 2s .  c o m
        setSeriesPaint(series, side * (series == 0 ? 1 : -1) > 0 ? Main.longColor : Main.shortColor, false);
        setSeriesStroke(series, Main.defaultStoke, false);
        setSeriesShape(series, series == 0 ? Main.enterShape : Main.exitShape, false);
    }

    super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
            crosshairState, pass);
}

From source file:com.insightml.math.statistics.Correlation.java

public Correlation(final double[] x, final double[] y) {
    arrays = new double[2][x.length];
    for (int i = 0; i < x.length; ++i) {
        arrays[0][i] = x[i];/*from   w  ww . ja v a2s  . co  m*/
        arrays[1][i] = y[i];
    }
    final DoubleLinkedList x2 = new DoubleLinkedList();
    final DoubleLinkedList y2 = new DoubleLinkedList();
    for (int i = 0; i < x.length; ++i) {
        if (!Double.isNaN(x[i])) {
            x2.add(x[i]);
            y2.add(y[i]);
        }
    }
    final double[] x2arr = x2.toArray();
    final double[] y2arr = y2.toArray();
    covariance = new Covariance().covariance(x2arr, y2arr);
    pearson = new PearsonsCorrelation().correlation(x2arr, y2arr);
    spearman = new SpearmansCorrelation().correlation(x2arr, y2arr);
    mean = (Math.abs(pearson) + Math.abs(spearman)) / 2;
}

From source file:com.sciaps.utils.ImportExportSpectrumCSV.java

public void exportSpectrumFile(File saveFile, PiecewiseSpectrum spectrum) throws IOException {
    if (spectrum == null || saveFile == null) {
        logger_.warn("", "will not save spectrum csv file");
        return;/*from ww w.j  a v a2 s.co  m*/
    }

    final UnivariateFunction intensity = spectrum.getIntensityFunction();

    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile)));
    try {
        bout.append("wavelength, intensity");
        bout.newLine();
        final DoubleRange range = spectrum.getValidRange();

        for (double x = range.getMinimumDouble(); x <= range.getMaximumDouble(); x += 1.0
                / EXPORT_SAMPLE_RATE) {
            double y = intensity.value(x);
            if (Double.isNaN(y)) {
                y = 0;
            }
            bout.append(Double.toString(x));
            bout.append(", ");
            bout.append(Double.toString(y));
            bout.newLine();
        }
    } finally {
        bout.close();
    }

    logger_.info("saved spectrum csv file to " + saveFile.getAbsolutePath());
}

From source file:cpcc.core.utils.GeoJsonUtils.java

/**
 * Extends an existing bounding box by checking if or if not a position is within that box. If the position is not
 * within the box, the box will be enlarged to include the position.
 * /*w  w  w.j a v a 2 s .co  m*/
 * @param boundingBox an existing bounding box.
 * @param position a position not yet considered in the bounding box.
 */
public static void mergeBoundingBox(double[] boundingBox, LngLatAlt position) {
    double lon = position.getLongitude();
    double lat = position.getLatitude();

    if (Double.isNaN(boundingBox[0]) || lon < boundingBox[0]) {
        boundingBox[0] = lon;
    }

    if (Double.isNaN(boundingBox[1]) || lat < boundingBox[1]) {
        boundingBox[1] = lat;
    }

    if (Double.isNaN(boundingBox[2]) || lon > boundingBox[2]) {
        boundingBox[2] = lon;
    }

    if (Double.isNaN(boundingBox[3]) || lat > boundingBox[3]) {
        boundingBox[3] = lat;
    }
}

From source file:com.opengamma.analytics.math.rootfinding.BracketRoot.java

/**
 * @param f The function, not null/*from   w w w. ja va2 s.co  m*/
 * @param xLower Initial value of lower bracket
 * @param xUpper Initial value of upper bracket
 * @return The bracketed points as an array, where the first element is the lower bracket and the second the upper bracket.
 * @throws MathException If a root is not bracketed in 50 attempts.
 */
public double[] getBracketedPoints(final Function1D<Double, Double> f, final double xLower,
        final double xUpper) {
    Validate.notNull(f, "f");
    double x1 = xLower;
    double x2 = xUpper;
    double f1 = 0;
    double f2 = 0;
    f1 = f.evaluate(x1);
    f2 = f.evaluate(x2);
    if (Double.isNaN(f1)) {
        throw new MathException("Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1);
    }
    if (Double.isNaN(f2)) {
        throw new MathException("Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2);
    }

    for (int count = 0; count < MAX_STEPS; count++) {
        if (f1 * f2 < 0) {
            return new double[] { x1, x2 };
        }
        if (Math.abs(f1) < Math.abs(f2)) {
            x1 += RATIO * (x1 - x2);
            f1 = f.evaluate(x1);
            if (Double.isNaN(f1)) {
                throw new MathException(
                        "Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1);
            }
        } else {
            x2 += RATIO * (x2 - x1);
            f2 = f.evaluate(x2);
            if (Double.isNaN(f2)) {
                throw new MathException(
                        "Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2);
            }
        }
    }
    throw new MathException("Failed to bracket root");
}

From source file:ai.susi.mind.SusiCognition.java

public SusiCognition(final SusiMind mind, final String query, int timezoneOffset, double latitude,
        double longitude, int maxcount, ClientIdentity identity) {
    this.json = new JSONObject(true);

    // get a response from susis mind
    String client = identity.getClient();
    this.setQuery(query);
    this.json.put("count", maxcount);
    SusiThought observation = new SusiThought();
    observation.addObservation("timezoneOffset", Integer.toString(timezoneOffset));

    if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
        observation.addObservation("latitude", Double.toString(latitude));
        observation.addObservation("longitude", Double.toString(longitude));
    }//w  ww .  j  a  va 2s.  c o m
    this.json.put("client_id", Base64.getEncoder().encodeToString(UTF8.getBytes(client)));
    long query_date = System.currentTimeMillis();
    this.json.put("query_date", DateParser.utcFormatter.print(query_date));

    // compute the mind reaction
    List<SusiArgument> dispute = mind.react(query, maxcount, client, observation);
    long answer_date = System.currentTimeMillis();

    // store answer and actions into json
    this.json.put("answers", new JSONArray(
            dispute.stream().map(argument -> argument.finding(client, mind)).collect(Collectors.toList())));
    this.json.put("answer_date", DateParser.utcFormatter.print(answer_date));
    this.json.put("answer_time", answer_date - query_date);
    this.json.put("language", "en");
}

From source file:jasmine.imaging.core.JasmineCorrelationGraph.java

public void processData() {
    DefaultCategoryDataset series = new DefaultCategoryDataset();

    for (int i = 0; i < observed.length; i++) {
        StatisticsSolver obs = observed[i];
        double correlation = obs.getCorrelationWith(expected);
        if (!Double.isNaN(correlation)) {
            series.addValue(correlation, "series1", names[i]);
        }//from  w  w w.  j av a 2s. c  o  m
        System.out.println(names[i] + ": " + correlation);
    }

    myChart = ChartFactory.createBarChart(null, "Features", "Pearson Correlation", series,
            PlotOrientation.VERTICAL, false, false, false);

}

From source file:fr.ens.transcriptome.teolenn.util.MathUtils.java

/**
 * Remove NaN from an array/*from   w w  w.j  ava 2s . c  o m*/
 * @param data Array to use
 * @return an new array without NaN values
 */
public static double[] removeNaN(final double[] data) {

    if (data == null)
        return null;

    int count = 0;

    for (int i = 0; i < data.length; i++)
        if (Double.isNaN(data[i]))
            count++;

    if (count == 0)
        return data;

    final double[] result = new double[count];
    count = 0;

    for (int i = 0; i < result.length; i++)
        if (!Double.isNaN(data[i]))
            result[count++] = data[i];

    return result;
}

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

public void addPoint(final double x, final double y, final double z, 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;//from w  w  w.j  ava 2s .c o 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(z) || Double.isInfinite(z)) {
        //throw new StatsException("Invalid z value in HeatmapSeries: " + z);
        logger.warn("Invalid z value in HeatmapSeries: " + z);
        return;
    }
    points.put(x, y, new HeatmapPoint(x, y, z)); //, startx, endx, starty, endy));
    updateBounds(x, y, z);
}

From source file:kieker.tools.opad.timeseries.forecast.mean.MeanForecasterJava.java

/**
 *
 * @param allHistory//from w  w w.j  a  v a  2s. co m
 *            List there null values should deltet in this function
 * @return List/Array with no NullValues
 */
public static Double[] removeNullValues(final List<Double> allHistory) {
    final List<Double> newList = new ArrayList<Double>();

    for (final Object obj : allHistory) {
        if ((null != obj) && (obj instanceof Double) && !Double.isNaN((Double) obj)) {
            newList.add((Double) obj);
        }
    }
    return newList.toArray(new Double[newList.size()]);
}