Record Class KMeans.Result<C>

java.lang.Object
java.lang.Record
com.apple.foundationdb.kmeans.KMeans.Result<C>
Type Parameters:
C - caller's centroid representation
Record Components:
clusterCentroids - the k cluster centroids in cluster-index order; defensively copied into an immutable list at construction time
clusterSizes - per-cluster size array of length k; entry c is the number of input vectors assigned to cluster c. Ownership transferred to the record
assignment - per-vector cluster assignment; entry i is the index of the cluster that vectors.get(i) was assigned to. Ownership transferred to the record
distances - per-vector contribution to the geometric objective: squared L2 distance to the assigned centroid in Euclidean mode, cosine distance in cosine mode. Ownership transferred to the record
objective - sum of distances — the geometric SSE in Euclidean mode, or the sum of cosine distances in cosine mode. The size-balance penalty is intentionally excluded so restarts can be compared on the geometric objective alone
Enclosing class:
KMeans

public static record KMeans.Result<C>(@Nonnull List<C> clusterCentroids, @Nonnull int[] clusterSizes, @Nonnull int[] assignment, @Nonnull double[] distances, double objective) extends Record
Outcome of a fit call: the chosen centroids, the per-vector cluster assignment, the per-cluster sizes, the per-vector objective contributions, and the total objective. All components are mutually consistent — i.e. for every i, distances[i] == baseObjective(vectors[i], clusterCentroids[assignment[i]]), and clusterSizes[c] == count(j: assignment[j] == c).

The compact constructor defensively copies clusterCentroids into an immutable list. The three primitive arrays are not copied — the caller transfers ownership to the record, and accessors return the underlying array references directly.

  • Constructor Details

    • Result

      public Result(@Nonnull List<C> clusterCentroids, @Nonnull int[] clusterSizes, @Nonnull int[] assignment, @Nonnull double[] distances, double objective)
      Creates an instance of a Result record class.
      Parameters:
      clusterCentroids - the value for the clusterCentroids record component
      clusterSizes - the value for the clusterSizes record component
      assignment - the value for the assignment record component
      distances - the value for the distances record component
      objective - the value for the objective record component
  • Method Details

    • 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
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • clusterCentroids

      @Nonnull public List<C> clusterCentroids()
      Returns the value of the clusterCentroids record component.
      Returns:
      the value of the clusterCentroids record component
    • clusterSizes

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

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

      @Nonnull public double[] distances()
      Returns the value of the distances record component.
      Returns:
      the value of the distances record component
    • objective

      public double objective()
      Returns the value of the objective record component.
      Returns:
      the value of the objective record component