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:mulavito.algorithms.shortestpath.ksp.Eppstein.java

@Override
protected List<List<E>> getShortestPathsIntern(V source, V target, int k) {
    PriorityQueue<WeightedPath> prioQ = new PriorityQueue<WeightedPath>();
    List<List<E>> found_paths = new LinkedList<List<E>>();

    Transformer<E, Double> delta = prepareTransformations(target);

    // Initialize with start vertex.
    prioQ.add(new WeightedPath(source));

    while (!prioQ.isEmpty() && found_paths.size() < k) {
        WeightedPath curPath = prioQ.poll(); // get & remove next shortest
        V curV = curPath.getLast();/*ww  w  .ja v  a2  s  .c  o  m*/

        if (curV.equals(target)) {
            found_paths.add(curPath.getPath());
            continue;
        }

        // Create new paths for every expanded vertex ...
        for (V nextV : graph.getSuccessors(curV)) {
            if (curPath.contains(nextV))
                continue; // Prevent looping!

            // ... and every possible edge.
            for (E e : graph.findEdgeSet(curV, nextV)) {
                if (Double.isInfinite(delta.transform(e)))
                    continue; // Skip unreachable vertices.

                WeightedPath tmpPath = new WeightedPath(curPath); // clone
                tmpPath.addHop(e, delta.transform(e), nextV);

                prioQ.add(tmpPath);
            }
        }
    }

    return found_paths;
}

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

public boolean hasProbability() {
    return !Double.isInfinite(_logCumulativeProb);
}

From source file:edu.stanford.cfuller.imageanalysistools.clustering.GaussianLikelihoodObjectiveFunction.java

/**
 * Evaluates the function with the specified parameters.
 *
 * The parameters describe a set of gaussian generators (which are the Clusters).
 *
 * @param parameters    A RealVector containing the values of all the parameters of each Gaussian, ordered so that all the parameters of a single gaussian are together, then the next gaussian, etc.
 * @return              The negative log likelihood of having observed the ClusterObjects at their locations, given the parameters describing the Gaussian clusters.
 *///  w  ww  .  ja v a 2  s. c o  m
