Package elki.clustering.kmeans
Class HartiganWongKMeans.Instance
- java.lang.Object
-
- elki.clustering.kmeans.AbstractKMeans.Instance
-
- elki.clustering.kmeans.HartiganWongKMeans.Instance
-
- Enclosing class:
- HartiganWongKMeans<V extends NumberVector>
protected static class HartiganWongKMeans.Instance extends AbstractKMeans.Instance
Instance for a particular data set.- Author:
- Minh Nhat Nguyen
-
-
Field Summary
Fields Modifier and Type Field Description (package private) double[]an1Weights for adding/removing points from a cluster.(package private) double[]an2Weights for adding/removing points from a cluster.(package private) boolean[]itranUpdated in quick-transfer(package private) int[]liveLive set indicators(package private) int[]ncpIn Optimal-transfer-stage, NCP(L) indicates the step at which cluster L is last updated.private intoptriesNumber of attempts to make an optimal transfer.(package private) WritableDoubleDataStorer1sThe value [NC(L1) * D(I,L1)^2] / [NC(L1) -1] will be remembered and will remain the same for Point I until cluster L1 is updated.(package private) WritableIntegerDataStoresecondarySecond nearest cluster.-
Fields inherited from class elki.clustering.kmeans.AbstractKMeans.Instance
assignment, clusters, diststat, isSquared, k, key, means, relation, varsum
-
-
Constructor Summary
Constructors Constructor Description Instance(Relation<? extends NumberVector> relation, NumberVectorDistance<?> df, double[][] means)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private doublecacheR1(DBIDIter it, NumberVector vec, int l1)Compute and cache the R1 value.protected LogginggetLogger()Get the class logger.private intinitialAssignToNearestCluster()Step 1: For each point I, find its two closest centers, IC1(I) and IC2(I).private voidinitialize()Initialize AN1, AN2, ITRAN, NCPprotected intiterate(int iteration)Main loop function.private intoptimalTransfer()In this stage, there is only one pass through the data.private intquickTransfer()Step 6: the quick transfer (QTRAN) phase.private voidtransfer(DBIDRef it, NumberVector vec, int l1, int l2)Transfer a point from one cluster to another.-
Methods inherited from class elki.clustering.kmeans.AbstractKMeans.Instance
assignToNearestCluster, buildResult, buildResult, computeSquaredSeparation, copyMeans, distance, distance, distance, initialSeperation, meansFromSums, movedDistance, recomputeSeperation, recomputeVariance, run, sqrtdistance, sqrtdistance, sqrtdistance
-
-
-
-
Field Detail
-
secondary
WritableIntegerDataStore secondary
Second nearest cluster. IC2(I).
-
r1s
WritableDoubleDataStore r1s
The value [NC(L1) * D(I,L1)^2] / [NC(L1) -1] will be remembered and will remain the same for Point I until cluster L1 is updated.
-
ncp
int[] ncp
In Optimal-transfer-stage, NCP(L) indicates the step at which cluster L is last updated. In the Quick-transfer-stage, NCP(L) is equal to the step at which cluster L is last updated plus M (number of points).
-
live
int[] live
Live set indicators
-
itran
boolean[] itran
Updated in quick-transfer
-
an1
double[] an1
Weights for adding/removing points from a cluster.
-
an2
double[] an2
Weights for adding/removing points from a cluster.
-
optries
private int optries
Number of attempts to make an optimal transfer.
-
-
Constructor Detail
-
Instance
public Instance(Relation<? extends NumberVector> relation, NumberVectorDistance<?> df, double[][] means)
Constructor.- Parameters:
relation- Data relationdf- Distance functionmeans- Initial means
-
-
Method Detail
-
iterate
protected int iterate(int iteration)
Description copied from class:AbstractKMeans.InstanceMain loop function.- Specified by:
iteratein classAbstractKMeans.Instance- Parameters:
iteration- Iteration number (beginning at 1)- Returns:
- Number of reassigned points
-
initialAssignToNearestCluster
private int initialAssignToNearestCluster()
Step 1: For each point I, find its two closest centers, IC1(I) and IC2(I). Assign it to IC1(I).- Returns:
- Number of reassigned points
-
initialize
private void initialize()
Initialize AN1, AN2, ITRAN, NCP
-
optimalTransfer
private int optimalTransfer()
In this stage, there is only one pass through the data. Each point is reallocated, if necessary, to the cluster that will induce the maximum reduction in wcss.- Returns:
- Number of reassigned objects
-
quickTransfer
private int quickTransfer()
Step 6: the quick transfer (QTRAN) phase. Each point is tested in turn to see if it should be reallocated to the cluster which it is most likely to be transferred to IC2(I) from its present cluster IC1(I). Loop through the data until no further change is to take place.
-
cacheR1
private double cacheR1(DBIDIter it, NumberVector vec, int l1)
Compute and cache the R1 value.- Parameters:
it- Point idvec- Data vectorl1- Center id- Returns:
- R1
-
transfer
private void transfer(DBIDRef it, NumberVector vec, int l1, int l2)
Transfer a point from one cluster to another.- Parameters:
it- Point idvec- Vectorl1- First clusterl2- Second cluster
-
getLogger
protected Logging getLogger()
Description copied from class:AbstractKMeans.InstanceGet the class logger.- Specified by:
getLoggerin classAbstractKMeans.Instance- Returns:
- Logger
-
-