Class GreedyClustering<T>

java.lang.Object
org.ojalgo.data.cluster.GreedyClustering<T>
All Implemented Interfaces:
ClusteringAlgorithm<T>

public final class GreedyClustering<T> extends 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 Details

    • myCentroids

      private final List<T> myCentroids
    • myUpdates

      private final List<AtomicInteger> myUpdates
    • myCentroidUpdater

      private final Function<Collection<T>, T> myCentroidUpdater
    • myDistanceCalculator

      private final ToDoubleBiFunction<T,T> myDistanceCalculator
    • myDistanceThreshold

      private final double myDistanceThreshold
  • Constructor Details

    • GreedyClustering

      public GreedyClustering(Function<Collection<T>, T> centroidUpdater, 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 Details

    • cluster

      public List<Set<T>> cluster(Collection<T> input)
      Description copied from interface: ClusteringAlgorithm
      Partitions the given items into clusters.
      Specified by:
      cluster in interface ClusteringAlgorithm<T>
      Parameters:
      input - The items to cluster; must not be null. 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

      List<T> getCentroids()