public double evaluate(RealVector parameters) {

    int nClusters = parameters.getDimension() / nParametersEach;

    //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("nClusters: " + nClusters + "  abdMatrices_size: " + abdMatrices.size() + "  det_dim: " + det.getDimension());

    if (det.getDimension() != nClusters) {

        clusterProbs = new Array2DRowRealMatrix(this.objects.size(), nClusters);
        det = new ArrayRealVector(nClusters);
        pk = new ArrayRealVector(nClusters);

        if (abdMatrices.size() < nClusters) {
            int originalSize = abdMatrices.size();
            for (int i = 0; i < nClusters - originalSize; i++) {
                abdMatrices.add(new Array2DRowRealMatrix(numDim, numDim));
            }
        } else {
            abdMatrices.setSize(nClusters);
        }

    }

    pk.mapMultiplyToSelf(0.0);

    //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("nClusters: " + nClusters + "  abdMatrices_size: " + abdMatrices.size() + "  det_dim: " + det.getDimension());

    for (int i = 0; i < nClusters; i++) {
        /*
        double ct = Math.cos(parameters.getEntry(nParametersEach*i+3));
        double st = Math.sin(parameters.getEntry(nParametersEach*i+3));
        double sin2t = Math.sin(2*parameters.getEntry(nParametersEach*i+3));
        double a = (ct*ct/(2*parameters.getEntry(nParametersEach*i+2)) + st*st/(2*parameters.getEntry(nParametersEach*i+4)));
        double b = (sin2t/(4*parameters.getEntry(nParametersEach*i+4)) - sin2t/(4*parameters.getEntry(nParametersEach*i+2)));
        double d = (st*st/(2*parameters.getEntry(nParametersEach*i+2)) + ct*ct/(2*parameters.getEntry(nParametersEach*i+4)));
        */

        double a = parameters.getEntry(nParametersEach * i + 2);
        double d = parameters.getEntry(nParametersEach * i + 4);
        double b = Math.sqrt(a * d) * parameters.getEntry(nParametersEach * i + 3);

        abdMatrices.get(i).setEntry(0, 0, a);
        abdMatrices.get(i).setEntry(1, 0, b);
        abdMatrices.get(i).setEntry(0, 1, b);
        abdMatrices.get(i).setEntry(1, 1, d);

        LUDecomposition abdLU = (new LUDecomposition(abdMatrices.get(i)));

        det.setEntry(i, (abdLU).getDeterminant());
        //det.setEntry(i, a*d-b*b);
        try {
            abdMatrices.set(i, abdLU.getSolver().getInverse());
        } catch (org.apache.commons.math3.linear.SingularMatrixException e) {
            return Double.MAX_VALUE;
        }

    }

    for (int n = 0; n < this.objects.size(); n++) {

        ClusterObject c = this.objects.get(n);

        double max = -1.0 * Double.MAX_VALUE;
        int maxIndex = 0;

        for (int k = 0; k < nClusters; k++) {

            mean.setEntry(0, c.getCentroid().getX() - parameters.getEntry(nParametersEach * k));
            mean.setEntry(1, c.getCentroid().getY() - parameters.getEntry(nParametersEach * k + 1));

            x = abdMatrices.get(k).operate(mean);

            double dot = x.dotProduct(mean);

            //                java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("k, n: " + k + ", " + this.objects.size());
            //                java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("parameters: " + parameters.toString());
            //                java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("abd matrix: " + abdMatrices.get(k).toString());
            //                java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("det: " + det.getEntry(k));
            //                java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("mean: " + mean.toString());
            //                java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("dot: " + dot);

            double logN = negLog2PI - 0.5 * Math.log(det.getEntry(k)) - 0.5 * dot;

            //                java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("logN: " + logN);

            clusterProbs.setEntry(n, k, logN);
            if (logN > max) {
                max = logN;
                maxIndex = k;
            }

            if (Double.isInfinite(logN) || Double.isNaN(logN)) {
                return Double.MAX_VALUE;
            }

        }

        c.setMostProbableCluster(maxIndex);

    }

    for (int k = 0; k < nClusters; k++) {

        double tempMax = -1.0 * Double.MAX_VALUE;

        for (int n = 0; n < this.objects.size(); n++) {
            if (clusterProbs.getEntry(n, k) > tempMax)
                tempMax = clusterProbs.getEntry(n, k);
        }

        pk.setEntry(k,
                tempMax + Math.log(
                        clusterProbs.getColumnVector(k).mapSubtract(tempMax).mapToSelf(new Exp()).getL1Norm())
                        - Math.log(this.objects.size()));

    }

    double pkMax = -1.0 * Double.MAX_VALUE;

    for (int k = 0; k < nClusters; k++) {
        if (pk.getEntry(k) > pkMax)
            pkMax = pk.getEntry(k);
    }

    double logSumPk = pkMax + Math.log(pk.mapSubtract(pkMax).mapToSelf(new Exp()).getL1Norm());

    pk.mapSubtractToSelf(logSumPk);

    //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("pk: " + pk.toString());

    double L = 0;

    for (int n = 0; n < this.objects.size(); n++) {

        RealVector toSum = clusterProbs.getRowVector(n).add(pk);

        double tempMax = -1.0 * Double.MAX_VALUE;

        for (int k = 0; k < nClusters; k++) {
            if (toSum.getEntry(k) > tempMax)
                tempMax = toSum.getEntry(k);
        }

        double pn = tempMax + Math.log(toSum.mapSubtract(tempMax).mapToSelf(new Exp()).getL1Norm());

        //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("pn: " + pn);

        L += pn;

    }

    return -1.0 * L;
}

From source file:org.opentripplanner.analyst.request.SampleGridRenderer.java

/**
 * Sample a SPT using a SPTWalker and an AccumulativeGridSampler.
 * /*from  w w  w .j  av a 2s  . c  o  m*/
 * @param spt
 * @return
 */
