Example usage for java.lang Double compare

List of usage examples for java.lang Double compare

Introduction

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

Prototype

public static int compare(double d1, double d2) 

Source Link

Document

Compares the two specified double values.

Usage

From source file:biomine.bmvis2.pipeline.BestPathHiderOperation.java

private void hideNodes(VisualGraph graph, long target) {
    HashSet<VisualNode> hiddenNodes = new HashSet<VisualNode>();

    ArrayList<VisualNode> nodes = new ArrayList<VisualNode>(graph.getAllNodes());
    if (this.grader == null || nodes.size() <= target) {
        graph.hideNodes(hiddenNodes);/*w  ww.ja va 2s.c o  m*/
        return;
    }

    Collections.sort(nodes, new Comparator<VisualNode>() {
        public int compare(VisualNode node1, VisualNode node2) {
            return Double.compare(grader.getNodeGoodness(node2), grader.getNodeGoodness(node1));
        }
    });

    for (VisualNode node : nodes) {
        if (target == 0)
            break;
        hiddenNodes.add(node);
        target--;
    }

    graph.hideNodes(hiddenNodes);
}

From source file:weatherRoute.MapHandler.java

public ArrayList<Location> getCities(String origin, String destination) {
    ArrayList<Location> cities = new ArrayList<Location>();

    origin = origin.replace(" ", "");
    destination = destination.replace(" ", "");

    String apiQuery = "https://maps.googleapis.com/maps/api/directions/json?origin=" + origin + "&destination="
            + destination + "&key=AIzaSyDbWBUUbN6UHlG9auqFVGmN6WJY9HSe8YI";

    try {/*www  . j  a v a2 s  . c  om*/
        URL url = new URL(apiQuery);
        HttpURLConnection request = (HttpURLConnection) url.openConnection();
        request.connect();

        JsonParser jp = new JsonParser();
        JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));

        //You have to step through the ugly, JSON within array within JSON stuff.
        JsonArray stepsArray = root.getAsJsonObject().getAsJsonArray("routes").get(0).getAsJsonObject()
                .getAsJsonArray("legs").get(0).getAsJsonObject().getAsJsonArray("steps");

        //loop through steps to get city locations
        for (JsonElement element : stepsArray) {
            //this gets a string value of the distance in miles
            String distance = element.getAsJsonObject().get("distance").getAsJsonObject().get("text")
                    .toString();

            if (distance.contains("mi")) {
                //parse return value and cast to a Double to be able to compare
                distance = distance.replace(" mi", "");
                distance = distance.replace("\"", "");
                Double test = Double.parseDouble(distance);

                //this limits out all the short .5 mile steps
                //should mostly get different cities now
                if (Double.compare(test, 10.0) > 0) {
                    System.out.println("TEST DISTANCE: " + distance + ", " + test);

                    JsonObject location = element.getAsJsonObject().get("end_location").getAsJsonObject();
                    String latitude = location.get("lat").toString();
                    String longitude = location.get("lng").toString();

                    Location tempLocation = new Location(Double.parseDouble(latitude),
                            Double.parseDouble(longitude));

                    cities.add(tempLocation);
                    //now I need to hit a different API and get CITY names from lat long
                    //http://stackoverflow.com/questions/6548504/how-can-i-get-city-name-from-a-latitude-and-longitude-point
                    //fortunately it shows me how here ^

                    //System.out.println("TEST LOCATION LAT: " + latitude + " LONG: " + longitude);
                }
            }
        }
    } catch (Exception e) {
        System.out.println("Error: " + e);
    }

    //testing();

    return cities;
}

From source file:com.opengamma.analytics.financial.simpleinstruments.pricing.SimpleFutureDataBundleDeprecated.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }/*from  ww  w  .j a v  a 2  s  .c  om*/
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof SimpleFutureDataBundleDeprecated)) {
        return false;
    }
    final SimpleFutureDataBundleDeprecated other = (SimpleFutureDataBundleDeprecated) obj;
    if (Double.compare(_marketPrice, other._marketPrice) != 0) {
        return false;
    }
    if (Double.compare(_spotValue, other._spotValue) != 0) {
        return false;
    }
    if (Double.compare(_dividendYield, other._dividendYield) != 0) {
        return false;
    }
    if (Double.compare(_costOfCarry, other._costOfCarry) != 0) {
        return false;
    }
    if (!ObjectUtils.equals(_fundingCurve, other._fundingCurve)) {
        return false;
    }
    return true;
}

