Examples of EuclidianDistance


Examples of de.jungblut.distance.EuclidianDistance

  @Test
  public void testKMeansClustering() {
    ArrayList<DoubleVector> lst = getClusteringInput();

    KMeansClustering clusterer = new KMeansClustering(2, lst, false);
    EuclidianDistance dist = new EuclidianDistance();
    List<Cluster> assignments = clusterer.cluster(100, dist, 0.1d, false);
    DoubleVector[] centers = clusterer.getCenters();
    assertEquals(49.5, centers[0].get(0), 1e-4);
    assertEquals(24.5, centers[0].get(1), 1e-4);
    assertEquals(49.5, centers[1].get(0), 1e-4);
    assertEquals(74.5, centers[1].get(1), 1e-4);

    // the centers should partition the space in half
    assertEquals(2, assignments.size());
    assertEquals(5000, assignments.get(0).getAssignments().size());
    assertEquals(5000, assignments.get(1).getAssignments().size());
    // now verify the assignments
    for (DoubleVector v : assignments.get(0).getAssignments()) {
      double distRightCenter = dist.measureDistance(v, centers[0]);
      double distOtherCenter = dist.measureDistance(v, centers[1]);
      assertTrue(distRightCenter < distOtherCenter);
    }
    for (DoubleVector v : assignments.get(1).getAssignments()) {
      double distRightCenter = dist.measureDistance(v, centers[1]);
      double distOtherCenter = dist.measureDistance(v, centers[0]);
      assertTrue(distRightCenter < distOtherCenter);
    }
  }
View Full Code Here

Examples of de.jungblut.distance.EuclidianDistance

  public void testCanopyClustering() {

    double t1 = 100;
    double t2 = 50d;
    ArrayList<DoubleVector> input = KMeansClusteringTest.getClusteringInput();
    EuclidianDistance measure = new EuclidianDistance();
    List<DoubleVector> canopies = CanopyClustering.createCanopies(input,
        measure, t1, t2, false);

    assertEquals(8, canopies.size());
    // now check if the properties hold
    for (DoubleVector v : canopies) {
      // remove all vectors that are in t1
      Iterator<DoubleVector> iterator = input.iterator();
      while (iterator.hasNext()) {
        DoubleVector next = iterator.next();
        if (measure.measureDistance(v, next) < t1) {
          iterator.remove();
        }
      }
    }
    // so in the end, we should have an empty input
View Full Code Here

Examples of de.jungblut.distance.EuclidianDistance

    KDTree<Integer> kdTree = new KDTree<>();
    int index = 0;
    for (DoubleVector v : points) {
      kdTree.add(v, index++);
    }
    double maxRadius = new EuclidianDistance().measureDistance(
        new double[] { 250 }, new double[] { 351 });

    List<VectorDistanceTuple<Integer>> neighbours = kdTree
        .getNearestNeighbours(new DenseDoubleVector(new double[] { 250 }),
            maxRadius);
View Full Code Here

Examples of de.jungblut.distance.EuclidianDistance

  @Test
  public void testClustering() {

    double t1 = 10;
    ArrayList<DoubleVector> input = KMeansClusteringTest.getClusteringInput();
    EuclidianDistance measure = new EuclidianDistance();
    OnePassExclusiveClustering clusterer = new OnePassExclusiveClustering(t1,
        Integer.MAX_VALUE, 1, false);
    List<DoubleVector> centers = clusterer.cluster(input, false);

    assertEquals(6377, centers.size());
    // now check if the properties hold
    for (DoubleVector v : centers) {
      // remove all vectors that are in t1
      Iterator<DoubleVector> iterator = input.iterator();
      while (iterator.hasNext()) {
        DoubleVector next = iterator.next();
        if (measure.measureDistance(v, next) < t1) {
          iterator.remove();
        }
      }
    }
    // so in the end, we should have an empty input
View Full Code Here

Examples of de.jungblut.distance.EuclidianDistance

  public void testDBSCAN() {
    List<DoubleVector> input = KMeansClusteringTest.getClusteringInput();
    // add some noise!
    input.add(new DenseDoubleVector(new double[] { 2000, 2000 }));

    EuclidianDistance measure = new EuclidianDistance();

    List<List<DoubleVector>> cluster = DBSCANClustering.cluster(input, measure,
        5, 100d);
    // we should just have a single connected cluster with all the points, but
    // the noise
View Full Code Here

Examples of de.jungblut.distance.EuclidianDistance

    for (DenseDoubleVector v : array) {
      tree.add(v);
    }

    double maxDist = new EuclidianDistance()
        .measureDistance(array[0], array[1]);
    List<VectorDistanceTuple<Object>> nearestNeighbours = tree
        .getNearestNeighbours(new DenseDoubleVector(new double[] { 5, 4 }),
            maxDist);
    Collections.sort(nearestNeighbours);
View Full Code Here

Examples of de.jungblut.distance.EuclidianDistance

    ArrayList<DoubleVector> input = KMeansClusteringTest.getClusteringInput(10,
        10);
    // add some noise!
    input.add(new DenseDoubleVector(new double[] { 2000, 2000 }));

    EuclidianDistance measure = new EuclidianDistance();

    DBSCAN scan = new DBSCAN();
    ArrayList<DoubleVector>[] cluster = scan.cluster(input, measure, 5, 100);
    // we should just have a single connected cluster with all the points, but
    // the noise
View Full Code Here

Examples of org.apache.hama.ml.distance.EuclidianDistance

      } catch (ClassNotFoundException e) {
        throw new RuntimeException("Wrong DistanceMeasurer implementation "
            + distanceClass + " provided");
      }
    } else {
      distanceMeasurer = new EuclidianDistance();
    }

    maxIterations = peer.getConfiguration().getInt(MAX_ITERATIONS_KEY, -1);
    // normally we want to rely on OS caching, but if not, we can cache in heap
    if (peer.getConfiguration().getBoolean(CACHING_ENABLED_KEY, false)) {
View Full Code Here

Examples of org.apache.hama.ml.distance.EuclidianDistance

        throw new RuntimeException(new StringBuilder("Wrong DistanceMeasurer implementation ").
            append(distanceClass).append(" provided").toString());
      }
    }
    else {
      distanceMeasurer = new EuclidianDistance();
    }

    maxIterations = peer.getConfiguration().getInt(MAX_ITERATIONS_KEY, -1);
    // normally we want to rely on OS caching, but if not, we can cache in heap
    if (peer.getConfiguration().getBoolean(CACHING_ENABLED_KEY, false)) {
View Full Code Here

Examples of org.apache.hama.ml.distance.EuclidianDistance

        throw new RuntimeException(new StringBuilder("Wrong DistanceMeasurer implementation ").
            append(distanceClass).append(" provided").toString());
      }
    }
    else {
      distanceMeasurer = new EuclidianDistance();
    }

    maxIterations = peer.getConfiguration().getInt(MAX_ITERATIONS_KEY, -1);
    // normally we want to rely on OS caching, but if not, we can cache in heap
    if (peer.getConfiguration().getBoolean(CACHING_ENABLED_KEY, false)) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.