@Test public void testKernels() { ThreadedContext random = new ThreadedContext(123, 4); Pair<List<Clusterable>, List<Integer>> blobs = makeBlobs(1000, of(new ClusterablePoint(1, 1), new ClusterablePoint(-1, -1), new ClusterablePoint(1, -1)), 0.6, true, random.getRandomForThread()); double bandwidth = MeanShiftUtils.estimateBandwidth(blobs.first(), 0.2, 100, random.getRandomForThread()); assertEquals(0.9445823374425488, bandwidth, EPS); MeanShift<Clusterable> flatShift = new MeanShift<>(new FlatKernel(), new EuclideanDistance(), bandwidth); MeanShift<Clusterable> gaussShift = new MeanShift<>(new GaussianKernel(), new EuclideanDistance(), bandwidth); List<CentroidCluster<Clusterable>> flatClusters = flatShift.cluster(blobs.first(), random); List<CentroidCluster<Clusterable>> gaussClusters = gaussShift.cluster(blobs.first(), random); assertEquals(3, flatClusters.size()); assertEquals(341, flatClusters.get(0).getPoints().size()); assertEquals(326, flatClusters.get(1).getPoints().size()); assertEquals(334, flatClusters.get(2).getPoints().size()); assertEquals(3, gaussClusters.size()); assertEquals(339, gaussClusters.get(0).getPoints().size()); assertEquals(330, gaussClusters.get(1).getPoints().size()); assertEquals(332, gaussClusters.get(2).getPoints().size()); }
@Override public List<CentroidCluster<T>> cluster(Collection<T> points, ThreadedContext context) { final List<ClusterableVector> vectors = pointsToVectors(points); final double bandwidth = getBandwidth(vectors, context.getRandomForThread()); final NearestNeighbors<ClusterableVector> nbrs = new NearestNeighbors<>(vectors, metric); final Map<ClusterableVector, Integer> densities = new ConcurrentHashMap<>(); context.submit(new ThreadedContext.Worker<ClusterableVector, Void>() { @Override public Void process(ClusterableVector seed, ThreadedContext context) throws Exception { meanShift(bandwidth, nbrs, densities, seed); return null; } }, initSeeds.getSeeds(vectors, bandwidth, context.getRandomForThread())); Set<ClusterableVector> clusterCenters = mergeClusters(bandwidth, densities); return getCentroidClusters(points, clusterCenters); }
MeanShift implements Clusterer<T> { @Override public List<CentroidCluster<T>> cluster(Collection<T> points, ThreadedContext context) { final List<ClusterableVector> vectors = pointsToVectors(points); final double bandwidth = getBandwidth(vectors, context.getRandomForThread()); final NearestNeighbors<ClusterableVector> nbrs = new NearestNeighbors<>(vectors, metric); final Map<ClusterableVector, Integer> densities = new ConcurrentHashMap<>(); context.submit(new ThreadedContext.Worker<ClusterableVector, Void>() { @Override public Void process(ClusterableVector seed, ThreadedContext context) throws Exception { meanShift(bandwidth, nbrs, densities, seed); return null; } }, initSeeds.getSeeds(vectors, bandwidth, context.getRandomForThread())); Set<ClusterableVector> clusterCenters = mergeClusters(bandwidth, densities); return getCentroidClusters(points, clusterCenters); } }
MeanShift implements Clusterer<T> { @Override public List<CentroidCluster<T>> cluster(Collection<T> points, ThreadedContext context) { final List<ClusterableVector> vectors = pointsToVectors(points); final double bandwidth = getBandwidth(vectors, context.getRandomForThread()); final NearestNeighbors<ClusterableVector> nbrs = new NearestNeighbors<>(vectors, metric); final Map<ClusterableVector, Integer> densities = new ConcurrentHashMap<>(); context.submit(new ThreadedContext.Worker<ClusterableVector, Void>() { @Override public Void process(ClusterableVector seed, ThreadedContext context) throws Exception { meanShift(bandwidth, nbrs, densities, seed); return null; } }, initSeeds.getSeeds(vectors, bandwidth, context.getRandomForThread())); Set<ClusterableVector> clusterCenters = mergeClusters(bandwidth, densities); return getCentroidClusters(points, clusterCenters); } MeanShift(Kernel kernel, DistanceMetric metric);  MeanShift(Kernel kernel, DistanceMetric metric, SeedingStrategy seed);  MeanShift(Kernel kernel, DistanceMetric metric, double window);  MeanShift(Kernel kernel, DistanceMetric metric, int iterations);  MeanShift(Kernel kernel, DistanceMetric metric, double window, int iterations, SeedingStrategy initSeeds); }
MeanShift implements Clusterer<T> { @Override public List<CentroidCluster<T>> cluster(Collection<T> points, ThreadedContext context) { final List<ClusterableVector> vectors = pointsToVectors(points); final double bandwidth = getBandwidth(vectors, context.getRandomForThread()); final NearestNeighbors<ClusterableVector> nbrs = new NearestNeighbors<>(vectors, metric); final Map<ClusterableVector, Integer> densities = new ConcurrentHashMap<>(); context.submit(new ThreadedContext.Worker<ClusterableVector, Void>() { @Override public Void process(ClusterableVector seed, ThreadedContext context) throws Exception { meanShift(bandwidth, nbrs, densities, seed); return null; } }, initSeeds.getSeeds(vectors, bandwidth, context.getRandomForThread())); Set<ClusterableVector> clusterCenters = mergeClusters(bandwidth, densities); return getCentroidClusters(points, clusterCenters); } MeanShift(Kernel kernel, DistanceMetric metric);  MeanShift(Kernel kernel, DistanceMetric metric, SeedingStrategy seed);  MeanShift(Kernel kernel, DistanceMetric metric, double window);  MeanShift(Kernel kernel, DistanceMetric metric, int iterations);  MeanShift(Kernel kernel, DistanceMetric metric, double window, int iterations, SeedingStrategy initSeeds); @Override List<CentroidCluster<T>> cluster(Collection<T> points, ThreadedContext context); }
MeanShift implements Clusterer<T> { @Override public List<CentroidCluster<T>> cluster(Collection<T> points, ThreadedContext context) { final List<ClusterableVector> vectors = pointsToVectors(points); final double bandwidth = getBandwidth(vectors, context.getRandomForThread()); final NearestNeighbors<ClusterableVector> nbrs = new NearestNeighbors<>(vectors, metric); final Map<ClusterableVector, Integer> densities = new ConcurrentHashMap<>(); context.submit(new ThreadedContext.Worker<ClusterableVector, Void>() { @Override public Void process(ClusterableVector seed, ThreadedContext context) throws Exception { meanShift(bandwidth, nbrs, densities, seed); return null; } }, initSeeds.getSeeds(vectors, bandwidth, context.getRandomForThread())); Set<ClusterableVector> clusterCenters = mergeClusters(bandwidth, densities); return getCentroidClusters(points, clusterCenters); } MeanShift(Kernel kernel, DistanceMetric metric);  MeanShift(Kernel kernel, DistanceMetric metric, SeedingStrategy seed);  MeanShift(Kernel kernel, DistanceMetric metric, double window);  MeanShift(Kernel kernel, DistanceMetric metric, int iterations);  MeanShift(Kernel kernel, DistanceMetric metric, double window, int iterations, SeedingStrategy initSeeds); @Override List<CentroidCluster<T>> cluster(Collection<T> points, ThreadedContext context);  }