
V - Vector typeD - Distance typepublic abstract class AbstractKMeans<V extends NumberVector<V,?>,D extends Distance<D>> extends AbstractPrimitiveDistanceBasedAlgorithm<NumberVector<?,?>,D,Clustering<MeanModel<V>>> implements KMeans
AbstractPrimitiveDistanceBasedAlgorithm.Parameterizer<O,D extends Distance<D>>| Modifier and Type | Field and Description |
|---|---|
protected KMeansInitialization<V> |
initializer
Method to choose initial means.
|
protected int |
k
Holds the value of
KMeans.K_ID. |
protected int |
maxiter
Holds the value of
KMeans.MAXITER_ID. |
INIT_ID, K_ID, MAXITER_ID, SEED_ID| Constructor and Description |
|---|
AbstractKMeans(PrimitiveDistanceFunction<NumberVector<?,?>,D> distanceFunction,
int k,
int maxiter,
KMeansInitialization<V> initializer)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
assignToNearestCluster(Relation<V> relation,
List<? extends NumberVector<?,?>> means,
List<? extends ModifiableDBIDs> clusters)
Returns a list of clusters.
|
TypeInformation[] |
getInputTypeRestriction()
Get the input type restriction used for negotiating the data query.
|
protected void |
incrementalUpdateMean(Vector mean,
V vec,
int newsize,
double op)
Compute an incremental update for the mean
|
protected boolean |
macQueenIterate(Relation<V> relation,
List<Vector> means,
List<ModifiableDBIDs> clusters)
Perform a MacQueen style iteration.
|
protected List<Vector> |
means(List<? extends ModifiableDBIDs> clusters,
List<? extends NumberVector<?,?>> means,
Relation<V> database)
Returns the mean vectors of the given clusters in the given database.
|
protected List<NumberVector<?,?>> |
medians(List<? extends ModifiableDBIDs> clusters,
List<? extends NumberVector<?,?>> medians,
Relation<V> database)
Returns the median vectors of the given clusters in the given database.
|
getDistanceFunctiongetLogger, makeParameterDistanceFunction, runprotected int k
KMeans.K_ID.protected int maxiter
KMeans.MAXITER_ID.protected KMeansInitialization<V extends NumberVector<V,?>> initializer
public AbstractKMeans(PrimitiveDistanceFunction<NumberVector<?,?>,D> distanceFunction, int k, int maxiter, KMeansInitialization<V> initializer)
distanceFunction - distance functionk - k parametermaxiter - Maxiter parameterinitializer - Function to generate the initial meansprotected boolean assignToNearestCluster(Relation<V> relation, List<? extends NumberVector<?,?>> means, List<? extends ModifiableDBIDs> clusters)
relation - the database to clustermeans - a list of k meansclusters - cluster assignmentpublic TypeInformation[] getInputTypeRestriction()
AbstractAlgorithmgetInputTypeRestriction in interface AlgorithmgetInputTypeRestriction in class AbstractAlgorithm<Clustering<MeanModel<V extends NumberVector<V,?>>>>protected List<Vector> means(List<? extends ModifiableDBIDs> clusters, List<? extends NumberVector<?,?>> means, Relation<V> database)
clusters - the clusters to compute the meansmeans - the recent meansdatabase - the database containing the vectorsprotected List<NumberVector<?,?>> medians(List<? extends ModifiableDBIDs> clusters, List<? extends NumberVector<?,?>> medians, Relation<V> database)
clusters - the clusters to compute the meansmedians - the recent mediansdatabase - the database containing the vectorsprotected void incrementalUpdateMean(Vector mean, V vec, int newsize, double op)
mean - Mean to updatevec - Object vectornewsize - (New) size of clusterop - Cluster size change / Weight change