protected abstract static class AbstractKMeans.Instance
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected WritableIntegerDataStore |
assignment
A mapping of elements to cluster ids.
|
protected java.util.List<ModifiableDBIDs> |
clusters
Store the elements per cluster.
|
private NumberVectorDistanceFunction<?> |
df
Distance function.
|
private long |
diststat
Number of distance computations
|
protected boolean |
isSquared
Indicates whether the distance function is squared.
|
protected int |
k
Number of clusters.
|
protected java.lang.String |
key
Key for statistics logging.
|
(package private) double[][] |
means
Cluster means.
|
protected Relation<? extends NumberVector> |
relation
Data relation.
|
protected double[] |
varsum
Sum of squared deviations in each cluster.
|
Constructor and Description |
---|
Instance(Relation<? extends NumberVector> relation,
NumberVectorDistanceFunction<?> df,
double[][] means)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected int |
assignToNearestCluster()
Assign each object to the nearest cluster.
|
protected Clustering<KMeansModel> |
buildResult()
Build a standard k-means result, with known cluster variance sums.
|
protected Clustering<KMeansModel> |
buildResult(boolean varstat,
Relation<? extends NumberVector> relation)
Build the result, recomputing the cluster variance if
varstat is
set to true. |
protected void |
copyMeans(double[][] src,
double[][] dst)
Copy means
|
protected double |
distance(NumberVector x,
NumberVector y)
Compute a distance (and count the distance computations).
|
(package private) abstract Logging |
getLogger()
Get the class logger.
|
protected boolean |
isSquared()
Get if the distance function is squared.
|
protected abstract int |
iterate(int iteration)
Main loop function.
|
protected void |
meansFromSums(double[][] dst,
double[][] sums)
Compute means from cluster sums by averaging.
|
protected double |
movedDistance(double[][] means,
double[][] newmeans,
double[] dists)
Maximum distance moved.
|
protected void |
recomputeSeperation(double[] sep,
double[][] cdist)
Recompute the separation of cluster means.
|
protected void |
run(int maxiter)
Run the clustering.
|
double[][] means
protected java.util.List<ModifiableDBIDs> clusters
protected WritableIntegerDataStore assignment
protected double[] varsum
protected Relation<? extends NumberVector> relation
private long diststat
private final NumberVectorDistanceFunction<?> df
protected final int k
protected final boolean isSquared
protected java.lang.String key
public Instance(Relation<? extends NumberVector> relation, NumberVectorDistanceFunction<?> df, double[][] means)
relation
- Relation to processmeans
- Initial meanprotected double distance(NumberVector x, NumberVector y)
x
- First objecty
- Second objectprotected void run(int maxiter)
maxiter
- Maximum number of iterationsprotected abstract int iterate(int iteration)
iteration
- Iteration number (beginning at 1)protected void meansFromSums(double[][] dst, double[][] sums)
dst
- Output meanssums
- Input sumsprotected void copyMeans(double[][] src, double[][] dst)
src
- Source valuesdst
- Destination valuesprotected int assignToNearestCluster()
protected void recomputeSeperation(double[] sep, double[][] cdist)
Used by Elkan's variant and Exponion.
sep
- Output array of separationcdist
- Center-to-Center distances (half-sqrt scaled)protected double movedDistance(double[][] means, double[][] newmeans, double[] dists)
Used by Hamerly, Elkan (not using the maximum).
means
- Old meansnewmeans
- New meansdists
- Distances moved (output)protected Clustering<KMeansModel> buildResult()
protected Clustering<KMeansModel> buildResult(boolean varstat, Relation<? extends NumberVector> relation)
varstat
is
set to true.varstat
- Recompute cluster variancerelation
- Data relation (only needed if varstat is set)protected boolean isSquared()
true
when squaredabstract Logging getLogger()
Copyright © 2019 ELKI Development Team. License information.