Package com.apple.foundationdb.kmeans
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- thekcluster centroids in cluster-index order; defensively copied into an immutable list at construction timeclusterSizes- per-cluster size array of lengthk; entrycis the number of input vectors assigned to clusterc. Ownership transferred to the recordassignment- per-vector cluster assignment; entryiis the index of the cluster thatvectors.get(i)was assigned to. Ownership transferred to the recorddistances- 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 recordobjective- sum ofdistances— 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]Returns the value of theassignmentrecord component.Returns the value of theclusterCentroidsrecord component.int[]Returns the value of theclusterSizesrecord component.double[]Returns the value of thedistancesrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doubleReturns the value of theobjectiverecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Result
public Result(@Nonnull List<C> clusterCentroids, @Nonnull int[] clusterSizes, @Nonnull int[] assignment, @Nonnull double[] distances, double objective) Creates an instance of aResultrecord class.- Parameters:
clusterCentroids- the value for theclusterCentroidsrecord componentclusterSizes- the value for theclusterSizesrecord componentassignment- the value for theassignmentrecord componentdistances- the value for thedistancesrecord componentobjective- the value for theobjectiverecord component
-
-
Method Details
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
clusterCentroids
Returns the value of theclusterCentroidsrecord component.- Returns:
- the value of the
clusterCentroidsrecord component
-
clusterSizes
@Nonnull public int[] clusterSizes()Returns the value of theclusterSizesrecord component.- Returns:
- the value of the
clusterSizesrecord component
-
assignment
@Nonnull public int[] assignment()Returns the value of theassignmentrecord component.- Returns:
- the value of the
assignmentrecord component
-
distances
@Nonnull public double[] distances()Returns the value of thedistancesrecord component.- Returns:
- the value of the
distancesrecord component
-
objective
public double objective()Returns the value of theobjectiverecord component.- Returns:
- the value of the
objectiverecord component
-