Example usage for java.lang Double NEGATIVE_INFINITY

List of usage examples for java.lang Double NEGATIVE_INFINITY

Introduction

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

Prototype

double NEGATIVE_INFINITY

To view the source code for java.lang Double NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type double .

Usage

From source file:org.ramadda.geodata.cdmdata.PointDatabaseTypeHandler.java

/**
 * _more_/* w w  w . j  a  v a  2  s . c om*/
 *
 * @param v _more_
 *
 * @return _more_
 */
protected double checkWriteValue(double v) {
    if (v != v) {
        return MISSING;
    }
    if (v == Double.POSITIVE_INFINITY) {
        return Double.MAX_VALUE;
    }
    if (v == Double.NEGATIVE_INFINITY) {
        return -Double.MAX_VALUE;
    }

    return v;
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JFreeChart createPredictionBarChart(PredictionCenter center) throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0)
            .getTransactionTypeNames();/*w w  w  . j ava 2s .  c  o  m*/
    for (int i = 0; i < numLegends; ++i) {
        String legend = (String) legends[i];
        for (int j = 0; j < transactionNames.size(); ++j) {
            if (legend.contains("Type " + (j + 1))) {
                legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j));
                break;
            }
        }
    }
    for (int j = 0; j < transactionNames.size(); ++j) {
        if (xLabel.contains("Type " + (j + 1))) {
            xLabel = xLabel.replace("Type " + (j + 1), transactionNames.get(j));
            break;
        }
    }
    for (int j = 0; j < transactionNames.size(); ++j) {
        if (yLabel.contains("Type " + (j + 1))) {
            yLabel = yLabel.replace("Type " + (j + 1), transactionNames.get(j));
            break;
        }
    }

    for (int i = 0; i < numYCellArray; ++i) {
        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        int row = (int) yArraySize[0];
        int col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            String category = "";
            int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount;
            String legend = (String) legends[legendIdx];
            if (numLegends == 0) {
                category = "Data " + dataCount + 1;
            } else if (dataCount >= numLegends) {
                category = legend + (dataCount + 1);
            } else {
                category = legend;
            }

            for (int r = 0; r < row; ++r) {
                double yValue = yArray[r + c * row];
                // remove negatives.
                if (yValue < 0 || yValue == Double.NaN || yValue == Double.POSITIVE_INFINITY
                        || yValue == Double.NEGATIVE_INFINITY) {
                    yValue = 0.0;
                }

                dataset.addValue(yValue, category, "");
            }
            ++dataCount;
        }
    }

    JFreeChart chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataset);

    return chart;
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

