Record Class PartitionEvaluator.Partition<V>

java.lang.Object
java.lang.Record
com.apple.foundationdb.kmeans.PartitionEvaluator.Partition<V>
Type Parameters:
V - the type of the centroid representation
Record Components:
centroids - the cluster centroids (one per cluster, size determines k)
vectorLens - lens for extracting a RealVector from a centroid of type V
assignments - per-vector cluster assignment; assignments[i] is the centroid index for the i-th vector in the corresponding vector list
Enclosing class:
PartitionEvaluator

public static record PartitionEvaluator.Partition<V>(@Nonnull List<V> centroids, @Nonnull Lens<V,RealVector> vectorLens, @Nonnull int[] assignments) extends Record
Represents a partitioning of a set of vectors into k clusters, as passed to PartitionEvaluator.evaluate(java.util.List<V>, com.apple.foundationdb.kmeans.PartitionEvaluator.Partition<?>, java.util.List<V>, com.apple.foundationdb.kmeans.PartitionEvaluator.Partition<?>, com.apple.foundationdb.util.Lens<V, com.apple.foundationdb.linear.RealVector>, com.apple.foundationdb.kmeans.PartitionEvaluator.Parameters). Each vector is assigned to exactly one centroid via the assignments array, where assignments[i] is the index into centroids that owns vectors.get(i).
  • Constructor Details

    • Partition

      public Partition(@Nonnull List<V> centroids, @Nonnull Lens<V,RealVector> vectorLens, @Nonnull int[] assignments)
      Creates an instance of a Partition record class.
      Parameters:
      centroids - the value for the centroids record component
      vectorLens - the value for the vectorLens record component
      assignments - the value for the assignments record component
  • Method Details

    • getCentroid

      @Nonnull public RealVector getCentroid(int index)
      Returns the centroid at the given cluster index as a RealVector, dereferenced through vectorLens.
      Parameters:
      index - cluster index in [0, k())
      Returns:
      the centroid as a RealVector; never null
    • getAssignment

      public int getAssignment(int index)
      Returns the cluster index assigned to the index-th vector in the corresponding point list.
      Parameters:
      index - vector index into the corresponding point list
      Returns:
      the cluster index assigned to the vector at index
    • k

      public int k()
      Returns the number of clusters in this partitioning, i.e. centroids.size().
      Returns:
      the number of centroids k in this partition.
    • equals

      public boolean equals(Object o)
      Custom equality: the auto-generated record equals would compare vectorLens as well as assignments by reference. This implementation ignores the lens and compares the arrays element-wise via Arrays.equals(int[], int[]) and the other components via Objects.equals(Object, Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the other object to compare this object to
      Returns:
      indicator whether this partition is equal to the object o passed in
    • hashCode

      public int hashCode()
      Custom hash code consistent with equals(java.lang.Object). Ignores vectorLens and uses element-wise hashing of the assignments array.
      Specified by:
      hashCode in class Record
      Returns:
      the hash code of this partition
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • centroids

      @Nonnull public List<V> centroids()
      Returns the value of the centroids record component.
      Returns:
      the value of the centroids record component
    • vectorLens

      @Nonnull public Lens<V,RealVector> vectorLens()
      Returns the value of the vectorLens record component.
      Returns:
      the value of the vectorLens record component
    • assignments

      @Nonnull public int[] assignments()
      Returns the value of the assignments record component.
      Returns:
      the value of the assignments record component