Class KMeans
java.lang.Object
es.uam.eps.ir.relison.sna.community.clustering.KMeans
public class KMeans
extends java.lang.Object
Implementation of the k-means clustering algorithm.
Reference: D. MacKay. An example inference task: clustering. Information Theory, Inference and Learning Algorithms, Chapter 20, pp. 284-292 (2003)
-
Field Summary
-
Constructor Summary
Constructors Constructor Description KMeans(int k)
Constructor. -
Method Summary
Modifier and Type Method Description Communities<java.lang.Integer>
cluster(java.util.List<cern.colt.matrix.DoubleMatrix1D> vectors, int length, boolean normalize)
Obtains a partition of a group of examples in k groups.java.util.List<cern.colt.matrix.DoubleMatrix1D>
normalize(java.util.List<cern.colt.matrix.DoubleMatrix1D> vectors, int length)
Given a group of vectors, normalizes them, so each coordinate has mean equal to 0 and variance equal to 1.
-
Field Details
-
THRESHOLD
private static final double THRESHOLDVariation threshold.- See Also:
- Constant Field Values
-
k
private final int kThe number of desired clusters.
-
-
Constructor Details
-
KMeans
public KMeans(int k)Constructor.- Parameters:
k
- The number of desired clusters.
-
-
Method Details
-
cluster
public Communities<java.lang.Integer> cluster(java.util.List<cern.colt.matrix.DoubleMatrix1D> vectors, int length, boolean normalize)Obtains a partition of a group of examples in k groups.- Parameters:
vectors
- The examples.length
- Length of the vectors.normalize
- True if the vectors have to be normalized, false if not.- Returns:
- The partition of the examples in groups. If k is smaller than 1, an empty set of communities is returned.
-
normalize
public java.util.List<cern.colt.matrix.DoubleMatrix1D> normalize(java.util.List<cern.colt.matrix.DoubleMatrix1D> vectors, int length)Given a group of vectors, normalizes them, so each coordinate has mean equal to 0 and variance equal to 1.- Parameters:
vectors
- The vectors to normalize.length
- The length of the vectors.- Returns:
- the normalized vectors.
-