Package org.apache.mahout.knn.search

Examples of org.apache.mahout.knn.search.BruteSearch


    return data;
  }

  @Override
  public UpdatableSearcher getSearch(int n) {
    return new BruteSearch(new EuclideanDistanceMeasure());
  }
View Full Code Here


  }

  @Test
  public void testMatrixSearch() {
    List<WeightedVector> referenceVectors = Lists.newArrayListWithExpectedSize(8);
    BruteSearch searcher = new BruteSearch(new EuclideanDistanceMeasure());
    for (int i = 0; i < 8; i++) {
      referenceVectors.add(new WeightedVector(
          new DenseVector(new double[]{0.125 * (i & 4), i & 2, i & 1}), 1, i));
      searcher.add(referenceVectors.get(referenceVectors.size() - 1));
    }

    final List<List<WeightedThing<Vector>>> searchResults =
        searcher.search(referenceVectors, 3);
    for (List<WeightedThing<Vector>> r : searchResults) {
      assertEquals(0, r.get(0).getWeight(), 1e-8);
      assertEquals(0.5, r.get(1).getWeight(), 1e-8);
      assertEquals(1, r.get(2).getWeight(), 1e-8);
    }
View Full Code Here

  @Test
  public void testBasicClustering() {
    List<? extends WeightedVector> data = cubishTestData(1);

    BallKMeans r = new BallKMeans(new BruteSearch(new EuclideanDistanceMeasure()), 6, 20);
    r.cluster(data);
    for (Centroid centroid : r) {
      for (int i = 0; i < 10; i++) {
        System.out.printf("%10.4f", centroid.get(i));
      }
View Full Code Here

  public void testInitialization() {
    // start with super clusterable data
    List<? extends WeightedVector> data = cubishTestData(0.01);

    // just do initialization of ball k-means.  This should drop a point into each of the clusters
    BallKMeans r = new BallKMeans(new BruteSearch(new EuclideanDistanceMeasure()), 6, 20);
    r.cluster(data);

    // put the centroids into a matrix
    Matrix x = new DenseMatrix(6, 5);
    int row = 0;
View Full Code Here

    }
    System.out.printf("Generated query matrix.\n");

    for (int threads : new int[]{1, 2, 3, 4, 5, 6, 10, 20, 50}) {
      for (int block : new int[]{1, 10, 50}) {
        BruteSearch search = new BruteSearch(new EuclideanDistanceMeasure());
        search.addAll(referenceVectors);
        long t0 = System.nanoTime();
        search.search(queryVectors, block, threads);
        long t1 = System.nanoTime();
        System.out.printf("%d\t%d\t%.2f\n", threads, block, (t1 - t0) / 1e9);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.knn.search.BruteSearch

Copyright © 2018 www.massapicom. 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.