List of usage examples for org.apache.commons.math3.ml.clustering Cluster Cluster
public Cluster()
From source file:com.yahoo.egads.utilities.DBSCANClusterer.java
/** * Performs DBSCAN cluster analysis./*w ww. ja v a 2s . co m*/ * * @param points the points to cluster * @return the list of clusters * @throws NullArgumentException if the data points are null */ public List<Cluster<T>> cluster(final Collection<T> points) throws NullArgumentException { // sanity checks MathUtils.checkNotNull(points); final List<Cluster<T>> clusters = new ArrayList<Cluster<T>>(); final List<Cluster<T>> anomalousClusters = new ArrayList<Cluster<T>>(); final Cluster<T> anomalyCluster = new Cluster<T>(); final Map<Clusterable, PointStatus> visited = new HashMap<Clusterable, PointStatus>(); for (final T point : points) { if (visited.get(point) != null) { continue; } final List<T> neighbors = getNeighbors(point, points); if (neighbors.size() >= minPts) { // DBSCAN does not care about center points final Cluster<T> cluster = new Cluster<T>(); clusters.add(expandCluster(cluster, point, neighbors, points, visited)); } else { visited.put(point, PointStatus.NOISE); anomalyCluster.addPoint(point); } } anomalousClusters.add(anomalyCluster); return anomalousClusters; }
From source file:utils.DBSCAN.TrajDbscan.java
/** * Performs DBSCAN cluster analysis./*w ww . j a v a2 s. co m*/ * * @param points the points to cluster * @return the list of clusters * @throws NullArgumentException if the data points are null */ @Override public List<Cluster<T>> cluster(final Collection<T> points) throws NullArgumentException { // sanity checks MathUtils.checkNotNull(points); final List<Cluster<T>> clusters = new ArrayList<Cluster<T>>(); final Map<Clusterable, PointStatus> visited = new HashMap<Clusterable, PointStatus>(); for (final T point : points) { if (visited.get(point) != null) { continue; } final List<T> neighbors = getNeighbors(point, points); if (neighbors.size() >= minPts) { // DBSCAN does not care about center points final Cluster<T> cluster = new Cluster<T>(); clusters.add(expandCluster(cluster, point, neighbors, points, visited)); } else { visited.put(point, PointStatus.NOISE); } } return clusters; }