@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); } }
@Override protected void reduce(Text arg0, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException { for (VectorWritable value : values) { Vector point = value.get(); canopyClusterer.addPointToCanopies(point, canopies); } for (Canopy canopy : canopies) { canopy.computeParameters(); if (canopy.getNumObservations() > clusterFilter) { ClusterWritable clusterWritable = new ClusterWritable(); clusterWritable.setValue(canopy); context.write(new Text(canopy.getIdentifier()), clusterWritable); } } }
@Override protected void reduce(Text arg0, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException { for (VectorWritable value : values) { Vector point = value.get(); canopyClusterer.addPointToCanopies(point, canopies); } for (Canopy canopy : canopies) { canopy.computeParameters(); if (canopy.getNumObservations() > clusterFilter) { ClusterWritable clusterWritable = new ClusterWritable(); clusterWritable.setValue(canopy); context.write(new Text(canopy.getIdentifier()), clusterWritable); } } }
@Override protected void reduce(Text arg0, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException { for (VectorWritable value : values) { Vector point = value.get(); canopyClusterer.addPointToCanopies(point, canopies); } for (Canopy canopy : canopies) { canopy.computeParameters(); if (canopy.getNumObservations() > clusterFilter) { ClusterWritable clusterWritable = new ClusterWritable(); clusterWritable.setValue(canopy); context.write(new Text(canopy.getIdentifier()), clusterWritable); } } }
canopy.getIdentifier(), AbstractCluster.formatVector(canopy.getCenter(), null), canopy.getNumObservations(), AbstractCluster.formatVector(canopy.getRadius(), null)); if (canopy.getNumObservations() > clusterFilter) { clusterWritable.setValue(canopy); writer.append(new Text(canopy.getIdentifier()), clusterWritable);
canopy.getIdentifier(), AbstractCluster.formatVector(canopy.getCenter(), null), canopy.getNumObservations(), AbstractCluster.formatVector(canopy.getRadius(), null)); if (canopy.getNumObservations() > clusterFilter) { clusterWritable.setValue(canopy); writer.append(new Text(canopy.getIdentifier()), clusterWritable);
canopy.getIdentifier(), AbstractCluster.formatVector(canopy.getCenter(), null), canopy.getNumObservations(), AbstractCluster.formatVector(canopy.getRadius(), null)); if (canopy.getNumObservations() > clusterFilter) { clusterWritable.setValue(canopy); writer.append(new Text(canopy.getIdentifier()), clusterWritable);
/** * Story: User can cluster points using a EuclideanDistanceMeasure and a * reference implementation */ @Test public void testReferenceEuclidean() throws Exception { // see setUp for cluster creation printCanopies(referenceEuclidean); assertEquals("number of canopies", 3, referenceEuclidean.size()); int[] expectedNumPoints = { 5, 5, 3 }; double[][] expectedCentroids = { { 1.8, 1.8 }, { 4.2, 4.2 }, { 4.666666666666667, 4.666666666666667 } }; for (int canopyIx = 0; canopyIx < referenceEuclidean.size(); canopyIx++) { Canopy testCanopy = referenceEuclidean.get(canopyIx); assertEquals("canopy points " + canopyIx, testCanopy.getNumObservations(), expectedNumPoints[canopyIx]); double[] refCentroid = expectedCentroids[canopyIx]; Vector testCentroid = testCanopy.computeCentroid(); for (int pointIx = 0; pointIx < refCentroid.length; pointIx++) { assertEquals("canopy centroid " + canopyIx + '[' + pointIx + ']', refCentroid[pointIx], testCentroid.get(pointIx), EPSILON); } } }
/** * Story: User can cluster points using a ManhattanDistanceMeasure and a * reference implementation */ @Test public void testReferenceManhattan() throws Exception { // see setUp for cluster creation printCanopies(referenceManhattan); assertEquals("number of canopies", 3, referenceManhattan.size()); for (int canopyIx = 0; canopyIx < referenceManhattan.size(); canopyIx++) { Canopy testCanopy = referenceManhattan.get(canopyIx); int[] expectedNumPoints = { 4, 4, 3 }; double[][] expectedCentroids = { { 1.5, 1.5 }, { 4.0, 4.0 }, { 4.666666666666667, 4.6666666666666667 } }; assertEquals("canopy points " + canopyIx, testCanopy.getNumObservations(), expectedNumPoints[canopyIx]); double[] refCentroid = expectedCentroids[canopyIx]; Vector testCentroid = testCanopy.computeCentroid(); for (int pointIx = 0; pointIx < refCentroid.length; pointIx++) { assertEquals("canopy centroid " + canopyIx + '[' + pointIx + ']', refCentroid[pointIx], testCentroid.get(pointIx), EPSILON); } } }