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:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java

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) {

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    Paint seriesPaint = getItemPaint(series, item);

    double value0;
    double value1;
    if (getUseYInterval()) {
        value0 = intervalDataset.getStartYValue(series, item);
        value1 = intervalDataset.getEndYValue(series, item);
    } else {//  ww w  . java 2  s.  c om
        value0 = getBase();
        value1 = intervalDataset.getYValue(series, item);
    }
    if (Double.isNaN(value0) || Double.isNaN(value1)) {
        return;
    }

    double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
    double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    double x1 = intervalDataset.getStartXValue(series, item);
    double translatedX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);

    double x2 = intervalDataset.getEndXValue(series, item);
    double translatedX2 = domainAxis.valueToJava2D(x2, dataArea, xAxisLocation);

    double translatedWidth = Math.max(1, Math.abs(translatedX2 - translatedX1));
    double translatedHeight = Math.abs(translatedValue0 - translatedValue1);

    /*
     * With BlueDragon, this value is always false so it's safe to comment this
     * code out. if (this.centerBarAtStartValue) { translatedX1 -=
     * translatedWidth / 2; }
     */

    PlotOrientation orientation = plot.getOrientation();
    if (getMargin() > 0.0) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            // BEGIN fix for horizontal bar charts that have a margin
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 - cut / 2;
            // END fix for horizontal bar charts that have a margin
        } else if (orientation == PlotOrientation.VERTICAL) {
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 + cut / 2;
        }
    }

    int numSeries = dataset.getSeriesCount();
    double seriesBarWidth = translatedWidth / numSeries;

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(Math.min(translatedValue0, translatedValue1),
                translatedX1 - seriesBarWidth * (numSeries - series), translatedHeight, seriesBarWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {

        bar = new Rectangle2D.Double(translatedX1 + seriesBarWidth * series,
                Math.min(translatedValue0, translatedValue1), seriesBarWidth, translatedHeight);

    }
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && Math.abs(translatedX2 - translatedX1) > 3) {
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(bar);
    }

    // TODO: we need something better for the item labels
    if (isItemLabelVisible(series, item)) {
        // Change parameters passed to this method to call our local version
        drawItemLabel(g2, orientation, dataset, series, item, bar, value1 < 0.0);
    }

    // add an entity for the item...
    if (info != null) {
        EntityCollection entities = info.getOwner().getEntityCollection();
        if (entities != null) {
            String tip = null;
            XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            XYItemEntity entity = new XYItemEntity(bar, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }

}

From source file:geogebra.kernel.cas.AlgoIntegralDefinite.java

protected final void compute() {
    if (!f.isDefined() || !ageo.isDefined() || !bgeo.isDefined()) {
        n.setUndefined();// w w  w.j a v  a 2 s .com
        return;
    }

    // check for equal bounds
    double lowerLimit = a.getDouble();
    double upperLimit = b.getDouble();
    if (Kernel.isEqual(lowerLimit, upperLimit)) {
        n.setValue(0);
        return;
    }

    // check if f(a) and f(b) are defined
    double fa = f.evaluate(lowerLimit);
    double fb = f.evaluate(upperLimit);
    if (Double.isNaN(fa) || Double.isInfinite(fa) || Double.isNaN(fb) || Double.isInfinite(fb)) {
        n.setUndefined();
        return;
    }

    // return if it should not be evaluated (i.e. is shade-only)
    if (evaluateOnly()) {
        n.setValue(Double.NaN);
        return;
    }

    /* 
     * Try to use symbolic integral
     *
     * We only do this for functions that do NOT include divisions by their variable.
     * Otherwise there might be problems like:
     * Integral[ 1/x, -2, -1 ] would be undefined (log(-1) - log(-2))
     * Integral[ 1/x^2, -1, 1 ] would be defined (-2)
     */
    if (symbIntegral != null && symbIntegral.isDefined() && !f.includesDivisionByVar()) {
        double val = symbIntegral.evaluate(upperLimit) - symbIntegral.evaluate(lowerLimit);
        n.setValue(val);
        if (n.isDefined())
            return;
    }

    // numerical integration
    // max_error = ACCURACY; // current maximum error
    //maxstep = 0;           

    double integral = numericIntegration(f, lowerLimit, upperLimit);
    n.setValue(integral);

    /*
    Application.debug("***\nsteps: " + maxstep);                   
    Application.debug("max_error: " + max_error);
    */
}

From source file:com.ning.metrics.collector.util.Stats.java

/**
 * 99.999th percentile//from  w ww.j  a v a  2s . co  m
 *
 * @return 99.999th percentile
 */
@Managed
@SuppressWarnings("unused")
public double getMillisTP99999() {
    double percentile = millisStats.getPercentile(99.999);
    return Double.isNaN(percentile) ? 0.0 : percentile;
}

From source file:es.uvigo.ei.sing.laimages.core.operations.BilinearInterpolatingFunction.java

private static int next(double value, double[] values) {
    if (value < values[0] || value > values[values.length - 1])
        throw new OutOfRangeException(value, values[0], values[values.length - 1]);

    for (int i = 0; i < values.length; i++) {
        if (!Double.isNaN(values[i]) && values[i] > value) {
            return i;
        }//from   w  ww . j  a  v a2s  .com
    }

    return values.length - 1;
}

From source file:lirmm.inria.fr.math.OpenLongToDoubleHashMapTest.java

@Test
public void testRemove() {
    OpenLongToDoubleHashMap map = createFromJavaMap();
    int mapSize = javaMap.size();
    Assert.assertEquals(mapSize, map.size());
    for (Map.Entry<Long, Double> mapEntry : javaMap.entrySet()) {
        map.remove(mapEntry.getKey());/*from w w  w  .  jav a  2  s  . com*/
        Assert.assertEquals(--mapSize, map.size());
        Assert.assertTrue(Double.isNaN(map.get(mapEntry.getKey())));
    }

    /* Ensure that put and get still work correctly after removals */
    assertPutAndGet(map);
}

From source file:edu.duke.cs.osprey.tupexp.IterativeCGTupleFitter.java

RealVector calcRHS() {//Calculate right-hand side vector of normal equations
    double atb[] = new double[numTup];
    //apply A^T to true vals
    for (int s = 0; s < numSamp; s++) {
        double curTarget = getCurTarget(s);
        if (!Double.isNaN(curTarget)) {//restraint active for sample
            ArrayList<Integer> sampTup = tupIndMat.calcSampleTuples(samples.get(s));
            for (int t : sampTup)
                atb[t] += curTarget;//w ww .j a va2s  .c o m
        }
    }

    //damping.  Slightly penalizes changes from curCoeffs
    if (curCoeffs != null) {
        for (int t = 0; t < numTup; t++)
            atb[t] += damperLambda * curCoeffs.getEntry(t);
    }

    Atb = new ArrayRealVector(atb);
    return Atb;
}

From source file:com.bdaum.zoom.gps.internal.operations.GeotagOperation.java

public GeotagOperation(Trackpoint[] trackpoints, String[] assetIds, GpsConfiguration gpsConfiguration) {
    super(Messages.getString("GeotagOperation.GeoTagging")); //$NON-NLS-1$
    this.assetIds = assetIds;
    this.gpsConfiguration = gpsConfiguration;
    this.trackpoints = trackpoints;
    removeTag = trackpoints.length == 1/* w  w  w  .  ja v  a 2s  . c om*/
            && (Double.isNaN(trackpoints[0].getLatitude()) || Double.isNaN(trackpoints[0].getLongitude()));
    if (gpsConfiguration.excludeNoGoAreas) {
        noGoAreas = new ArrayList<>();
        GpsUtilities.getGeoAreas(GpsActivator.getDefault().getPreferenceStore(), noGoAreas);
    }
}

From source file:gedi.util.math.stat.testing.DirichletLikelihoodRatioTest.java

/**
 * Tests the 0 Null hypothesis that all sample vectors come from a multinomial with equal probability vector
 * // w w w  . j a  v  a2  s.  c  om
 * Removes all components where one of the vectors has NaN!
 * 
 * TODO: Test with more than two samples (are the df right?)
 * 
 * @param pseudo
 * @param samples is changed!
 * 
 * @return
 */
public static double testMultinomials(MutableDouble statistic, double pseudo, double[]... samples) {

    double[][] psamples = new double[samples.length][];
    assert samples.length > 1;

    // remove NaNs
    BitVector nans = new BitVector(samples[0].length);
    for (int i = 0; i < samples.length; i++) {
        assert samples[i].length == samples[0].length;
        for (int j = 0; j < samples[i].length; j++)
            if (Double.isNaN(samples[i][j]))
                nans.putQuick(j, true);
    }
    nans.not();
    for (int i = 0; i < samples.length; i++) {
        psamples[i] = ArrayUtils.restrict(samples[i], nans);
        assert ArrayUtils.min(psamples[i]) >= 0;
    }

    // remove all zero components
    nans.clear();
    for (int i = 0; i < samples.length; i++)
        for (int j = 0; j < samples[i].length; j++)
            if (samples[i][j] > 0)
                nans.putQuick(j, true);
    for (int i = 0; i < samples.length; i++) {
        psamples[i] = ArrayUtils.restrict(psamples[i], nans);
    }

    int dim = psamples[0].length;
    int obj = psamples.length;
    if (dim < 2)
        return Double.NaN;

    // add pseudocounts proportional to total sum of counts
    double[] n1 = new double[dim];
    for (int i = 0; i < obj; i++)
        ArrayUtils.add(n1, psamples[i]);
    ArrayUtils.normalize(n1);

    for (int i = 0; i < obj; i++)
        for (int j = 0; j < dim; j++)
            psamples[i][j] += pseudo * n1[j];

    double[] concat = ArrayUtils.concat(psamples);
    double[] norm = concat.clone();
    ArrayUtils.normalize(norm);

    // normalize for L1
    double[] c1 = new double[dim];
    for (int i = 0; i < norm.length; i += dim) {
        for (int j = 0; j < dim; j++)
            c1[j] += norm[i + j];
    }
    ArrayUtils.normalize(c1);

    // normalize for L2
    double[] cnorm = new double[concat.length];
    for (int i = 0; i < norm.length; i += dim) {
        double s = ArrayUtils.sum(norm, i, i + dim);
        for (int j = 0; j < dim; j++)
            cnorm[i + j] = c1[j] * s;
    }

    // do the test
    double L1 = logProbability(concat, norm);
    double L2 = logProbability(concat, cnorm);

    return ChiSquare.cumulative(2 * (L1 - L2), (dim - 1) * (obj - 1), false, false);
}

From source file:com.netflix.spectator.controllers.MetricsController.java

/**
 * Internal API for encoding a registry that can be encoded as JSON.
 * This is a helper function for the REST endpoint and to test against.
 *//*ww w.j  a va 2  s  .com*/
Map<String, MetricValues> encodeRegistry(Registry sourceRegistry, Predicate<Measurement> filter) {
    Map<String, MetricValues> metricMap = new HashMap<String, MetricValues>();

    /**
     * Flatten the meter measurements into a map of measurements keyed by
     * the name and mapped to the different tag variants.
     */
    for (Meter meter : sourceRegistry) {
        String kind = knownMeterKinds.computeIfAbsent(meter.id(), k -> meterToKind(sourceRegistry, meter));

        for (Measurement measurement : meter.measure()) {
            if (!filter.test(measurement)) {
                continue;
            }
            if (Double.isNaN(measurement.value())) {
                continue;
            }

            String measurementName = measurement.id().name();
            MetricValues have = metricMap.get(measurementName);
            if (have == null) {
                metricMap.put(measurementName, new MetricValues(kind, measurement));
            } else {
                have.addMeasurement(measurement);
            }
        }
    }
    return metricMap;
}

From source file:com.mapr.synth.drive.DriveTest.java

@Test
public void testCrazyPlan() {
    Random rand = new Random(3);
    GeoPoint start = new GeoPoint(new Vector3D(0.84338521, 0.40330691, 0.35502805));
    GeoPoint end = new GeoPoint(new Vector3D(0.84293820, 0.40512281, 0.35402076));
    for (int i = 0; i < 100000; i++) {
        List<Car.Segment> plan = Car.plan(start, end, rand);
        GeoPoint old = start;//w w w . ja  v  a  2s  .  co  m
        for (Car.Segment segment : plan.subList(1, plan.size())) {
            double distance = old.distance(segment.getEnd());
            if (distance > 100 || Double.isNaN(distance)) {
                Assert.fail("Got bad distance");
            }
            old = segment.getEnd();
        }
    }
}