- java.lang.Object
-
- org.ojalgo.data.cluster.GreedyClustering<T>
-
- All Implemented Interfaces:
ClusteringAlgorithm<T>
public final class GreedyClustering<T> extends java.lang.Object implements ClusteringAlgorithm<T>
Greedy clustering algorithm. Assigns each item to the nearest centroid, creating new centroids as needed. Will only pass through the data once. The centroids are recalculated as the clusters are updated (not with every single update, but continuously during the process).
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<T>myCentroidsprivate java.util.function.Function<java.util.Collection<T>,T>myCentroidUpdaterprivate java.util.function.ToDoubleBiFunction<T,T>myDistanceCalculatorprivate doublemyDistanceThresholdprivate java.util.List<java.util.concurrent.atomic.AtomicInteger>myUpdates
-
Constructor Summary
Constructors Constructor Description GreedyClustering(java.util.function.Function<java.util.Collection<T>,T> centroidUpdater, java.util.function.ToDoubleBiFunction<T,T> distanceCalculator, double distanceThreshold)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.util.Set<T>>cluster(java.util.Collection<T> input)Partitions the given items into clusters.(package private) java.util.List<T>getCentroids()
-
-
-
Field Detail
-
myCentroids
private final java.util.List<T> myCentroids
-
myUpdates
private final java.util.List<java.util.concurrent.atomic.AtomicInteger> myUpdates
-
myCentroidUpdater
private final java.util.function.Function<java.util.Collection<T>,T> myCentroidUpdater
-
myDistanceThreshold
private final double myDistanceThreshold
-
-
Constructor Detail
-
GreedyClustering
public GreedyClustering(java.util.function.Function<java.util.Collection<T>,T> centroidUpdater, java.util.function.ToDoubleBiFunction<T,T> distanceCalculator, double distanceThreshold)
- Parameters:
centroidUpdater- The update function should return a new centroid based on a collection of points (the set of items in a cluster).distanceCalculator- A function that calculates the distance between two points.distanceThreshold- The maximum distance between a point and a centroid for the point to be assigned to that cluster. The points are always assigned to the cluster of the nearest centroid among the already existing clusters. This threshold determines when a new cluster should be created.
-
-
Method Detail
-
cluster
public java.util.List<java.util.Set<T>> cluster(java.util.Collection<T> input)
Description copied from interface:ClusteringAlgorithmPartitions the given items into clusters.- Specified by:
clusterin interfaceClusteringAlgorithm<T>- Parameters:
input- The items to cluster; must not benull. May be empty.- Returns:
- A list of clusters; each element of the list is a
Set<T>representing one cluster and containing its members. Sets are non-empty and pairwise disjoint; ordering is unspecified.
-
getCentroids
java.util.List<T> getCentroids()
-
-