public static void sampleSPT(ShortestPathTree spt, ZSampleGrid<WTWD> sampleGrid, final double d0,
        final double gridSizeMeters, final double v0, final double maxWalkDistance, final double cosLat) {

    final DistanceLibrary distanceLibrary = SphericalDistanceLibrary.getInstance();

    // Below is a closure that makes use of the parameters to the enclosing function.

    /**
     * Any given sample is weighted according to the inverse of the squared normalized distance
     * + 1 to the grid sample. We add to the sampling time a default off-road walk distance to
     * account for off-road sampling.
     */
    AccumulativeMetric<WTWD> accMetric = new AccumulativeMetric<WTWD>() {
        @Override
        public WTWD cumulateSample(Coordinate C0, Coordinate Cs, WTWD z, WTWD zS) {
            double t = z.wTime / z.w;
            double b = z.wBoardings / z.w;
            double wd = z.wWalkDist / z.w;
            double d = distanceLibrary.fastDistance(C0, Cs, cosLat);
            // additionnal time
            double dt = d / v0;
            // t weight
            double w = 1 / ((d + d0) * (d + d0));
            if (zS == null) {
                zS = new WTWD();
                zS.d = Double.MAX_VALUE;
            }
            zS.w = zS.w + w;
            zS.wTime = zS.wTime + w * (t + dt);
            zS.wBoardings = zS.wBoardings + w * b;
            zS.wWalkDist = zS.wWalkDist + w * (wd + d);
            if (d < zS.d)
                zS.d = d;
            return zS;
        }

        /**
         * A Generated closing sample take 1) as off-road distance, the minimum of the off-road
         * distance of all enclosing samples, plus the grid size, and 2) as time the minimum
         * time of all enclosing samples plus the grid size * off-road walk speed as additional
         * time. All this are approximations.
         *
         * TODO Is there a better way of computing this? Here the computation will be different
         * based on the order where we close the samples.
         */
        @Override
        public WTWD closeSample(WTWD zUp, WTWD zDown, WTWD zRight, WTWD zLeft) {
            double dMin = Double.MAX_VALUE;
            double tMin = Double.MAX_VALUE;
            double bMin = Double.MAX_VALUE;
            double wdMin = Double.MAX_VALUE;
            for (WTWD z : new WTWD[] { zUp, zDown, zRight, zLeft }) {
                if (z == null)
                    continue;
                if (z.d < dMin)
                    dMin = z.d;
                double t = z.wTime / z.w;
                if (t < tMin)
                    tMin = t;
                double b = z.wBoardings / z.w;
                if (b < bMin)
                    bMin = b;
                double wd = z.wWalkDist / z.w;
                if (wd < wdMin)
                    wdMin = wd;
            }
            WTWD z = new WTWD();
            z.w = 1.0;
            /*
             * The computations below are approximation, but we are on the edge anyway and the
             * current sample does not correspond to any computed value.
             */
            z.wTime = tMin + gridSizeMeters / v0;
            z.wBoardings = bMin;
            z.wWalkDist = wdMin + gridSizeMeters;
            z.d = dMin + gridSizeMeters;
            return z;
        }
    };
    final AccumulativeGridSampler<WTWD> gridSampler = new AccumulativeGridSampler<WTWD>(sampleGrid, accMetric);

    SPTWalker johnny = new SPTWalker(spt);
    johnny.walk(new SPTVisitor() {
        @Override
        public final boolean accept(Edge e) {
            return e instanceof StreetEdge;
        }

        @Override
        public final void visit(Coordinate c, State s0, State s1, double d0, double d1) {
            double wd0 = s0.getWalkDistance() + d0;
            double wd1 = s0.getWalkDistance() + d1;
            double t0 = wd0 > maxWalkDistance ? Double.POSITIVE_INFINITY : s0.getActiveTime() + d0 / v0;
            double t1 = wd1 > maxWalkDistance ? Double.POSITIVE_INFINITY : s1.getActiveTime() + d1 / v0;
            if (!Double.isInfinite(t0) || !Double.isInfinite(t1)) {
                WTWD z = new WTWD();
                z.w = 1.0;
                z.d = 0.0;
                if (t0 < t1) {
                    z.wTime = t0;
                    z.wBoardings = s0.getNumBoardings();
                    z.wWalkDist = s0.getWalkDistance();
                } else {
                    z.wTime = t1;
                    z.wBoardings = s1.getNumBoardings();
                    z.wWalkDist = s1.getWalkDistance();
                }
                gridSampler.addSamplingPoint(c, z);
            }
        }
    }, d0);
    gridSampler.close();
}

From source file:com.bmwcarit.barefoot.matcher.MatcherKState.java

