Home | History | Annotate | Download | only in clustering

Lines Matching refs:Cluster

31  * @param <T> type of the points to cluster
38 /** Strategies to use for replacing an empty cluster. */
41 /** Split the cluster with largest distance variance. */
44 /** Split the cluster with largest number of points. */
47 /** Create a cluster around the point farthest from its centroid. */
64 * algorithm iterations is to split the cluster with largest distance variance.
86 * @param points the points to cluster
92 public List<Cluster<T>> cluster(final Collection<T> points,
95 List<Cluster<T>> clusters = chooseInitialCenters(points, k, random);
102 List<Cluster<T>> newClusters = new ArrayList<Cluster<T>>();
103 for (final Cluster<T> cluster : clusters) {
105 if (cluster.getPoints().isEmpty()) {
121 newCenter = cluster.getCenter().centroidOf(cluster.getPoints());
122 if (!newCenter.equals(cluster.getCenter())) {
126 newClusters.add(new Cluster<T>(newCenter));
138 * Adds the given points to the closest {@link Cluster}.
140 * @param <T> type of the points to cluster
141 * @param clusters the {@link Cluster}s to add the points to
142 * @param points the points to add to the given {@link Cluster}s
145 assignPointsToClusters(final Collection<Cluster<T>> clusters, final Collection<T> points) {
147 Cluster<T> cluster = getNearestCluster(clusters, p);
148 cluster.addPoint(p);
155 * @param <T> type of the points to cluster
161 private static <T extends Clusterable<T>> List<Cluster<T>>
165 final List<Cluster<T>> resultSet = new ArrayList<Cluster<T>>();
169 resultSet.add(new Cluster<T>(firstPoint));
178 final Cluster<T> nearest = getNearestCluster(resultSet, p);
190 resultSet.add(new Cluster<T>(p));
201 * Get a random point from the {@link Cluster} with the largest distance variance.
203 * @param clusters the {@link Cluster}s to search
204 * @return a random point from the selected cluster
206 private T getPointFromLargestVarianceCluster(final Collection<Cluster<T>> clusters) {
209 Cluster<T> selected = null;
210 for (final Cluster<T> cluster : clusters) {
211 if (!cluster.getPoints().isEmpty()) {
213 // compute the distance variance of the current cluster
214 final T center = cluster.getCenter();
216 for (final T point : cluster.getPoints()) {
221 // select the cluster with the largest variance
224 selected = cluster;
230 // did we find at least one non-empty cluster ?
235 // extract a random point from the cluster
242 * Get a random point from the {@link Cluster} with the largest number of points
244 * @param clusters the {@link Cluster}s to search
245 * @return a random point from the selected cluster
247 private T getPointFromLargestNumberCluster(final Collection<Cluster<T>> clusters) {
250 Cluster<T> selected = null;
251 for (final Cluster<T> cluster : clusters) {
253 // get the number of points of the current cluster
254 final int number = cluster.getPoints().size();
256 // select the cluster with the largest number of points
259 selected = cluster;
264 // did we find at least one non-empty cluster ?
269 // extract a random point from the cluster
276 * Get the point farthest to its cluster center
278 * @param clusters the {@link Cluster}s to search
279 * @return point farthest to its cluster center
281 private T getFarthestPoint(final Collection<Cluster<T>> clusters) {
284 Cluster<T> selectedCluster = null;
286 for (final Cluster<T> cluster : clusters) {
289 final T center = cluster.getCenter();
290 final List<T> points = cluster.getPoints();
295 selectedCluster = cluster;
302 // did we find at least one non-empty cluster ?
312 * Returns the nearest {@link Cluster} to the given point
314 * @param <T> type of the points to cluster
315 * @param clusters the {@link Cluster}s to search
316 * @param point the point to find the nearest {@link Cluster} for
317 * @return the nearest {@link Cluster} to the given point
319 private static <T extends Clusterable<T>> Cluster<T>
320 getNearestCluster(final Collection<Cluster<T>> clusters, final T point) {
322 Cluster<T> minCluster = null;
323 for (final Cluster<T> c : clusters) {