Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

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

Prototype

public static boolean isInfinite(double v) 

Source Link

Document

Returns true if the specified number is infinitely large in magnitude, false otherwise.

Usage

From source file:classes.MyVisitor.java

public boolean isInt(Double variable) {
    if ((variable == Math.floor(variable)) && !Double.isInfinite(variable)) {
        return true;
    }//from   w w  w  .j av  a 2  s .co  m
    return false;
}

From source file:org.apache.metron.common.math.stats.OnlineStatisticsProvider.java

private void checkFlowError(double sumOfSquares, double sum, double... vals) {
    //overflow/* w w w  .ja va  2s . c  o  m*/
    for (double val : vals) {
        if (Double.isInfinite(val)) {
            throw new IllegalStateException("Double overflow!");
        }
    }
    //underflow.  It is sufficient to check sumOfSquares because sumOfSquares is going to converge to 0 faster than sum
    //in the situation where we're looking at an underflow.
    if (sumOfSquares == 0.0 && sum > 0) {
        throw new IllegalStateException("Double overflow!");
    }
}

From source file:org.renjin.primitives.MathGroup.java

@Deferrable
@Builtin/*w  ww . j  a  v a  2  s.  com*/
@DataParallel(value = PreserveAttributeStyle.ALL, passNA = true)
public static double asinh(double val) {
    if (Double.isInfinite(val)) {
        return val;
    }
    return Math.log(val + Math.sqrt(val * val + 1));
}

From source file:mase.mason.world.DistanceSensorArcs.java

/**
 * Very efficient implementation using an ordered TreeMap Should ensure
 * scalability when large numbers of objects are present, as there is no
 * need to check angles with objects that are farther than the closest
 * object in the given cone. Potential limitation (unlikely): if there are
 * two objects at exactly the same distance but at different angles, only
 * one of them will be considered, as the distance is used as key in the
 * TreeMap/*from w w  w  .  ja va 2  s.c o  m*/
 */
@Override
public double[] readValues() {
    lastDistances = new double[valueCount()];
    Arrays.fill(lastDistances, Double.POSITIVE_INFINITY);
    Arrays.fill(closestObjects, null);
    if (range < 0.001) {
        return lastDistances;
    }
    double rangeNoiseAbs = Double.isInfinite(range) ? rangeNoise * fieldDiagonal : range * rangeNoise;

    WorldObject[] candidates = getCandidates();

    // TODO: replace treemap with collection-sort
    Pair<Double, WorldObject>[] distances = new Pair[candidates.length];
    int index = 0;
    for (WorldObject o : candidates) {
        if (!centerToCenter && o.isInside(ag.getLocation())) {
            Arrays.fill(lastDistances, 0);
            Arrays.fill(closestObjects, o);
            return lastDistances;
        }

        double dist = centerToCenter ? ag.getLocation().distance(o.getLocation())
                : Math.max(0, ag.distanceTo(o));
        if (rangeNoiseAbs > 0) {
            dist += rangeNoiseAbs
                    * (noiseType == UNIFORM ? state.random.nextDouble() * 2 - 1 : state.random.nextGaussian());
            dist = Math.max(dist, 0);
        }
        if (dist <= range) {
            distances[index++] = Pair.of(dist, o);
        }
    }
    if (index < distances.length) {
        distances = Arrays.copyOf(distances, index);
    }

    Arrays.sort(distances, new Comparator<Pair<Double, WorldObject>>() {
        @Override
        public int compare(Pair<Double, WorldObject> a, Pair<Double, WorldObject> b) {
            return Double.compare(a.getLeft(), b.getLeft());
        }
    });

    int filled = 0;
    for (Pair<Double, WorldObject> e : distances) {
        if (filled == arcStart.length) {
            break;
        }
        double angle = ag.angleTo(e.getRight().getLocation());
        if (orientationNoise > 0) {
            angle += orientationNoise
                    * (noiseType == UNIFORM ? state.random.nextDouble() * 2 - 1 : state.random.nextGaussian());
            angle = EmboddiedAgent.normalizeAngle(angle);
        }
        for (int a = 0; a < arcStart.length; a++) {
            if (Double.isInfinite(lastDistances[a]) && ((angle >= arcStart[a] && angle <= arcEnd[a])
                    || (arcStart[a] > arcEnd[a] && (angle >= arcStart[a] || angle <= arcEnd[a])))) {
                filled++;
                lastDistances[a] = e.getKey();
                closestObjects[a] = e.getValue();
            }
        }
    }
    return lastDistances;
}