From source file:edu.umich.robot.soar.SetHeadingLinearCommand.java

@Override
boolean isComplete() {
    double currentYaw = output.getPose().getYaw();
    double difference = targetYaw - currentYaw;
    difference = Math.abs(difference);

    return Double.compare(difference, TOLERANCE) < 0;
}

From source file:org.apache.mahout.knn.search.ProjectionSearchEval.java

public void testSearch() {
    final EuclideanDistanceMeasure distance = new EuclideanDistanceMeasure();
    for (int d = 20; d < 21; d++) {
        ProjectionSearch ps = new ProjectionSearch(20, distance, d, 1);
        List<Vector> ref = Lists.newArrayList();

        final DoubleFunction random = Functions.random();
        for (int i = 0; i < 40000; i++) {
            Vector v = new DenseVector(20);
            v.assign(random);/*from   www  .  j  a va2s .c o  m*/
            ps.add(v, i);
            ref.add(v);
        }

        double sim = 0;
        int nSim = 0;
        double D1 = 0;
        double D2 = 0;
        double D3 = 0;
        int searchSize = 800;
        int returnSize = 100;
        List<Vector> randomNeighbor = Lists.newArrayList();
        randomNeighbor.addAll(ref.subList(0, returnSize));

        for (int i = 0; i < 100; i++) {
            // final Vector query = new DenseVector(ref.get(0));
            final Vector query = new DenseVector(20);
            query.assign(random);
            Ordering<Vector> queryOrder = new Ordering<Vector>() {
                @Override
                public int compare(Vector v1, Vector v2) {
                    return Double.compare(distance.distance(query, v1), distance.distance(query, v2));
                }
            };

            ps.setSearchSize(searchSize);
            List<WeightedVector> r = ps.search(query, returnSize);

            Collections.sort(ref, queryOrder);
            List<Vector> trueNeighbor = ref.subList(0, returnSize);
            List<WeightedVector> proxyNeighbor = r.subList(0, returnSize);

            List<Vector> intersection1 = ListUtils.intersection(trueNeighbor, proxyNeighbor);
            List<Vector> union1 = ListUtils.sum(trueNeighbor, proxyNeighbor);
            // double jaccardSim = intersection1.size() / (double)union1.size();  
            // sim += jaccardSim;
            sim += intersection1.size() / (double) returnSize;
            nSim++;

            double d1 = 0;
            double d2 = 0;
            double d3 = 0;
            for (int j = 0; j < returnSize; j++) {
                d1 += distance.distance(query, trueNeighbor.get(j));
                d2 += distance.distance(query, proxyNeighbor.get(j));
                d3 += distance.distance(query, randomNeighbor.get(j));
                //System.out.print(distance.distance(query,trueNeighbor.get(j)));
                //System.out.print(" ");
                //System.out.println(distance.distance(query,randomNeighbor.get(j)));
            }
            d1 = d1 / returnSize;
            d2 = d2 / returnSize;
            d3 = d3 / returnSize;
            D1 += d1;
            D2 += d2;
            D3 += d3;

            /****
             System.out.print(intersection1.size());
             System.out.print(" ");
             System.out.print(union1.size());
             System.out.print(" ");
             System.out.println(jaccardSim);
             *****/
        }
        System.out.printf(
                "d=%d ave_sim=%.2f trueNeighbor_dist=%.2f proxyNeighbor_dist=%.2f randomNeighbor_dist=%.2f \n",
                d, sim / nSim, D1 / nSim, D2 / nSim, D3 / nSim);
    }

}

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

