Package org.apache.mahout.clustering.classify

Examples of org.apache.mahout.clustering.classify.WeightedVectorWritable


        for (Pair<Writable, ClusterWritable> record
            : new SequenceFileIterable<Writable, ClusterWritable>(s.getPath(), conf)) {
          ClusterWritable clusterWritable = record.getSecond();
          MeanShiftCanopy canopy = (MeanShiftCanopy) clusterWritable.getValue();
          MeanShiftCanopy closest = MeanShiftCanopyClusterer.findCoveringCanopy(canopy, clusters);
          writer.append(new IntWritable(closest.getId()), new WeightedVectorWritable(1, canopy.getCenter()));
        }
      } finally {
        Closeables.close(writer, false);
      }
    }
View Full Code Here


    int vectorId = canopy.getId();
    for (MeanShiftCanopy msc : canopies) {
      for (int containedId : msc.getBoundPoints().toList()) {
        if (vectorId == containedId) {
          context.write(new IntWritable(msc.getId()),
                         new WeightedVectorWritable(1, canopy.getCenter()));
        }
      }
    }
  }
View Full Code Here

    Map<Integer,List<WeightedVectorWritable>> clusterIdToPoints = getClusterIdToPoints();
    List<WeightedVectorWritable> points = clusterIdToPoints.get(clusterWritable.getValue().getId());
    if (points != null) {
      writer.write("\tWeight : [props - optional]:  Point:\n\t");
      for (Iterator<WeightedVectorWritable> iterator = points.iterator(); iterator.hasNext();) {
        WeightedVectorWritable point = iterator.next();
        writer.write(String.valueOf(point.getWeight()));
        if (point instanceof WeightedPropertyVectorWritable) {
          WeightedPropertyVectorWritable tmp = (WeightedPropertyVectorWritable) point;
          Map<Text,Text> map = tmp.getProperties();
          // map can be null since empty maps when written are returned as null
          writer.write(" : [");
          if (map != null) {
            for (Map.Entry<Text,Text> entry : map.entrySet()) {
              writer.write(entry.getKey().toString());
              writer.write("=");
              writer.write(entry.getValue().toString());
            }
          }
          writer.write("]");
        }
       
        writer.write(": ");
       
        writer.write(AbstractCluster.formatVector(point.getVector(), dictionary));
        if (iterator.hasNext()) {
          writer.write("\n\t");
        }
      }
      writer.write('\n');
View Full Code Here

  @Override
  protected void reduce(IntWritable key, Iterable<WeightedVectorWritable> values, Context context)
    throws IOException, InterruptedException {
    // find the most distant point
    WeightedVectorWritable mdp = null;
    for (WeightedVectorWritable dpw : values) {
      if (mdp == null || mdp.getWeight() < dpw.getWeight()) {
        mdp = new WeightedVectorWritable(dpw.getWeight(), dpw.getVector());
      }
    }
    context.write(new IntWritable(key.get()), new VectorWritable(mdp.getVector()));
  }
View Full Code Here

                              WeightedVectorWritable point,
                              DistanceMeasure measure,
                              Map<Integer, List<VectorWritable>> representativePoints,
                              Map<Integer, WeightedVectorWritable> mostDistantPoints) {
    int key = clusterId.get();
    WeightedVectorWritable currentMDP = mostDistantPoints.get(key);

    List<VectorWritable> repPoints = representativePoints.get(key);
    double totalDistance = 0.0;
    if (repPoints != null) {
      for (VectorWritable refPoint : repPoints) {
        totalDistance += measure.distance(refPoint.get(), point.getVector());
      }
    }
    if (currentMDP == null || currentMDP.getWeight() < totalDistance) {
      mostDistantPoints.put(key, new WeightedVectorWritable(totalDistance, point.getVector().clone()));
    }
  }
View Full Code Here

          ClusterWritable clusterWritable = record.getSecond();
      MeanShiftCanopy canopy = (MeanShiftCanopy) clusterWritable.getValue();
          MeanShiftCanopy closest = MeanShiftCanopyClusterer
              .findCoveringCanopy(canopy, clusters);
          writer.append(new IntWritable(closest.getId()),
              new WeightedVectorWritable(1, canopy.getCenter()));
        }
      } finally {
        Closeables.closeQuietly(writer);
      }
    }
View Full Code Here

    int vectorId = canopy.getId();
    for (MeanShiftCanopy msc : canopies) {
      for (int containedId : msc.getBoundPoints().toList()) {
        if (vectorId == containedId) {
          context.write(new IntWritable(msc.getId()),
                         new WeightedVectorWritable(1, canopy.getCenter()));
        }
      }
    }
  }
View Full Code Here

                              WeightedVectorWritable point,
                              DistanceMeasure measure,
                              Map<Integer, List<VectorWritable>> representativePoints,
                              Map<Integer, WeightedVectorWritable> mostDistantPoints) {
    int key = clusterId.get();
    WeightedVectorWritable currentMDP = mostDistantPoints.get(key);

    List<VectorWritable> repPoints = representativePoints.get(key);
    double totalDistance = 0.0;
    for (VectorWritable refPoint : repPoints) {
      totalDistance += measure.distance(refPoint.get(), point.getVector());
    }
    if (currentMDP == null || currentMDP.getWeight() < totalDistance) {
      mostDistantPoints.put(key, new WeightedVectorWritable(totalDistance, point.getVector().clone()));
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.clustering.classify.WeightedVectorWritable

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.