public JSONObject toMonitorJSON() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("time", sample().time());
    json.put("point",
            GeometryEngine.geometryToWkt(estimate().point().geometry(), WktExportFlags.wktExportPoint));
    Polyline routes = monitorRoute(estimate());
    if (routes.getPathCount() > 0) {
        json.put("route", GeometryEngine.geometryToWkt(routes, WktExportFlags.wktExportMultiLineString));
    }//w ww . j a va2s . c  om

    JSONArray candidates = new JSONArray();
    for (MatcherCandidate candidate : vector()) {
        JSONObject jsoncandidate = new JSONObject();
        jsoncandidate.put("point",
                GeometryEngine.geometryToWkt(candidate.point().geometry(), WktExportFlags.wktExportPoint));
        jsoncandidate.put("prob", Double.isInfinite(candidate.filtprob()) ? "Infinity" : candidate.filtprob());

        routes = monitorRoute(candidate);
        if (routes.getPathCount() > 0) {
            jsoncandidate.put("route",
                    GeometryEngine.geometryToWkt(routes, WktExportFlags.wktExportMultiLineString));
        }
        candidates.put(jsoncandidate);
    }
    json.put("candidates", candidates);
    return json;
}

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

public boolean canSample() {
    return !_entriesToLogProbs.isEmpty() && !Double.isInfinite(_logCumulativeProb);
}

From source file:Complex.java

/**
 * Returns a {@code Complex} whose value is {@code this * factor}.
 * Implements preliminary checks for {@code NaN} and infinity followed by
 * the definitional formula://from w ww  .j  a  v a  2 s.c o m
 * <pre>
 *  <code>
 *   (a + bi)(c + di) = (ac - bd) + (ad + bc)i
 *  </code>
 * </pre>
 * Returns {@link #NaN} if either {@code this} or {@code factor} has one or
 * more {@code NaN} parts.
 * <br/>
 * Returns {@link #INF} if neither {@code this} nor {@code factor} has one
 * or more {@code NaN} parts and if either {@code this} or {@code factor}
 * has one or more infinite parts (same result is returned regardless of
 * the sign of the components).
 * <br/>
 * Returns finite values in components of the result per the definitional
 * formula in all remaining cases.
 *
 * @param  factor value to be multiplied by this {@code Complex}.
 * @return {@code this * factor}.
 * @throws NullArgumentException if {@code factor} is {@code null}.
 */
public Complex multiply(Complex factor) throws NullArgumentException {
    MathUtils.checkNotNull(factor);
    if (isNaN || factor.isNaN) {
        return NaN;
    }
    if (Double.isInfinite(real) || Double.isInfinite(imaginary) || Double.isInfinite(factor.real)
            || Double.isInfinite(factor.imaginary)) {
        // we don't use isInfinite() to avoid testing for NaN again
        return INF;
    }
    return createComplex(real * factor.real - imaginary * factor.imaginary,
            real * factor.imaginary + imaginary * factor.real);
}

From source file:org.broadinstitute.gatk.engine.recalibration.RecalDatum.java

public synchronized void setEmpiricalQuality(final double empiricalQuality) {
    if (empiricalQuality < 0)
        throw new IllegalArgumentException("empiricalQuality < 0");
    if (Double.isInfinite(empiricalQuality))
        throw new IllegalArgumentException("empiricalQuality is infinite");
    if (Double.isNaN(empiricalQuality))
        throw new IllegalArgumentException("empiricalQuality is NaN");

    this.empiricalQuality = empiricalQuality;
}

From source file:r.lang.DoubleVector.java

public static boolean isFinite(double d) {
    return !Double.isInfinite(d) && !Double.isNaN(d);
}

From source file:com.joptimizer.optimizers.LPPresolver.java

public LPPresolver(double unboundedLBValue, double unboundedUBValue) {
    if (!Double.isNaN(unboundedLBValue) && !Double.isInfinite(unboundedLBValue)) {
        throw new IllegalArgumentException(
                "The field unboundedLBValue must be set to Double.NaN or Double.NEGATIVE_INFINITY");
    }/*from w  ww  .j  a  v a 2 s . com*/
    if (!Double.isNaN(unboundedUBValue) && !Double.isInfinite(unboundedUBValue)) {
        throw new IllegalArgumentException(
                "The field unboundedUBValue must be set to Double.NaN or Double.POSITIVE_INFINITY");
    }
    //      this.unspecifiedLBValue = unspecifiedLBValue;
    //      this.unspecifiedUBValue = unspecifiedUBValue;
    this.unboundedLBValue = unboundedLBValue;
    this.unboundedUBValue = unboundedUBValue;
}