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()); } } }
reader.close(); List<Canopy> canopies = CanopyClusterer.createCanopies(points, new CosineDistanceMeasure(), 0.7, 0.5); List<Cluster> clusters = new ArrayList<Cluster>(); System.out.println(canopies.size());
@Override @Before public void setUp() throws Exception { super.setUp(); fs = FileSystem.get(getConfiguration()); referenceManhattan = CanopyClusterer.createCanopies(getPoints(), manhattanDistanceMeasure, 3.1, 2.1); manhattanCentroids = CanopyClusterer.getCenters(referenceManhattan); referenceEuclidean = CanopyClusterer.createCanopies(getPoints(), euclideanDistanceMeasure, 3.1, 2.1); euclideanCentroids = CanopyClusterer.getCenters(referenceEuclidean); }