V
- Vector typeD
- Distance typeM
- Cluster model typepublic abstract class AbstractKMeans<V extends NumberVector<?>,D extends Distance<D>,M extends MeanModel<V>> extends AbstractPrimitiveDistanceBasedAlgorithm<NumberVector<?>,D,Clustering<M>> implements KMeans, ClusteringAlgorithm<Clustering<M>>
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<? super 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.
|
getDistanceFunction
getLogger, makeParameterDistanceFunction, run
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
run
protected int k
KMeans.K_ID
.protected int maxiter
KMeans.MAXITER_ID
.protected KMeansInitialization<V extends NumberVector<?>> initializer
public AbstractKMeans(PrimitiveDistanceFunction<? super 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()
AbstractAlgorithm
getInputTypeRestriction
in interface Algorithm
getInputTypeRestriction
in class AbstractAlgorithm<Clustering<M extends MeanModel<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