Package org.apache.mahout.utils

Examples of org.apache.mahout.utils.EuclideanDistanceMeasure


        + canopy.toString()));
  }

  public boolean shiftToMean() {
    Vector centroid = computeCentroid();
    converged = new EuclideanDistanceMeasure().distance(centroid, center) < convergenceDelta;
    center = centroid;
    numPoints = 1;
    pointTotal = centroid.copy();
    return converged;
  }
View Full Code Here


   * test datapoints are clustered in a reasonable manner.
   *
   * @throws CardinalityException
   */
  public void testReferenceImplementation() {
    MeanShiftCanopy.config(new EuclideanDistanceMeasure(), 4.0, 1.0, 0.5);
    List<MeanShiftCanopy> canopies = new ArrayList<MeanShiftCanopy>();
    // add all points to the canopies
    for (Vector aRaw : raw) {
      MeanShiftCanopy.mergeCanopy(new MeanShiftCanopy(aRaw), canopies);
    }
View Full Code Here

  public void testFuzzyKMeansMapper() throws Exception {
    List<Vector> points = TestKmeansClustering
        .getPoints(TestKmeansClustering.reference);

    DistanceMeasure measure = new EuclideanDistanceMeasure();
    SoftCluster.config(measure, 0.001);

    for (int k = 0; k < points.size(); k++) {
      System.out.println("testKFuzzyKMeansMRJob k= " + k);
      // pick k initial cluster centers at random
View Full Code Here

  public void testFuzzyKMeansCombiner() throws Exception {
    List<Vector> points = TestKmeansClustering
        .getPoints(TestKmeansClustering.reference);

    DistanceMeasure measure = new EuclideanDistanceMeasure();
    SoftCluster.config(measure, 0.001);

    for (int k = 0; k < points.size(); k++) {
      System.out.println("testKFuzzyKMeansMRJob k= " + k);
      // pick k initial cluster centers at random
View Full Code Here

  public void testFuzzyKMeansReducer() throws Exception {
    List<Vector> points = TestKmeansClustering
        .getPoints(TestKmeansClustering.reference);

    DistanceMeasure measure = new EuclideanDistanceMeasure();
    SoftCluster.config(measure, 0.001);

    for (int k = 0; k < points.size(); k++) {
      System.out.println("testKFuzzyKMeansMRJob k= " + k);
      // pick k initial cluster centers at random
View Full Code Here

  public void testFuzzyKMeansClusterMapper() throws Exception {
    List<Vector> points = TestKmeansClustering
        .getPoints(TestKmeansClustering.reference);

    DistanceMeasure measure = new EuclideanDistanceMeasure();
    SoftCluster.config(measure, 0.001);

    for (int k = 0; k < points.size(); k++) {
      System.out.println("testKFuzzyKMeansMRJob k= " + k);
      // pick k initial cluster centers at random
View Full Code Here

   *
   * @throws Exception
   */
  public void testIterativeEuclidean() throws Exception {
    List<Vector> points = getPoints(raw);
    Canopy.config(new EuclideanDistanceMeasure(), 3.1, 2.1);

    List<Canopy> canopies = new ArrayList<Canopy>();
    for (Vector point : points)
      Canopy.addPointToCanopies(point, canopies);

View Full Code Here

   *
   * @throws Exception
   */
  public void testReferenceImplementation() throws Exception {
    List<Vector> points = getPoints(reference);
    DistanceMeasure measure = new EuclideanDistanceMeasure();
    Cluster.config(measure, 0.001);
    // try all possible values of k
    for (int k = 0; k < points.size(); k++) {
      System.out.println("Test k=" + (k + 1) + ':');
      // pick k initial cluster centers at random
View Full Code Here

   *
   * @throws Exception
   */
  public void testKMeansMapper() throws Exception {
    KMeansMapper mapper = new KMeansMapper();
    EuclideanDistanceMeasure euclideanDistanceMeasure = new EuclideanDistanceMeasure();
    Cluster.config(euclideanDistanceMeasure, 0.001);
    List<Vector> points = getPoints(reference);
    for (int k = 0; k < points.size(); k++) {
      // pick k initial cluster centers at random
      DummyOutputCollector<Text, Text> collector = new DummyOutputCollector<Text, Text>();
      List<Cluster> clusters = new ArrayList<Cluster>();

      for (int i = 0; i < k + 1; i++) {
        Cluster cluster = new Cluster(points.get(i));
        // add the center so the centroid will be correct upon output
        cluster.addPoint(cluster.getCenter());
        clusters.add(cluster);
      }

      Map<String, Cluster> clusterMap = loadClusterMap(clusters);
      mapper.config(clusters);
      // map the data
      for (Vector point : points) {
        mapper.map(new Text(), new Text(point.asFormatString()), collector,
            null);
      }
      assertEquals("Number of map results", k + 1, collector.getData().size());
      // now verify that all points are correctly allocated
      for (String key : collector.getKeys()) {
        Cluster cluster = clusterMap.get(key);
        List<Text> values = collector.getValue(key);
        for (Writable value : values) {
          String[] pointInfo = value.toString().split("\t");

          Vector point = AbstractVector.decodeVector(pointInfo[1]);
          double distance = euclideanDistanceMeasure.distance(cluster
              .getCenter(), point);
          for (Cluster c : clusters)
            assertTrue("distance error", distance <= euclideanDistanceMeasure
                .distance(point, c.getCenter()));
        }
      }
    }
  }
View Full Code Here

   *
   * @throws Exception
   */
  public void testKMeansCombiner() throws Exception {
    KMeansMapper mapper = new KMeansMapper();
    EuclideanDistanceMeasure euclideanDistanceMeasure = new EuclideanDistanceMeasure();
    Cluster.config(euclideanDistanceMeasure, 0.001);
    List<Vector> points = getPoints(reference);
    for (int k = 0; k < points.size(); k++) {
      // pick k initial cluster centers at random
      DummyOutputCollector<Text, Text> collector = new DummyOutputCollector<Text, Text>();
View Full Code Here

TOP

Related Classes of org.apache.mahout.utils.EuclideanDistanceMeasure

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.