public static double getMax(double[] data) {
    double max = Double.NEGATIVE_INFINITY;
    for (double d : data)
        if (d > max)
            max = d;/*from   w ww .  j  a  va2 s. c o m*/
    return max;
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

public static Range getBounds(double[] data) {
    double min = Double.MAX_VALUE;
    double max = Double.NEGATIVE_INFINITY;
    for (double d : data) {
        if (d < min)
            min = d;/*from   w  ww .  jav  a  2 s  .  co m*/
        if (d > max)
            max = d;
    }
    return new Range(min, max);
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#compareTo(java.lang.Number, java.lang.Number)}.
 *//* w ww .j  av  a 2s.  co  m*/
@SuppressWarnings("unchecked")
@Test
public void testCompareToNumberNumber() {
    assertEquals("null", (Object) 0, compareTo(null, null));
    assertEquals("null", (Object) 1, compareTo(1, null));
    assertEquals("null", (Object) 1, compareTo(-1, null));
    assertEquals("null", (Object) 1, compareTo(Float.NEGATIVE_INFINITY, null));
    assertEquals("null", (Object) (-1), compareTo(null, 1));
    assertEquals("null", (Object) (-1), compareTo(null, -1));
    assertEquals("null", (Object) (-1), compareTo(null, Double.NEGATIVE_INFINITY));
    assertEquals("Infinity", (Object) 0, compareTo(Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY));
    assertEquals("Infinity", (Object) 0, compareTo(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, null));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, 1));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, -1));
    assertEquals("NaN", (Object) 1, compareTo(Float.NaN, Double.POSITIVE_INFINITY));
    assertEquals("NaN", (Object) 0, compareTo(Float.NaN, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(null, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(1, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(-1, Double.NaN));
    assertEquals("NaN", (Object) (-1), compareTo(Float.NEGATIVE_INFINITY, Double.NaN));
    assertEquals("NaN", (Object) 0, compareTo(Double.NaN, Float.NaN));
    for (Class<?> type : NUMBERS) {
        Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
        try {
            Number n = null;
            if (ClassUtils.isPrimitiveWrapper(type)) {
                n = (Number) wrapper.getField("MAX_VALUE").get(null);
            } else {
                n = INFINITY_DOUBLE.pow(2);
                if (BigInteger.class.equals(type))
                    n = ((BigDecimal) n).toBigInteger();
            }
            assertEquals("equals: " + type.getSimpleName(), 0, compareTo(n, new BigDecimal(n.toString())));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java

/**
* The cross gamma - the sensitity of the delta to the strike $\frac{\partial^2 V}{\partial f \partial K}$
* @param spot The spot value of the underlying
* @param strike The Strike//from  w ww .  ja  v a  2  s.  c o m
* @param timeToExpiry The time-to-expiry
* @param lognormalVol The log-normal volatility
* @param interestRate The interest rate 
* @param costOfCarry The cost-of-carry  rate
* @return The dual gamma
*/
@ExternalFunction
public static double crossGamma(final double spot, final double strike, final double timeToExpiry,
        final double lognormalVol, final double interestRate, final double costOfCarry) {
    ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot);
    ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike);
    ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry);
    ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol);
    ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN");
    ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN");

    if (-interestRate > LARGE) {
        return costOfCarry > LARGE ? 0. : Double.NEGATIVE_INFINITY;
    }
    if (interestRate > LARGE) {
        return 0.;
    }
    double discount = (Math.abs(interestRate) < SMALL && timeToExpiry > LARGE) ? 1.
            : Math.exp(-interestRate * timeToExpiry);

    final double rootT = Math.sqrt(timeToExpiry);
    double sigmaRootT = lognormalVol * rootT;
    if (Double.isNaN(sigmaRootT)) {
        sigmaRootT = 1.; //ref value is returned
    }
    if (spot > LARGE * strike || spot < SMALL * strike || sigmaRootT > LARGE) {
        return 0.;
    }

    double factor = Math.exp(costOfCarry * timeToExpiry);
    if (Double.isNaN(factor)) {
        factor = 1.; //ref value is returned
    }

    double d2 = 0.;
    if (Math.abs(spot - strike) < SMALL || (spot > LARGE && strike > LARGE)) {
        final double coefD1 = (Math.abs(costOfCarry) < SMALL && lognormalVol < SMALL)
                ? Math.signum(costOfCarry) - 0.5 * lognormalVol
                : (costOfCarry / lognormalVol - 0.5 * lognormalVol);
        final double tmp = coefD1 * rootT;
        d2 = Double.isNaN(tmp) ? 0. : tmp;
    } else {
        if (sigmaRootT < SMALL) {
            final double scnd = (Math.abs(costOfCarry) > LARGE && rootT < SMALL) ? Math.signum(costOfCarry)
                    : costOfCarry * rootT;
            final double tmp = (Math.log(spot / strike) / rootT + scnd) / lognormalVol;
            d2 = Double.isNaN(tmp) ? 0. : tmp;
        } else {
            final double tmp = costOfCarry * rootT / lognormalVol;
            final double sig = (costOfCarry >= 0.) ? 1. : -1.;
            final double scnd = Double.isNaN(tmp)
                    ? ((lognormalVol < LARGE && lognormalVol > SMALL) ? sig / lognormalVol : sig * rootT)
                    : tmp;
            d2 = Math.log(spot / strike) / sigmaRootT + scnd - 0.5 * sigmaRootT;
        }
    }
    //    if (Double.isNaN(d2)) {
    //      throw new IllegalArgumentException("NaN found");
    //    }
    final double norm = NORMAL.getPDF(d2);

    final double res = norm < SMALL ? 0. : -discount * norm / spot / sigmaRootT;
    return Double.isNaN(res) ? Double.NEGATIVE_INFINITY : res;
}

From source file:handlers.actionshift.OnActionShift.java

/**
 * Method addResist./* www  .j  av a2s  .  c  o  m*/
 * @param dialog StringBuilder
 * @param name String
 * @param val double
 * @return boolean
 */
private boolean addResist(StringBuilder dialog, String name, double val) {
    if (val == 0) {
        return false;
    }

    dialog.append("<tr><td>").append(name).append("</td><td>");

    if (val == Double.POSITIVE_INFINITY) {
        dialog.append("MAX");
    } else if (val == Double.NEGATIVE_INFINITY) {
        dialog.append("MIN");
    } else {
        dialog.append(String.valueOf((int) val));
        dialog.append("</td></tr>");
        return true;
    }

    dialog.append("</td></tr>");
    return true;
}

From source file:com.androzic.Androzic.java

public Route trackToRoute2(Track track, float sensitivity) throws IllegalArgumentException {
    Route route = new Route();
    List<Track.TrackPoint> points = track.getAllPoints();
    Track.TrackPoint tp = points.get(0);
    route.addWaypoint("RWPT", tp.latitude, tp.longitude).proximity = 0;

    if (points.size() < 2)
        throw new IllegalArgumentException("Track too short");

    tp = points.get(points.size() - 1);// w w  w . j a v  a 2s .  c om
    route.addWaypoint("RWPT", tp.latitude, tp.longitude).proximity = points.size() - 1;

    int prx = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this).getString(
            getString(R.string.pref_navigation_proximity), getString(R.string.def_navigation_proximity)));
    double proximity = prx * sensitivity;
    boolean peaks = true;
    int s = 1;

    while (peaks) {
        peaks = false;
        //Log.d("ANDROZIC", s+","+peaks);
        for (int i = s; i > 0; i--) {
            Waypoint sp = route.getWaypoint(i - 1);
            Waypoint fp = route.getWaypoint(i);
            if (fp.silent)
                continue;
            double c = Geo.bearing(sp.latitude, sp.longitude, fp.latitude, fp.longitude);
            double xtkMin = 0, xtkMax = 0;
            int tpMin = 0, tpMax = 0;
            //Log.d("ANDROZIC", "vector: "+i+","+c);
            //Log.d("ANDROZIC", sp.name+"-"+fp.name+","+sp.proximity+"-"+fp.proximity);
            for (int j = sp.proximity; j < fp.proximity; j++) {
                tp = points.get(j);
                double b = Geo.bearing(tp.latitude, tp.longitude, fp.latitude, fp.longitude);
                double d = Geo.distance(tp.latitude, tp.longitude, fp.latitude, fp.longitude);
                double xtk = Geo.xtk(d, c, b);
                if (xtk != Double.NEGATIVE_INFINITY && xtk < xtkMin) {
                    xtkMin = xtk;
                    tpMin = j;
                }
                if (xtk != Double.NEGATIVE_INFINITY && xtk > xtkMax) {
                    xtkMax = xtk;
                    tpMax = j;
                }
            }
            // mark this vector to skip it on next pass
            if (xtkMin >= -proximity && xtkMax <= proximity) {
                fp.silent = true;
                continue;
            }
            if (xtkMin < -proximity) {
                tp = points.get(tpMin);
                route.insertWaypoint(i - 1, "RWPT", tp.latitude, tp.longitude).proximity = tpMin;
                //Log.w("ANDROZIC", "min peak: "+s+","+tpMin+","+xtkMin);
                s++;
                peaks = true;
            }
            if (xtkMax > proximity) {
                tp = points.get(tpMax);
                int after = xtkMin < -proximity && tpMin < tpMax ? i : i - 1;
                route.insertWaypoint(after, "RWPT", tp.latitude, tp.longitude).proximity = tpMax;
                //Log.w("ANDROZIC", "max peak: "+s+","+tpMax+","+xtkMax);
                s++;
                peaks = true;
            }
        }
        //Log.d("ANDROZIC", s+","+peaks);
        if (s > 500)
            peaks = false;
    }
    s = 0;
    for (Waypoint wpt : route.getWaypoints()) {
        wpt.name += s;
        wpt.proximity = prx;
        wpt.silent = false;
        s++;
    }
    route.name = "RT_" + track.name;
    route.show = true;
    return route;
}

