Package com.apple.foundationdb.kmeans
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 determinesk)vectorLens- lens for extracting aRealVectorfrom a centroid of typeVassignments- 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]Returns the value of theassignmentsrecord component.Returns the value of thecentroidsrecord component.booleanCustom equality: the auto-generated recordequalswould comparevectorLensas well asassignmentsby reference.intgetAssignment(int index) Returns the cluster index assigned to theindex-th vector in the corresponding point list.getCentroid(int index) Returns the centroid at the given cluster index as aRealVector, dereferenced throughvectorLens.inthashCode()Custom hash code consistent withequals(java.lang.Object).intk()Returns the number of clusters in this partitioning, i.e.final StringtoString()Returns a string representation of this record class.Returns the value of thevectorLensrecord component.
-
Constructor Details
-
Partition
public Partition(@Nonnull List<V> centroids, @Nonnull Lens<V, RealVector> vectorLens, @Nonnull int[] assignments) Creates an instance of aPartitionrecord class.- Parameters:
centroids- the value for thecentroidsrecord componentvectorLens- the value for thevectorLensrecord componentassignments- the value for theassignmentsrecord component
-
-
Method Details
-
getCentroid
Returns the centroid at the given cluster index as aRealVector, dereferenced throughvectorLens.- Parameters:
index- cluster index in[0, k())- Returns:
- the centroid as a
RealVector; nevernull
-
getAssignment
public int getAssignment(int index) Returns the cluster index assigned to theindex-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
kin this partition.
-
equals
Custom equality: the auto-generated recordequalswould comparevectorLensas well asassignmentsby reference. This implementation ignores the lens and compares the arrays element-wise viaArrays.equals(int[], int[])and the other components viaObjects.equals(Object, Object). -
hashCode
public int hashCode()Custom hash code consistent withequals(java.lang.Object). IgnoresvectorLensand uses element-wise hashing of theassignmentsarray. -
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. -
centroids
Returns the value of thecentroidsrecord component.- Returns:
- the value of the
centroidsrecord component
-
vectorLens
Returns the value of thevectorLensrecord component.- Returns:
- the value of the
vectorLensrecord component
-
assignments
@Nonnull public int[] assignments()Returns the value of theassignmentsrecord component.- Returns:
- the value of the
assignmentsrecord component
-