Class GeneralisedKMeans<T>

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

public final class GeneralisedKMeans<T> extends Object implements ClusteringAlgorithm<T>
Contains the outline of the k-means algorithm, but designed for customisation.
  • Works with any type of data
  • Allows for custom distance calculations
  • Allows for custom centroid initialisation and updating
  • Field Details

  • Constructor Details

    • GeneralisedKMeans

      public GeneralisedKMeans(Function<Collection<T>, List<T>> centroidInitialiser, Function<Collection<T>, T> centroidUpdater, ToDoubleBiFunction<T,T> distanceCalculator)
      You have to configure how distances are measured and how centroids are derived.
      Parameters:
      centroidInitialiser - The initialisation function should return a list of k centroids. This function determines 'K'.
      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.
  • 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.