public double computePval(H1 h1, double[] x, double[] y) {
    double[] conc = ArrayUtils.concat(x, y);
    double[] r = naturalRanking.rank(conc);
    double[] rsort = r.clone();
    Arrays.sort(rsort);/*from w  w w  . j av  a2 s. c  om*/

    int nx = x.length;
    int ny = y.length;
    double w = xsum(r, nx) - nx * (nx + 1) / 2;
    double tiesSum = 0;
    int s = 0;
    for (int i = 1; i < rsort.length; i++) {
        if (Double.compare(rsort[s], rsort[i]) < 0) {
            double d = i - s;
            if (d > 1)
                tiesSum += d * d * d - d;
            s = i;
        }
    }
    int d = r.length - s;
    if (d > 1)
        tiesSum += d * d * d * -d;
    double z = w - nx * ny / 2;
    double SIGMA = Math.sqrt((nx * ny / 12) * ((nx + ny + 1) - tiesSum / ((nx + ny) * (nx + ny - 1))));
    double CORRECTION = Math.signum(z) * 0.5;
    if (h1 == H1.GREATER_THAN)
        CORRECTION = 0.5;
    else if (h1 == H1.LESS_THAN)
        CORRECTION = 0.5;

    z = (z - CORRECTION) / SIGMA;
    double PVAL = norm.cumulativeProbability(z);
    if (h1 == H1.GREATER_THAN)
        PVAL = 1 - PVAL;
    else if (h1 == H1.NOT_EQUAL)
        PVAL = 2 * Math.min(PVAL, 1 - PVAL);

    return PVAL;
}

From source file:com.hybris.mobile.lib.location.geofencing.data.GeofenceObject.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    GeofenceObject that = (GeofenceObject) o;

    if (Double.compare(that.latitude, latitude) != 0)
        return false;
    if (Double.compare(that.longitude, longitude) != 0)
        return false;
    if (Float.compare(that.radius, radius) != 0)
        return false;
    if (expirationDuration != that.expirationDuration)
        return false;
    if (transitionType != that.transitionType)
        return false;
    if (id != null ? !id.equals(that.id) : that.id != null)
        return false;
    return !(notificationByTransition != null ? !notificationByTransition.equals(that.notificationByTransition)
            : that.notificationByTransition != null);
}

From source file:net.big_oh.algorithms.search.informed.astar.AStarSearch.java

public AStarSearchResult<SearchNodeType> doSearch(SearchNodeType startNode) {

    Duration searchDuration = new Duration();

    // create priority queue
    SortedSet<SearchNodeType> prioritySet = new TreeSet<SearchNodeType>(new Comparator<SearchNodeType>() {

        public int compare(SearchNodeType o1, SearchNodeType o2) {
            switch (searchType) {
            case MIN:
                return Double.compare(getF(o1), getF(o2));
            case MAX:
                return -1 * Double.compare(getF(o1), getF(o2));
            default:
                throw new RuntimeException("Unexpected search type: " + searchType);
            }/*  w ww  .  j av  a2 s.  c  o  m*/
        }

    });

    // enqueue the start node
    prioritySet.add(startNode);

    // declare tracking member variables
    int numSearchNodesGenerated = 0;
    int numSearchNodesConsidered = 0;
    int maxPossibleBranchingFactor = 1;

    // search for a goal state
    SearchNodeType goalNode = null;
    while (!prioritySet.isEmpty()) {

        // Remove the best candidate node from the queue
        SearchNodeType candidateSearchNode = prioritySet.first();
        prioritySet.remove(candidateSearchNode);
        numSearchNodesConsidered++;

        // get the next search node candidates
        Collection<SearchNodeType> nextSearchNodes = nextNodesGenerator.getNextSearchNodes(candidateSearchNode);

        // do some record keeping
        numSearchNodesGenerated += nextSearchNodes.size();
        maxPossibleBranchingFactor = Math.max(maxPossibleBranchingFactor, nextSearchNodes.size());

        if (candidateSearchNode.isGoalState()) {
            // sanity check
            assert (nextSearchNodes.isEmpty());

            // found an optimal solution
            goalNode = candidateSearchNode;
            break;
        } else {
            // enqueue all next search nodes
            Duration enqueueDuration = new Duration();

            prioritySet.addAll(nextSearchNodes);

            if (logger.isDebugEnabled()) {
                logger.debug("Enqueued " + nextSearchNodes.size() + " A* search nodes in "
                        + enqueueDuration.stop() + " milliseconds.");
            }
        }

    }

    // return the search results
    AStarSearchResult<SearchNodeType> results = new AStarSearchResult<SearchNodeType>(goalNode,
            numSearchNodesGenerated, calculateEffectiveBranchingFactor(goalNode.getNodeDepth(),
                    numSearchNodesConsidered, maxPossibleBranchingFactor));

    logger.debug("Completed an A* search in " + searchDuration.stop() + " milliseconds.");
    logger.debug("Number of nodes generated: " + results.getNumSearchNodesGenerated());
    logger.debug("Depth of goal node: " + results.getGoalNode().getNodeDepth());
    logger.debug("Effective branching factor: " + results.getEfectiveBranchingFactor());

    return results;

}