From source file:org.esa.beam.framework.datamodel.Stx.java

public Stx(double minimum, double maximum, double mean, double medianRaster, boolean includesMedianRaster,
        double standardDeviation, boolean logHistogram, boolean intHistogram, Histogram histogram,
        int resolutionLevel) {
    Assert.argument(!Double.isNaN(minimum), "minimum must not be NaN");
    Assert.argument(!Double.isInfinite(minimum), "minimum must not be infinity");
    Assert.argument(!Double.isNaN(maximum), "maximum must not be NaN");
    Assert.argument(!Double.isInfinite(maximum), "minimum must not be infinity");
    Assert.argument(resolutionLevel >= 0, "resolutionLevel");

    // todo - this is still a lot of behaviour, move all computations to StxFactory (nf)
    this.sampleCount = StxFactory.computeSum(histogram.getBins(0));
    this.minimum = minimum;
    this.maximum = maximum;
    this.histogramScaling = getHistogramScaling(logHistogram);
    if (minimum == maximum) {
        this.mean = minimum;
        this.standardDeviation = 0.0;
        this.median = maximum;
    } else {//from w w w  . j  a  v a 2 s  . c o  m
        this.mean = Double.isNaN(mean) ? histogramScaling.scaleInverse(histogram.getMean()[0]) : mean;
        this.standardDeviation = Double.isNaN(standardDeviation)
                ? histogramScaling.scaleInverse(histogram.getStandardDeviation()[0])
                : standardDeviation;
        this.median = histogramScaling.scaleInverse(StxFactory.computeMedian(histogram, this.sampleCount));
    }
    this.logHistogram = logHistogram;
    this.intHistogram = intHistogram;
    this.histogram = histogram;
    this.resolutionLevel = resolutionLevel;
    this.medianRaster = medianRaster;
    this.includesMedianRaster = includesMedianRaster;

}

From source file:geogebra.common.kernel.algos.AlgoRootNewton.java

public final double calcRoot(Function fun, double start) {
    double root = Double.NaN;
    if (rootFinderBrent == null)
        rootFinderBrent = new BrentSolver(Kernel.STANDARD_PRECISION);

    // try Brent method with borders close to start value
    try {// w w w  .  ja  v a 2s  .com

        // arbitrary (used to depend on screen width)
        double step = 1;

        root = rootFinderBrent.solve(MAX_ITERATIONS, new RealRootAdapter(fun), start - step, start + step,
                start);
        if (checkRoot(fun, root)) {
            // System.out.println("1. Brent worked: " + root);
            return root;
        }
    } catch (Exception e) {
        root = Double.NaN;
    }

    // try Brent method on valid interval around start
    double[] borders = getDomain(fun, start);
    try {
        root = rootFinderBrent.solve(MAX_ITERATIONS, new RealRootAdapter(fun), borders[0], borders[1], start);
        if (checkRoot(fun, root)) {
            // System.out.println("2. Brent worked: " + root);
            return root;
        }
    } catch (Exception e) {
        root = Double.NaN;
    }

    // try Newton's method
    RealRootDerivFunction derivFun = fun.getRealRootDerivFunction();
    if (derivFun != null) {
        // check if fun(start) is defined
        double eval = fun.evaluate(start);
        if (Double.isNaN(eval) || Double.isInfinite(eval)) {
            // shift left border slightly right
            borders[0] = 0.9 * borders[0] + 0.1 * borders[1];
            start = (borders[0] + borders[1]) / 2;
        }

        if (rootFinderNewton == null) {
            rootFinderNewton = new NewtonSolver();
        }

        try {
            root = rootFinderNewton.solve(MAX_ITERATIONS, new RealRootDerivAdapter(derivFun), borders[0],
                    borders[1], start);
            if (checkRoot(fun, root)) {
                // System.out.println("Newton worked: " + root);
                return root;
            }
        } catch (Exception e) {
            root = Double.NaN;
        }
    }

    // neither Brent nor Newton worked
    return Double.NaN;
}

From source file:MutableDouble.java

/**
 * Checks whether the double value is infinite.
 * 
 * @return true if infinite
 */
public boolean isInfinite() {
    return Double.isInfinite(value);
}

From source file:com.opengamma.analytics.math.function.PiecewisePolynomialWithSensitivityFunction1D.java

