Learn R Programming

pmclust (version 0.1-1)

kmeans.step.worker: K-means steps for workers

Description

The K-means algorithm.

Usage

kmeans.step.worker(PARAM.org)

Arguments

PARAM.org
an original set of parameters generated by set.global.

Value

  • A convergent results will be returned in the other list variables containing all new parameters which represent the components of models. Note that the following elements are commonly shared with model-based clustering, and may not make sense for the K-means algorithm. See the help page of PARAM or PARAM.org for details.

Details

A global variable called X.worker should exist in the .GlobalEnv environment, usually the working environment. The X.worker is the data matrix to be clustered, and this matrix has a dimension N.worker by p.

A PARAM.org will be a local variable inside kmeans.step.worker, and this variable is a list containing all parameters related to models. This function also updates in the parameters by the EM algorithm, and return the convergent results. The details of list elements are initially generated by set.global.

References

High Performance Statistical Computing Website: http://thirteen-01.stat.iastate.edu/snoweye/hpsc/

Lloyd., S. P. (1982) Least squares quantization in PCM, IEEE Transactions on Information Theory, 28, 129-137.

See Also

set.global, mb.print, em.step.worker.

Examples

Run this code
# Save code in a file "demo.r" and run in 4 processors by
# > mpirun -np 4 Rscript demo.r

### Setup mpi environment.
library(Rmpi)
library(pmclust)
invisible(mpi.comm.dup(0, 1))

### Generate an example data.
N.allworkers <- rep(5000, mpi.comm.size())
N.worker <- 5000
N.K.worker <- c(2000, 3000)
N <- 5000 * mpi.comm.size()
p <- 2
K <- 2
seed <- 123 + mpi.comm.rank()
data.worker <- generate.basic.worker(N.allworkers, N.worker, N.K.worker,
                                     N, p, K, seed)
X.worker <- data.worker$X.worker

### Run clustering.
PARAM.org <- set.global(K = 2)
PARAM.org <- initial.center.worker(PARAM.org)
PARAM.new <- kmeans.step.worker(PARAM.org)
kmeans.update.class.worker()
mb.print(PARAM.new, CHECK)

### Get results.
N.CLASS <- get.N.CLASS(K)
catmpi("# of class:", N.CLASS, "\n")

### Quit Rmpi.
mpi.quit()

Run the code above in your browser using DataLab