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:edu.cmu.tetrad.sem.GeneralizedSemIm.java

public DataSet simulateDataNSteps(int sampleSize, boolean latentDataSaved) {
    final Map<String, Double> variableValues = new HashMap<String, Double>();

    List<Node> continuousVariables = new LinkedList<Node>();
    final List<Node> variableNodes = pm.getVariableNodes();

    // Work with a copy of the variables, because their type can be set externally.
    for (Node node : variableNodes) {
        ContinuousVariable var = new ContinuousVariable(node.getName());
        var.setNodeType(node.getNodeType());

        if (var.getNodeType() != NodeType.ERROR) {
            continuousVariables.add(var);
        }//  w  w w .  j ava  2  s.  co m
    }

    DataSet fullDataSet = new ColtDataSet(sampleSize, continuousVariables);

    final Context context = new Context() {
        public Double getValue(String term) {
            Double value = parameterValues.get(term);

            if (value != null) {
                return value;
            }

            value = variableValues.get(term);

            if (value != null) {
                return value;
            }

            throw new IllegalArgumentException("No value recorded for '" + term + "'");
        }
    };

    // Do the simulation.
    ROW: for (int row = 0; row < sampleSize; row++) {

        // Take random draws from error distributions.
        for (Node variable : variableNodes) {
            Node error = pm.getErrorNode(variable);

            Expression expression = pm.getNodeExpression(error);
            double value = expression.evaluate(context);

            if (Double.isNaN(value)) {
                throw new IllegalArgumentException("Undefined value for expression: " + expression);
            }

            variableValues.put(error.getName(), value);
        }

        // Set the variable nodes to zero.
        for (Node variable : variableNodes) {
            variableValues.put(variable.getName(), 0.0);// RandomUtil.getInstance().nextUniform(-5, 5));
        }

        // Repeatedly update variable values until one of them hits infinity or negative infinity or
        // convergence within delta.

        for (int m = 0; m < 1; m++) {
            double[] values = new double[variableNodes.size()];

            for (int i = 0; i < values.length; i++) {
                Node node = variableNodes.get(i);
                Expression expression = pm.getNodeExpression(node);
                double value = expression.evaluate(context);

                if (Double.isNaN(value)) {
                    throw new IllegalArgumentException("Undefined value for expression: " + expression);
                }

                values[i] = value;
            }

            for (double value : values) {
                if (value == Double.POSITIVE_INFINITY || value == Double.NEGATIVE_INFINITY) {
                    row--;
                    continue ROW;
                }
            }

            for (int i = 0; i < variableNodes.size(); i++) {
                variableValues.put(variableNodes.get(i).getName(), values[i]);
            }

        }

        for (int i = 0; i < variableNodes.size(); i++) {
            double value = variableValues.get(variableNodes.get(i).getName());
            fullDataSet.setDouble(row, i, value);
        }
    }

    if (latentDataSaved) {
        return fullDataSet;
    } else {
        return DataUtils.restrictToMeasured(fullDataSet);
    }

}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Iterates over the data items of the xy dataset to find
 * the range bounds.// w  w  w.j a va2  s .com
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines, for an
 *          {@link IntervalXYDataset}, whether the y-interval or just the
 *          y-value is used to determine the overall range.
 *
 * @return The range (possibly <code>null</code>).
 *
 * @since 1.0.10
 */