/** 
 * @param pp {@link PiecewisePolynomialResultsWithSensitivity}
 * @param xKey //from   w  ww  . j  a  v  a  2  s.  com
 * @return Node sensitivity of derivative value at x=xKey
 */
public DoubleMatrix1D differentiateNodeSensitivity(final PiecewisePolynomialResultsWithSensitivity pp,
        final double xKey) {
    ArgumentChecker.notNull(pp, "null pp");
    ArgumentChecker.isFalse(Double.isNaN(xKey), "xKey containing NaN");
    ArgumentChecker.isFalse(Double.isInfinite(xKey), "xKey containing Infinity");

    if (pp.getDimensions() > 1) {
        throw new NotImplementedException();
    }
    final int nCoefs = pp.getOrder();
    ArgumentChecker.isFalse(nCoefs < 2, "Polynomial degree is too low");

    final double[] knots = pp.getKnots().getData();
    final int nKnots = knots.length;
    int interval = FunctionUtils.getLowerBoundIndex(knots, xKey);
    if (interval == nKnots - 1) {
        interval--; // there is 1 less interval that knots
    }

    final double s = xKey - knots[interval];
    final DoubleMatrix2D a = pp.getCoefficientSensitivity(interval);

    DoubleMatrix1D res = (DoubleMatrix1D) MA.scale(a.getRowVector(0), nCoefs - 1);
    for (int i = 1; i < nCoefs - 1; i++) {
        res = (DoubleMatrix1D) MA.scale(res, s);
        res = (DoubleMatrix1D) MA.add(res, MA.scale(a.getRowVector(i), nCoefs - 1 - i));
    }

    return res;
}

From source file:edu.cmu.tetrad.data.MultiGeneralAndersonDarlingTest.java

private void runTest() {
    int n = data.get(0).size();
    double h = 0.0;

    int numSummed = 0;

    for (int g = 0; g < data.size(); g++) {
        List<Double> _data = data.get(g);

        for (int i = 1; i <= n; i++) {
            double x1 = _data.get(i - 1);
            double a1 = Math.log(distributions.get(g).cumulativeProbability(x1));

            double x2 = _data.get(n + 1 - i - 1);
            double a2 = Math.log(1.0 - distributions.get(g).cumulativeProbability(x2));

            double k = (2 * i - 1) * (a1 + a2);

            if (!(Double.isNaN(a1) || Double.isNaN(a2) || Double.isInfinite(a1) || Double.isInfinite(a2))) {
                h += k;//from  w w w  .j  ava 2 s  . c o m
                numSummed++;
            }
        }
    }

    System.out.println("n = " + n + " numSummed = " + numSummed);

    double a = -n - (1.0 / numSummed) * h;
    double aa = (1 + 0.75 / numSummed + 2.25 / Math.pow(numSummed, 2)) * a;
    double p;

    if (aa < 0.2) {
        p = 1 - Math.exp(-13.436 + 101.14 * aa - 223.73 * aa * aa);
    } else if (aa < 0.34) {
        p = 1 - Math.exp(-8.318 + 42.796 * aa - 59.938 * aa * aa);
    } else if (aa < 0.6) {
        p = Math.exp(0.9177 - 4.279 * aa - 1.38 * aa * aa);
    } else {
        p = Math.exp(1.2937 - 5.709 * aa + 0.0186 * aa * aa);
    }

    this.aSquared = a;
    this.aSquaredStar = aa;
    this.p = p;
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.CategoricalDist.java

@SuppressWarnings("unchecked")
public T sample() {

    Preconditions.checkState(!_entriesToLogProbs.isEmpty(), "No entries in the CDF");
    Preconditions.checkState(!Double.isInfinite(_logCumulativeProb), "No cumulative probability in CDF");

    if (_entriesToLogProbs.size() == 1) {
        return Iterables.getOnlyElement(_entriesToLogProbs.keySet());
    }//from  w  ww  .  ja  v a 2s .  c  o m

    if (_emd == null) {
        initializeDistribution();
    }

    _emd.setNumTrials(1);
    final Vector sampleRes = _emd.sample(threadLocalRng.get());
    final int newIdx = Iterables.indexOf(sampleRes, new Predicate<VectorEntry>() {
        @Override
        public boolean apply(VectorEntry input) {
            return Double.compare(input.getValue(), 0.0) >= 1;
        }
    });

    // final double u = threadLocalRng.get().nextDouble();
    // final int newIdx = (int) emd.inverseF(u);

    return (T) _entries[_objIdx.get(newIdx)];
}