From source file:io.seldon.client.beans.DemographicBean.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (!(o instanceof DemographicBean))
        return false;

    DemographicBean that = (DemographicBean) o;

    if (Double.compare(that.amount, amount) != 0)
        return false;
    if (demoId != that.demoId)
        return false;
    if (attr != null ? !attr.equals(that.attr) : that.attr != null)
        return false;
    if (attrName != null ? !attrName.equals(that.attrName) : that.attrName != null)
        return false;
    if (val != null ? !val.equals(that.val) : that.val != null)
        return false;
    if (valName != null ? !valName.equals(that.valName) : that.valName != null)
        return false;

    return true;// w  w w. j  a v a 2s .  c  o  m
}

From source file:org.apache.mahout.knn.search.OldProjectionSearchTest.java

public void testSearch() {
    final EuclideanDistanceMeasure distance = new EuclideanDistanceMeasure();
    for (int d = 10; d < 11; d++) {
        ProjectionSearch ps = new ProjectionSearch(20, distance, d, 1);
        List<Vector> ref = Lists.newArrayList();

        final DoubleFunction random = Functions.random();
        for (int i = 0; i < 40000; i++) {
            Vector v = new DenseVector(20);
            v.assign(random);/*from  w  w  w  . j  a v  a  2 s  .c  om*/
            ps.add(v, i);
            ref.add(v);
        }

        double sim = 0;
        int nSim = 0;
        double D1 = 0;
        double D2 = 0;
        double D3 = 0;
        int searchSize = 400;
        int returnSize = 100;
        List<Vector> randomNeighbor = Lists.newArrayList();
        randomNeighbor.addAll(ref.subList(0, returnSize));

        long runningTime = 0;

        for (int i = 0; i < 100; i++) {
            // final Vector query = new DenseVector(ref.get(0));
            final Vector query = new DenseVector(20);
            query.assign(random);
            Ordering<Vector> queryOrder = new Ordering<Vector>() {
                @Override
                public int compare(Vector v1, Vector v2) {
                    return Double.compare(distance.distance(query, v1), distance.distance(query, v2));
                }
            };

            Collections.sort(ref, queryOrder);
            List<Vector> trueNeighbor = ref.subList(0, returnSize);

            long t1 = System.nanoTime();
            ps.setSearchSize(searchSize);
            List<WeightedVector> r = ps.search(query, returnSize);
            long t2 = System.nanoTime();
            runningTime = runningTime + t2 - t1;

            List<WeightedVector> proxyNeighbor = r.subList(0, returnSize);
            List<Vector> intersection1 = ListUtils.intersection(trueNeighbor, proxyNeighbor);
            List<Vector> union1 = ListUtils.sum(trueNeighbor, proxyNeighbor);
            // double jaccardSim = intersection1.size() / (double)union1.size();  
            // sim += jaccardSim;
            sim += intersection1.size() / (double) returnSize;
            nSim++;

            double d1 = 0;
            double d2 = 0;
            double d3 = 0;
            for (int j = 0; j < returnSize; j++) {
                d1 += distance.distance(query, trueNeighbor.get(j));
                d2 += distance.distance(query, proxyNeighbor.get(j));
                d3 += distance.distance(query, randomNeighbor.get(j));
                //System.out.print(distance.distance(query,trueNeighbor.get(j)));
                //System.out.print(" ");
                //System.out.println(distance.distance(query,randomNeighbor.get(j)));
            }
            d1 = d1 / returnSize;
            d2 = d2 / returnSize;
            d3 = d3 / returnSize;
            D1 += d1;
            D2 += d2;
            D3 += d3;

            /****
            System.out.print(intersection1.size());
            System.out.print(" ");
            System.out.print(union1.size());
            System.out.print(" ");
            System.out.println(jaccardSim);
            *****/
        }
        System.out.printf(
                "d=%d ave_sim=%.2f trueNeighbor_dist=%.2f proxyNeighbor_dist=%.2f randomNeighbor_dist=%.2f \n",
                d, sim / nSim, D1 / nSim, D2 / nSim, D3 / nSim);
        System.out.printf("running time = %.2f seconds \n", runningTime / 1e9);
    }

}