/** * Iterate through the canopies, adding their centroids to a list * * @param canopies * a List<Canopy> * @return the List<Vector> */ public static List<Vector> getCenters(Iterable<Canopy> canopies) { List<Vector> result = Lists.newArrayList(); for (Canopy canopy : canopies) { result.add(canopy.getCenter()); } return result; }
/** * Iterate through the canopies, adding their centroids to a list * * @param canopies * a List<Canopy> * @return the List<Vector> */ public static List<Vector> getCenters(Iterable<Canopy> canopies) { List<Vector> result = Lists.newArrayList(); for (Canopy canopy : canopies) { result.add(canopy.getCenter()); } return result; }
/** * Iterate through the canopies, adding their centroids to a list * * @param canopies * a List<Canopy> * @return the List<Vector> */ public static List<Vector> getCenters(Iterable<Canopy> canopies) { List<Vector> result = Lists.newArrayList(); for (Canopy canopy : canopies) { result.add(canopy.getCenter()); } return result; }
@Override public String toString() { return getIdentifier() + ": " + getCenter().asFormatString(); }
@Override public String toString() { return getIdentifier() + ": " + getCenter().asFormatString(); }
@Override public String toString() { return getIdentifier() + ": " + getCenter().asFormatString(); }
@Override protected void cleanup(Context context) throws IOException, InterruptedException { for (Canopy canopy : canopies) { canopy.computeParameters(); if (canopy.getNumObservations() > clusterFilter) { context.write(new Text("centroid"), new VectorWritable(canopy .getCenter())); } } super.cleanup(context); } }
@Override protected void cleanup(Context context) throws IOException, InterruptedException { for (Canopy canopy : canopies) { canopy.computeParameters(); if (canopy.getNumObservations() > clusterFilter) { context.write(new Text("centroid"), new VectorWritable(canopy .getCenter())); } } super.cleanup(context); } }
@Override protected void cleanup(Context context) throws IOException, InterruptedException { for (Canopy canopy : canopies) { canopy.computeParameters(); if (canopy.getNumObservations() > clusterFilter) { context.write(new Text("centroid"), new VectorWritable(canopy .getCenter())); } } super.cleanup(context); } }
clusters.add(new Kluster(canopy.getCenter(), canopy.getId(), canopy.getMeasure())); } else { throw new IllegalStateException("Bad value class: " + valueClass);
clusters.add(new Kluster(canopy.getCenter(), canopy.getId(), canopy.getMeasure())); } else { throw new IllegalStateException("Bad value class: " + valueClass);
public static void main(String args[]) throws Exception { String inputDir = "reuters"; Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); String vectorsFolder = inputDir + "/tfidf-vectors"; SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(vectorsFolder + "/part-r-00000"), conf); List<Vector> points = new ArrayList<Vector>(); Text key = new Text(); VectorWritable value = new VectorWritable(); while (reader.next(key, value)) { points.add(value.get()); } System.out.println(points.size()); reader.close(); List<Canopy> canopies = CanopyClusterer.createCanopies(points, new CosineDistanceMeasure(), 0.8, 0.7); List<Cluster> clusters = new ArrayList<Cluster>(); System.out.println(canopies.size()); for (Canopy canopy : canopies) { clusters.add(new Cluster(canopy.getCenter(), canopy.getId(), new CosineDistanceMeasure())); } } }
public static void main(String[] args) { List<Vector> sampleData = new ArrayList<Vector>(); RandomPointsUtil.generateSamples(sampleData, 400, 1, 1, 2); RandomPointsUtil.generateSamples(sampleData, 300, 1, 0, 0.5); RandomPointsUtil.generateSamples(sampleData, 300, 0, 2, 0.1); List<Canopy> canopies = CanopyClusterer.createCanopies(sampleData, new EuclideanDistanceMeasure(), 3.0, 1.5); for (Canopy canopy : canopies) { System.out.println("Canopy id: " + canopy.getId() + " center: " + canopy.getCenter().asFormatString()); } } }
System.out.println(canopies.size()); for (Canopy canopy : canopies) { clusters.add(new Cluster(canopy.getCenter(), canopy.getId(), new CosineDistanceMeasure()));