public static Range iterateRangeBounds(XYDataset dataset, boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();

    // handle three cases by dataset type
    if (includeInterval && dataset instanceof IntervalXYDataset) {
        // handle special case of IntervalXYDataset
        IntervalXYDataset ixyd = (IntervalXYDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value = ixyd.getYValue(series, item);
                double lvalue = ixyd.getStartYValue(series, item);
                double uvalue = ixyd.getEndYValue(series, item);
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                    maximum = Math.max(maximum, value);
                }
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                    maximum = Math.max(maximum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    minimum = Math.min(minimum, uvalue);
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else if (includeInterval && dataset instanceof OHLCDataset) {
        // handle special case of OHLCDataset
        OHLCDataset ohlc = (OHLCDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double lvalue = ohlc.getLowValue(series, item);
                double uvalue = ohlc.getHighValue(series, item);
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else {
        // standard case - plain XYDataset
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value = dataset.getYValue(series, item);
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                    maximum = Math.max(maximum, value);
                }
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

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

/**
* The vanna of an option, i.e. second order derivative of the option value, once to the underlying spot and once to volatility.<p>
* $\frac{\partial^2 FV}{\partial f \partial \sigma}$
* @param spot The spot value of the underlying
* @param strike The Strike// w w w .j  av a2 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 spot vanna
*/
@ExternalFunction
public static double vanna(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");

    final double rootT = Math.sqrt(timeToExpiry);
    double sigmaRootT = lognormalVol * rootT;
    if (Double.isNaN(sigmaRootT)) {
        sigmaRootT = 1.; //ref value is returned
    }

    double d1 = 0.;
    double d2 = 0.;
    if (Math.abs(spot - strike) < SMALL || (spot > LARGE && strike > LARGE) || sigmaRootT > LARGE) {
        final double coefD1 = Double.isNaN(Math.abs(costOfCarry) / lognormalVol)
                ? Math.signum(costOfCarry) + 0.5 * lognormalVol
                : (costOfCarry / lognormalVol + 0.5 * lognormalVol);
        final double tmpD1 = Math.abs(coefD1) < SMALL ? 0. : coefD1 * rootT;
        d1 = Double.isNaN(tmpD1) ? Math.signum(coefD1) : tmpD1;
        final double coefD2 = Double.isNaN(Math.abs(costOfCarry) / lognormalVol)
                ? Math.signum(costOfCarry) - 0.5 * lognormalVol
                : (costOfCarry / lognormalVol - 0.5 * lognormalVol);
        final double tmpD2 = Math.abs(coefD2) < SMALL ? 0. : coefD2 * rootT;
        d2 = Double.isNaN(tmpD2) ? Math.signum(coefD2) : tmpD2;
    } 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;
            d1 = Double.isNaN(tmp) ? 0. : tmp;
            d2 = d1;
        } 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;
            final double d1Tmp = Math.log(spot / strike) / sigmaRootT + scnd + 0.5 * sigmaRootT;
            final double d2Tmp = Math.log(spot / strike) / sigmaRootT + scnd - 0.5 * sigmaRootT;
            d1 = Double.isNaN(d1Tmp) ? 0. : d1Tmp;
            d2 = Double.isNaN(d2Tmp) ? 0. : d2Tmp;
        }
    }
    //    if (Double.isNaN(d1) || Double.isNaN(d2)) {
    //      throw new IllegalArgumentException("NaN found");
    //    }

    double coef = 0.;
    if ((interestRate > LARGE && costOfCarry > LARGE) || (-interestRate > LARGE && -costOfCarry > LARGE)
            || Math.abs(costOfCarry - interestRate) < SMALL) {
        coef = 1.; //ref value is returned
    } else {
        final double rate = costOfCarry - interestRate;
        if (rate > LARGE) {
            return costOfCarry > LARGE ? 0. : (d2 >= 0. ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
        }
        if (-rate > LARGE) {
            return 0.;
        }
        coef = Math.exp(rate * timeToExpiry);
    }

    final double norm = NORMAL.getPDF(d1);
    double tmp = d2 * coef / lognormalVol;
    if (Double.isNaN(tmp)) {
        tmp = coef;
    }
    return norm < SMALL ? 0. : -norm * tmp;
}

From source file:io.prestosql.tests.AbstractTestQueries.java

@Test
public void testSpecialFloatingPointValues() {
    MaterializedResult actual = computeActual("SELECT nan(), infinity(), -infinity()");
    MaterializedRow row = getOnlyElement(actual.getMaterializedRows());
    assertEquals(row.getField(0), Double.NaN);
    assertEquals(row.getField(1), Double.POSITIVE_INFINITY);
    assertEquals(row.getField(2), Double.NEGATIVE_INFINITY);
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Range filters changed//from   w  ww.j  a v  a 2 s  . c  o m
 */
public void rangeFiltersChanged() {
    if ((rangeFilters.size() == 0) || (dataChoiceWrappers.size() == 0)) {
        return;
    }
    DataChoice dataChoice = ((DataChoiceWrapper) dataChoiceWrappers.get(0)).getDataChoice();
    double min = Double.NEGATIVE_INFINITY;
    double max = Double.POSITIVE_INFINITY;
    int greaterThanCnt = 0;
    int lessThanCnt = 0;

    for (int i = 0; i < rangeFilters.size(); i++) {
        RangeFilter rangeFilter = (RangeFilter) rangeFilters.get(i);
        if (rangeFilter.getType() == RangeFilter.TYPE_LESSTHAN) {
            if (lessThanCnt == 0) {
                max = rangeFilter.getRangeValue();
            } else {
                max = Math.max(max, rangeFilter.getRangeValue());
            }
            lessThanCnt++;
        } else {
            if (greaterThanCnt == 0) {
                min = rangeFilter.getRangeValue();
            } else {
                min = Math.min(min, rangeFilter.getRangeValue());
            }
            greaterThanCnt++;
        }
    }
    getDisplayControl().doShare(DisplayControlImpl.SHARE_SELECTRANGE,
            new Object[] { dataChoice, new ucar.unidata.util.Range(min, max) });
}

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

/**
 * {@link jp.furplag.util.commons.NumberUtils#multiply(java.lang.Object, java.lang.Number, java.lang.Class)}.
 */// w w  w.  java2s. c  o m
@SuppressWarnings("unchecked")
@Test
public void testMultiplyObjectNumberClassOfT() {
    assertEquals("null", null, multiply(null, null, null));
    assertEquals("null", null, multiply(1, 23, null));
    assertEquals("null", null, multiply(1, 2, null));
    try {
        for (Class<?> type : PRIMITIVES) {
            Object expected = ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class)
                    .invoke(null, "0");
            assertEquals("fallback: " + type.getSimpleName(), expected,
                    multiply(null, null, (Class<? extends Number>) type));
        }
        for (Class<?> type : NUMBERS) {
            Object expected = valueOf(new BigDecimal("12").multiply(new BigDecimal("3.456")),
                    (Class<? extends Number>) type);
            assertEquals("12 * 3.456:" + type.getSimpleName(), expected,
                    multiply(12, 3.456, (Class<? extends Number>) type));
            if (ClassUtils.isPrimitiveOrWrapper(type)) {
                expected = valueOf(valueOf("-Infinity"), (Class<? extends Number>) type);
            } else {
                expected = INFINITY_DOUBLE.pow(2).negate();
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("Infinity * -Infinity: " + type.getSimpleName(), expected,
                    multiply("Infinity", Double.NEGATIVE_INFINITY, (Class<? extends Number>) type));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
    }
}

From source file:com.androzic.MapActivity.java

protected void updateNavigationInfo() {
    if (navigationService == null || !navigationService.isNavigating())
        return;//from ww  w  .ja v a 2  s. co m

    double distance = navigationService.navDistance;
    double bearing = navigationService.navBearing;
    long turn = navigationService.navTurn;
    double vmg = navigationService.navVMG * speedFactor;
    int ete = navigationService.navETE;

    String[] dist = StringFormatter.distanceC(distance, precisionFormat);
    String extra = String.format(precisionFormat, vmg) + " " + speedAbbr + " | " + StringFormatter.timeH(ete);

    String trnsym = "";
    if (turn > 0) {
        trnsym = "R";
    } else if (turn < 0) {
        trnsym = "L";
        turn = -turn;
    }

    bearing = application.fixDeclination(bearing);
    distanceValue.setText(dist[0]);
    distanceUnit.setText(dist[1]);
    bearingValue.setText(String.valueOf(Math.round(bearing)));
    turnValue.setText(String.valueOf(Math.round(turn)) + trnsym);
    waypointExtra.setText(extra);

    if (navigationService.isNavigatingViaRoute()) {
        boolean hasNext = navigationService.hasNextRouteWaypoint();
        if (distance < navigationService.navProximity * 3 && !animationSet) {
            AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new AlphaAnimation(1.0f, 0.3f));
            animation.addAnimation(new AlphaAnimation(0.3f, 1.0f));
            animation.setDuration(500);
            animation.setRepeatCount(10);
            findViewById(R.id.waypointinfo).startAnimation(animation);
            if (!hasNext) {
                findViewById(R.id.routeinfo).startAnimation(animation);
            }
            animationSet = true;
        } else if (animationSet) {
            findViewById(R.id.waypointinfo).setAnimation(null);
            if (!hasNext) {
                findViewById(R.id.routeinfo).setAnimation(null);
            }
            animationSet = false;
        }

        if (navigationService.navXTK == Double.NEGATIVE_INFINITY) {
            xtkValue.setText("--");
            xtkUnit.setText("--");
        } else {
            String xtksym = navigationService.navXTK == 0 ? "" : navigationService.navXTK > 0 ? "R" : "L";
            String[] xtks = StringFormatter.distanceC(Math.abs(navigationService.navXTK));
            xtkValue.setText(xtks[0] + xtksym);
            xtkUnit.setText(xtks[1]);
        }

        double navDistance = navigationService.navRouteDistanceLeft();
        int eta = navigationService.navRouteETE(navDistance);
        if (eta < Integer.MAX_VALUE)
            eta += navigationService.navETE;
        extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + StringFormatter.timeH(eta);
        routeExtra.setText(extra);
    }
}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java

/**
 * Export a solid./* ww  w.  j  a  v a  2 s .  c  o m*/
 *
 * @param fileName the file name
 * @param variables the variables
 * @param knit the knit
 * @param split the split
 * @param fitness the fitness
 * @return true, if successful
 */
public boolean exportSolid(String fileName, Set<String> variables, Set<String> knit, Set<String> split,
        String fitness) {

    // Attempt to create a new formulation class.
    try {

        // Declare the graph storage.
        Graph<String, String> graph = new DirectedSparseMultigraph<String, String>();

        // Build the graph.
        int edgeCount = exportSolidBuildGraph(graph);

        // Draw the graph.
        CircleLayout<String, String> layout = exportRenderGraph(graph);

        // Find the bounds storage.
        double minimum = Double.POSITIVE_INFINITY;
        double maximum = Double.NEGATIVE_INFINITY;

        // Find the bounds of the space.
        for (int source = 0; source < this.nodeCount(); source++) {
            double x = layout.getX("" + source);
            double y = layout.getY("" + source);
            minimum = Math.min(minimum, x);
            minimum = Math.min(minimum, y);
            maximum = Math.max(maximum, x);
            maximum = Math.max(maximum, y);
        }

        // Attempt to write out the SCAD file.
        this.exportSolidWriteSCAD(fileName, graph, edgeCount, layout, minimum, maximum);

        // Catch errors.
    } catch (Exception e) {

        // Note errors.
        return false;

    }

    // Return the default results.
    return true;

}

From source file:de.unijena.bioinf.FragmentationTreeConstruction.computation.FragmentationPatternAnalysis.java

/**
 * Computes a fragmentation tree/*from w w w . j  a  v  a 2s  .  c o m*/
 *
 * @param graph fragmentation graph from which the tree should be built
 * @return an optimal fragmentation tree
 */
public FTree computeTree(FGraph graph) {
    return computeTree(graph, Double.NEGATIVE_INFINITY);
}

From source file:net.panthema.BispanningGame.GamePanel.java

void centerAndScaleGraph() {

    // clear layout
    MultiLayerTransformer mlTransformer = mVV.getRenderContext().getMultiLayerTransformer();
    mlTransformer.setToIdentity();//from   w w w.  j av  a2s . co m

    if (mGraph.getVertexCount() == 0)
        return;

    // calculate bounding box of layout
    double xMin = Double.POSITIVE_INFINITY;
    double yMin = Double.POSITIVE_INFINITY;
    double xMax = Double.NEGATIVE_INFINITY;
    double yMax = Double.NEGATIVE_INFINITY;

    for (Integer v : mGraph.getVertices()) {
        Point2D p = mLayout.transform(v);
        if (p.getX() < xMin)
            xMin = p.getX();
        if (p.getX() > xMax)
            xMax = p.getX();
        if (p.getY() < yMin)
            yMin = p.getY();
        if (p.getY() > yMax)
            yMax = p.getY();
    }

    System.err.println("xMin: " + xMin + " xMax: " + xMax + " yMin: " + yMin + " yMax: " + yMax);

    // shift and scale layout
    Dimension vv_size = mVV.getSize();
    System.err.println("vv_size: " + vv_size);

    double xSize = xMax - xMin;
    double ySize = yMax - yMin;

    double xRatio = vv_size.getWidth() / xSize;
    double yRatio = vv_size.getHeight() / ySize;
    double ratio = 0.75 * Math.min(xRatio, yRatio);

    System.err.println("ratio: " + ratio);

    mlTransformer.getTransformer(Layer.LAYOUT).scale(ratio, ratio, new Point2D.Double(0, 0));

    double xShift = -xMin + (vv_size.getWidth() / ratio - xSize) / 2.0;
    double yShift = -yMin + (vv_size.getHeight() / ratio - ySize) / 2.0;
    mlTransformer.getTransformer(Layer.LAYOUT).translate(xShift, yShift);
}