Interface KMeans.SizePenalty

Enclosing class:
KMeans
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface KMeans.SizePenalty
Soft size-balancing penalty hook. During the assignment steps of the Lloyd iterations, fit multiplies the value returned by this function by the weight relativeLambda * s, where s is the per-vector objective of the single-cluster fit (see KMeans.fit(java.util.SplittableRandom, com.apple.foundationdb.linear.DistanceEstimator, com.apple.foundationdb.util.Lens<V, com.apple.foundationdb.linear.RealVector>, com.apple.foundationdb.util.Lens<C, com.apple.foundationdb.linear.RealVector>, java.util.List<V>, int, int, int, double, com.apple.foundationdb.kmeans.KMeans.SizePenalty, java.util.function.Predicate<int[]>)), and adds it to the per-pair base objective, biasing the iterations, and with them the centroids, away from oversized clusters. The final, distance-only assignment pass of each run ignores it.

Pass relativeLambda == 0 (or sizePenalty == null) to fit to disable balancing.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    penalty(int projectedSize, int targetSize)
    Implementation of penalty function.
  • Method Details

    • penalty

      double penalty(int projectedSize, int targetSize)
      Implementation of penalty function.
      Parameters:
      projectedSize - the projected size of the candidate cluster after hypothetically assigning the current vector to it
      targetSize - the target cluster size, n / k
      Returns:
      a non-negative penalty; larger values discourage assignment to the cluster