From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java

/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset./*  w w  w .ja v a 2s  . co m*/
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(XYDataset dataset, boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getSeriesCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getSeriesKey(s));
            }
        }
        // the bounds should be calculated using just the items within
        // the current range of the x-axis...if there is one
        Range xRange = null;
        XYPlot p = getPlot();
        if (p != null) {
            ValueAxis xAxis = null;
            int index = p.getIndexOf(this);
            if (index >= 0) {
                xAxis = plot.getDomainAxisForDataset(index);
            }
            if (xAxis != null) {
                xRange = xAxis.getRange();
            }
        }
        if (xRange == null) {
            xRange = new Range(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
        }
        return DatasetUtilities.findRangeBounds(dataset, visibleSeriesKeys, xRange, includeInterval);
    } else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotFunction(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape,
        double minX, double maxX) throws ConvertException {
    double[][] points = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX,
            maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    double[][] functionErrors = null;
    String legend = shortLegend.get(id);
    Color color = colors.get(id);
    Shape shape = shapes.get(id);

    if (showConfidenceInterval) {
        functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX,
                maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    }/*from  w w  w .ja va 2s  .c  om*/

    if (addInfoInLegend) {
        legend = longLegend.get(id);
    }

    if (color == null) {
        color = defaultColor;
    }

    if (shape == null) {
        shape = defaultShape;
    }

    if (points != null) {
        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        if (functionErrors != null) {
            YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection();
            DeviationRenderer functionRenderer = new DeviationRenderer(true, false);
            YIntervalSeries series = new YIntervalSeries(legend);

            for (int j = 0; j < points[0].length; j++) {
                double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j];

                series.add(points[0][j], points[1][j], points[1][j] - error, points[1][j] + error);
            }

            functionDataset.addSeries(series);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesFillPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        } else {
            DefaultXYDataset functionDataset = new DefaultXYDataset();
            XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false);

            functionDataset.addSeries(legend, points);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        }
    }
}