org.ddogleg.clustering.kmeans
Class AssignKMeans_F64
- java.lang.Object
-
- org.ddogleg.clustering.kmeans.AssignKMeans_F64
-
- All Implemented Interfaces:
- java.io.Serializable, AssignCluster<double[]>
public class AssignKMeans_F64 extends java.lang.Object implements AssignCluster<double[]>
Implementation ofAssignClusterfor K-Means. Euclidean distance squared is used to select the best fit clusters to a point. This distance metric works well for hard assignment but can produce undesirable results for soft assignment, see JavaDoc.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description AssignKMeans_F64(AssignKMeans_F64 original)AssignKMeans_F64(java.util.List<double[]> clusters)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intassign(double[] point)Assigns the point to cluster which is the best fit.voidassign(double[] point, double[] fit)Soft assignment is done by summing the total distance of the point from each cluster.AssignCluster<double[]>copy()Creates an exact copy of this class.java.util.List<double[]>getClusters()intgetNumberOfClusters()Total number of clusters.voidsetClusters(java.util.List<double[]> clusters)
-
-
-
Constructor Detail
-
AssignKMeans_F64
public AssignKMeans_F64(java.util.List<double[]> clusters)
-
AssignKMeans_F64
public AssignKMeans_F64(AssignKMeans_F64 original)
-
-
Method Detail
-
assign
public int assign(double[] point)
Description copied from interface:AssignClusterAssigns the point to cluster which is the best fit.- Specified by:
assignin interfaceAssignCluster<double[]>- Parameters:
point- Point which is to be assigned- Returns:
- Index of the cluster from 0 to N-1
-
assign
public void assign(double[] point, double[] fit)Soft assignment is done by summing the total distance of the point from each cluster. Then for each cluster its value is set to total minus its distance. The output array is then normalized by dividing each element by the sum.
When all clusters are approximately the same distance or one is clearly the closest this produces reasonable results. When multiple clusters are much closer than at least on other cluster then it effectively ignores the relative difference in distances between the closest points. There are several obvious heuristic "fixes" to this issue, but the best way to solve it is to simply use
AssignGmm_F64instead.- Specified by:
assignin interfaceAssignCluster<double[]>- Parameters:
point- Point which is to be assignedfit- Storage for relative fit quality of each cluster. Length must be at least the number of clusters.
-
getNumberOfClusters
public int getNumberOfClusters()
Description copied from interface:AssignClusterTotal number of clusters.- Specified by:
getNumberOfClustersin interfaceAssignCluster<double[]>- Returns:
- The total number of clusters.
-
copy
public AssignCluster<double[]> copy()
Description copied from interface:AssignClusterCreates an exact copy of this class.- Specified by:
copyin interfaceAssignCluster<double[]>- Returns:
- Copy of class
-
getClusters
public java.util.List<double[]> getClusters()
-
setClusters
public void setClusters(java.util.List<double[]> clusters)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG