V
- Vector typeM
- Cluster model typepublic abstract class AbstractKMeans<V extends NumberVector,M extends Model> extends AbstractNumberVectorDistanceBasedAlgorithm<V,Clustering<M>> implements KMeans<V,M>
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractKMeans.Instance
Inner instance for a run, for better encapsulation, that encapsulates the
standard flow of most (but not all) k-means variations.
|
static class |
AbstractKMeans.Parameterizer<V extends NumberVector>
Parameterization class.
|
Modifier and Type | Field and Description |
---|---|
protected KMeansInitialization |
initializer
Method to choose initial means.
|
protected int |
k
Number of cluster centers to initialize.
|
protected int |
maxiter
Maximum number of iterations
|
distanceFunction
ALGORITHM_ID
INIT_ID, K_ID, MAXITER_ID, SEED_ID, VARSTAT_ID
DISTANCE_FUNCTION_ID
Constructor and Description |
---|
AbstractKMeans(NumberVectorDistanceFunction<? super V> distanceFunction,
int k,
int maxiter,
KMeansInitialization initializer)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private static double[][] |
denseMeans(java.util.List<? extends DBIDs> clusters,
double[][] means,
Relation<? extends NumberVector> relation)
Returns the mean vectors of the given clusters in the given database.
|
TypeInformation[] |
getInputTypeRestriction()
Get the input type restriction used for negotiating the data query.
|
protected static void |
incrementalUpdateMean(double[] mean,
NumberVector vec,
int newsize,
double op)
Compute an incremental update for the mean.
|
protected double[][] |
initialMeans(Database database,
Relation<V> relation)
Choose the initial means.
|
protected static double[][] |
means(java.util.List<? extends DBIDs> clusters,
double[][] means,
Relation<? extends NumberVector> relation)
Returns the mean vectors of the given clusters in the given database.
|
static void |
minusEquals(double[] sum,
NumberVector vec)
Similar to VMath.minusEquals, but accepts a number vector.
|
protected static void |
nearestMeans(double[][] cdist,
int[][] cnum)
Recompute the separation of cluster means.
|
static void |
plusEquals(double[] sum,
NumberVector vec)
Similar to VMath.plusEquals, but accepts a number vector.
|
static void |
plusMinusEquals(double[] add,
double[] sub,
NumberVector vec)
Add to one, remove from another.
|
void |
setDistanceFunction(NumberVectorDistanceFunction<? super V> distanceFunction)
Set the distance function to use.
|
void |
setInitializer(KMeansInitialization init)
Set the initialization method.
|
void |
setK(int k)
Set the value of k.
|
private static double[][] |
sparseMeans(java.util.List<? extends DBIDs> clusters,
double[][] means,
Relation<? extends SparseNumberVector> relation)
Returns the mean vectors of the given clusters in the given database.
|
getDistanceFunction
getLogger, run
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
run
getDistanceFunction
protected int k
protected int maxiter
protected KMeansInitialization initializer
public AbstractKMeans(NumberVectorDistanceFunction<? super V> distanceFunction, int k, int maxiter, KMeansInitialization initializer)
distanceFunction
- distance functionk
- k parametermaxiter
- Maxiter parameterinitializer
- Function to generate the initial meanspublic TypeInformation[] getInputTypeRestriction()
AbstractAlgorithm
getInputTypeRestriction
in interface Algorithm
getInputTypeRestriction
in class AbstractAlgorithm<Clustering<M extends Model>>
protected double[][] initialMeans(Database database, Relation<V> relation)
database
- Databaserelation
- Relationprotected static double[][] means(java.util.List<? extends DBIDs> clusters, double[][] means, Relation<? extends NumberVector> relation)
clusters
- the clusters to compute the meansmeans
- the recent meansrelation
- the database containing the vectorsprivate static double[][] denseMeans(java.util.List<? extends DBIDs> clusters, double[][] means, Relation<? extends NumberVector> relation)
clusters
- the clusters to compute the meansmeans
- the recent meansrelation
- the database containing the vectorspublic static void plusEquals(double[] sum, NumberVector vec)
sum
- Aggregation arrayvec
- Vector to addpublic static void minusEquals(double[] sum, NumberVector vec)
sum
- Aggregation arrayvec
- Vector to subtractpublic static void plusMinusEquals(double[] add, double[] sub, NumberVector vec)
add
- Array to add tosub
- Array to remove fromvec
- Vector to subtractprivate static double[][] sparseMeans(java.util.List<? extends DBIDs> clusters, double[][] means, Relation<? extends SparseNumberVector> relation)
clusters
- the clusters to compute the meansmeans
- the recent meansrelation
- the database containing the vectorsprotected static void nearestMeans(double[][] cdist, int[][] cnum)
Used by sort, and our exponion implementation.
cdist
- Center-to-Center distancescnum
- Center numbersprotected static void incrementalUpdateMean(double[] mean, NumberVector vec, int newsize, double op)
mean
- Mean to updatevec
- Object vectornewsize
- (New) size of clusterop
- Cluster size change / Weight changepublic void setK(int k)
KMeans
public void setDistanceFunction(NumberVectorDistanceFunction<? super V> distanceFunction)
KMeans
setDistanceFunction
in interface KMeans<V extends NumberVector,M extends Model>
distanceFunction
- Distance function.public void setInitializer(KMeansInitialization init)
KMeans
setInitializer
in interface KMeans<V extends NumberVector,M extends Model>
init
- Initialization methodCopyright © 2019 ELKI Development Team. License information.