- All Implemented Interfaces:
ClusteringAlgorithm<Point>
Provides utilities to cluster arbitrary data by mapping items to Points (immutable float[] feature
vectors).
Usage: Use cluster(Collection, Function) to cluster your own data by providing an extractor
that produces the feature vector for each item. The result is a list of clusters, each represented as a
Map<T, float[]> containing the original items and their extracted features.
Available clustering algorithms:
newAutomatic(DistanceMeasure): Automatic clustering that determines the number of clusters and thresholds based on distance statistics.newGreedy(DistanceMeasure, double): Greedy, single-pass clustering using a distance threshold.newKMeans(DistanceMeasure, int): K-means style clustering with a specified number of clusters.newSpectral(DistanceMeasure, int): Spectral clustering using a Gaussian kernel and Laplacian embedding.
Performance: Internally, distances are cached for efficiency. All clustering is performed on
Point objects with unique ids and float[] coordinates.
Extensibility: Subclasses implement ClusteringAlgorithm.cluster(Collection) to provide concrete clustering
strategies over Points.
Thread safety: Not thread-safe. Each instance maintains internal state for distance caching.
- Author:
- apete
-
Method Summary
Modifier and TypeMethodDescriptioncluster(Collection<T> input, Function<T, float[]> extractor) Clusters arbitrary items by first extracting their float feature representation.static FeatureBasedClustererReturns a new automatic clusterer using squared Euclidean distance.static FeatureBasedClusterernewAutomatic(DistanceMeasure measure) Returns a new automatic clusterer using the specified distance measure.static FeatureBasedClusterernewGreedy(double threshold) Returns a new greedy, single-pass clusterer using squared Euclidean distance and the given threshold.static FeatureBasedClusterernewGreedy(DistanceMeasure measure, double threshold) Returns a new greedy, single-pass clusterer using the supplied distance and threshold.static FeatureBasedClusterernewKMeans(int k) Returns a new k-means–style clusterer using squared Euclidean distance and the given number of clusters.static FeatureBasedClusterernewKMeans(DistanceMeasure measure, int k) Returns a new k-means–style clusterer using the supplied distance measure and number of clusters.static FeatureBasedClusterernewSpectral(int k) Returns a new spectral clusterer using squared Euclidean distance and the given number of clusters.static FeatureBasedClusterernewSpectral(DistanceMeasure measure, int k) Returns a new spectral clusterer using the supplied distance measure and number of clusters.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.ojalgo.data.cluster.ClusteringAlgorithm
cluster
-
Method Details
-
newAutomatic
Returns a new automatic clusterer using squared Euclidean distance. Equivalent tonewAutomatic(DistanceMeasure)withDistanceMeasure.SQUARED_EUCLIDEAN.- Returns:
- a new automatic clusterer
-
newAutomatic
Returns a new automatic clusterer using the specified distance measure.The algorithm:
- Extracts features
- Caches all pairwise distances
- Performs statistical analysis to determine a distance threshold
- Performs greedy clustering to get initial centroids
- Filters out very small clusters (determining k)
- Performs k-means clustering to refine clusters and centroids
- Parameters:
measure- the distance measure to use- Returns:
- a new automatic clusterer
-
newGreedy
Returns a new greedy, single-pass clusterer using the supplied distance and threshold.Each item is assigned to the nearest existing centroid if its distance is
<= threshold; otherwise a new cluster is created. The threshold must be in the same units as the chosen distance measure.- Parameters:
measure- the distance measurethreshold- the maximum allowed distance to join an existing cluster- Returns:
- a new greedy clusterer
-
newGreedy
Returns a new greedy, single-pass clusterer using squared Euclidean distance and the given threshold.- Parameters:
threshold- the maximum allowed distance to join an existing cluster- Returns:
- a new greedy clusterer
-
newKMeans
Returns a new k-means–style clusterer using the supplied distance measure and number of clusters.- Parameters:
measure- the distance functionk- the number of clusters (k >= 1)- Returns:
- a new k-means clusterer
-
newKMeans
Returns a new k-means–style clusterer using squared Euclidean distance and the given number of clusters.- Parameters:
k- the number of clusters (k >= 1)- Returns:
- a new k-means clusterer
-
newSpectral
Returns a new spectral clusterer using the supplied distance measure and number of clusters.Uses a Gaussian kernel and the symmetric normalised Laplacian.
- Parameters:
measure- the distance measure for the kernelk- the number of clusters (k >= 1)- Returns:
- a new spectral clusterer
-
newSpectral
Returns a new spectral clusterer using squared Euclidean distance and the given number of clusters.- Parameters:
k- the number of clusters (k >= 1)- Returns:
- a new spectral clusterer
-
cluster
Clusters arbitrary items by first extracting their float feature representation.Each item is wrapped as a
Pointusing the extractor output. Clustering is then performed byClusteringAlgorithm.cluster(Collection). The result mirrors the internal clusters but maps back to the original items along with their feature vectors.- Type Parameters:
T- the item type- Parameters:
input- the items to cluster (not null)extractor- a function that returns a non-null float[] feature vector for an item- Returns:
- a list of clusters, each as a map from the original item to its feature vector, sorted by decreasing size
-